Skip to content

Commit

Permalink
Merge pull request #43 from coldbox-modules/feature/CBFS-38
Browse files Browse the repository at this point in the history
#38 Pass file object where it makes sense for announced interceptions
  • Loading branch information
jclausen authored Jan 26, 2023
2 parents 7e821dc + e716335 commit 74578d1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 30 deletions.
24 changes: 13 additions & 11 deletions models/providers/LocalProvider.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ component accessors="true" extends="cbfs.models.AbstractDiskProvider" {
fileSetAccessMode( diskPath, arguments.mode );
}

arguments[ "disk" ] = this;
intercept.announce( "cbfsOnFileCreate", arguments );
intercept.announce( "cbfsOnFileCreate", { file : this.file( arguments.path ) } );

return this;
}
Expand Down Expand Up @@ -278,7 +277,7 @@ component accessors="true" extends="cbfs.models.AbstractDiskProvider" {
variables.jCopyOption.ATOMIC_MOVE
]
);
intercept.announce( "cbfsOnFileCreate", { "path" : filePath, "disk" : this } );
intercept.announce( "cbfsOnFileCreate", { file : this.file( filePath ) } );
} else {
// otherwise we can go directly to the directory
var upload = fileUpload(
Expand All @@ -289,10 +288,9 @@ component accessors="true" extends="cbfs.models.AbstractDiskProvider" {
);
var filePath = arguments.directory & "/" & upload.serverFile;

intercept.announce( "cbfsOnFileCreate", { "path" : filePath, "disk" : this } );
intercept.announce( "cbfsOnFileCreate", { file : this.file( filePath ) } );
}


return this;
}

Expand Down Expand Up @@ -604,7 +602,7 @@ component accessors="true" extends="cbfs.models.AbstractDiskProvider" {
}
variables.jFiles.delete( buildJavaDiskPath( arguments.path ) );

intercept.announce( "cbfsOnFileDelete", { "path" : normalizePath( arguments.path ), "disk" : this } );
intercept.announce( "cbfsOnFileDelete", { file : this.file( normalizePath( arguments.path ) ) } );

return true;
}
Expand Down Expand Up @@ -762,10 +760,9 @@ component accessors="true" extends="cbfs.models.AbstractDiskProvider" {
if ( missing( arguments.path ) ) {
throw( type = "cbfs.FileNotFoundException", message = "File [#arguments.path#] not found." );
}
var fileInfo = getFileInfo( buildDiskPath( arguments.path ) );
fileInfo[ "diskPath" ] = normalizePath( arguments.path );
var fileInfo = getFileInfo( buildDiskPath( arguments.path ) );

intercept.announce( "cbfsOnFileInfoRequest", fileInfo );
intercept.announce( "cbfsOnFileInfoRequest", { file : buildDiskPath( arguments.path ), info : fileInfo } );

return fileInfo;
}
Expand Down Expand Up @@ -799,9 +796,14 @@ component accessors="true" extends="cbfs.models.AbstractDiskProvider" {
return arguments.value.toString();
}
} );
infoMap[ "diskPath" ] = normalizePath( arguments.path );

intercept.announce( "cbfsOnFileInfoRequest", infoMap );
intercept.announce(
"cbfsOnFileInfoRequest",
{
file : this.file( normalizePath( arguments.path ) ),
infoMap : infoMap
}
);

return infoMap;
}
Expand Down
5 changes: 2 additions & 3 deletions models/providers/RamProvider.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ component accessors="true" extends="cbfs.models.AbstractDiskProvider" {
createDirectory( getDirectoryFromPath( arguments.path ) );
}

arguments[ "disk" ] = this;
intercept.announce( "cbfsOnFileCreate", arguments );
intercept.announce( "cbfsOnFileCreate", { file : this.file( arguments.path ) } );

return this;
}
Expand Down Expand Up @@ -415,7 +414,7 @@ component accessors="true" extends="cbfs.models.AbstractDiskProvider" {
}
variables.fileStorage.delete( arguments.path );

intercept.announce( "cbfsOnFileDelete", { "path" : normalizePath( arguments.path ), "disk" : this } );
intercept.announce( "cbfsOnFileDelete", { file : this.file( normalizePath( arguments.path ) ) } );

return true;
}
Expand Down
26 changes: 10 additions & 16 deletions models/providers/S3Provider.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ component accessors="true" extends="cbfs.models.AbstractDiskProvider" {

evictFromCache( arguments.path );

arguments[ "disk" ] = this;
intercept.announce( "cbfsOnFileCreate", arguments );
intercept.announce( "cbfsOnFileCreate", { file : this.file( arguments.path ) } );

return this;
}
Expand Down Expand Up @@ -193,10 +192,10 @@ component accessors="true" extends="cbfs.models.AbstractDiskProvider" {
}

variables.s3.putObjectFile(
bucketName = variables.properties.bucketName,
filePath = arguments.source,
uri = buildPath( filePath ),
acl = arguments.visibility,
bucketName = variables.properties.bucketName,
filePath = arguments.source,
uri = buildPath( filePath ),
acl = arguments.visibility,
contentType = getMimeType( arguments.name )
);

Expand Down Expand Up @@ -466,24 +465,19 @@ component accessors="true" extends="cbfs.models.AbstractDiskProvider" {
* @throws cbfs.FileNotFoundException
*/
any function get( required path ){

ensureFileExists( arguments.path );

arguments.path = buildPath( arguments.path );

var response = variables.s3.getObject(
bucketName = variables.properties.bucketName,
uri = arguments.path
).response;
var response = variables.s3.getObject( bucketName = variables.properties.bucketName, uri = arguments.path ).response;

if( getMetadata( response ).name == "java.io.ByteArrayOutputStream" ){
if ( getMetadata( response ).name == "java.io.ByteArrayOutputStream" ) {
var bytes = [];
response.writeBytes( bytes );
return response.toByteArray();
} else {
return response;
}

}

/**
Expand Down Expand Up @@ -597,7 +591,7 @@ component accessors="true" extends="cbfs.models.AbstractDiskProvider" {
/**
* Deletes a file
*
* @path The path to delete
* @path The path to delete
* @throwOnMissing When true an error will be thrown if the file does not exist
*/
boolean function delete( required any path, boolean throwOnMissing = false ){
Expand All @@ -616,7 +610,7 @@ component accessors="true" extends="cbfs.models.AbstractDiskProvider" {
return false;
}

intercept.announce( "cbfsOnFileDelete", { "path" : normalizePath( arguments.path ), "disk" : this } );
intercept.announce( "cbfsOnFileDelete", { file : this.file( normalizePath( arguments.path ) ) } );

return true;
}
Expand Down Expand Up @@ -664,7 +658,7 @@ component accessors="true" extends="cbfs.models.AbstractDiskProvider" {
"isHidden" : acl == "private"
};

intercept.announce( "cbfsOnFileInfoRequest", info );
intercept.announce( "cbfsOnFileInfoRequest", { file : this.file( filePath ), info : info } );

return info;
}
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Apache License, Version 2.0.

- Lucee 5+
- Adobe ColdFusion 2018+
- Java 11-15

## Installation

Expand Down

0 comments on commit 74578d1

Please sign in to comment.