Skip to content

Commit

Permalink
Merge pull request #177 from linuxonrails/separate-the-path-where-tem…
Browse files Browse the repository at this point in the history
…porary-files-uploaded-by-the-user-are-stored-in-a-module-setting-variable

Separate the path where temporary files uploaded by the user are stor…
  • Loading branch information
grantcopley authored Feb 20, 2025
2 parents e3e6caa + 8031d52 commit 8b379f5
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 61 deletions.
8 changes: 6 additions & 2 deletions ModuleConfig.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ component {
function configure(){
settings = {
/**
* Set to true to automatically include CSS and JS
* Set to true to automatically include CSS and JS
* assets for CBWIRE. This makes it where you do not
* need to add wireStyles() and wireScripts() to your layout.
*/
Expand All @@ -24,6 +24,10 @@ component {
* Capture our module root for use throughout CBWIRE.
*/
"moduleRootPath": getCanonicalPath( getCurrentTemplatePath().replaceNoCase( "/ModuleConfig.cfc", "", "one" ) ),
/**
* The default storage path for all cbwire components.
*/
"storagePath": getCanonicalPath( getCurrentTemplatePath().replaceNoCase( "/ModuleConfig.cfc", "", "one" ) & "/models/tmp" ),
/**
* Set to true to throw a 'WireSetterNotFound' exception if
* the incoming cbwire request tries to update a property
Expand All @@ -43,7 +47,7 @@ component {
* Enables or disables the progress bar when using wire:navigate
*/
"showProgressBar": true,
/**
/**
* The color of the progress bar when using wire:navigate
*/
"progressBarColor": "##2299dd"
Expand Down
76 changes: 38 additions & 38 deletions models/CBWIREController.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ component singleton {

// Inject module settings
property name="moduleSettings" inject="coldbox:modulesettings:cbwire";

// Inject module service
property name="moduleService" inject="coldbox:moduleService";

Expand Down Expand Up @@ -43,8 +43,8 @@ component singleton {
._withKey( arguments.key );

// If the component is lazy loaded, we need to generate an x-intersect snapshot of the component
return arguments.lazy ?
local.instance._generateXIntersectLazyLoadSnapshot( params=arguments.params ) :
return arguments.lazy ?
local.instance._generateXIntersectLazyLoadSnapshot( params=arguments.params ) :
local.instance._render();
}

Expand All @@ -53,7 +53,7 @@ component singleton {
*
* @incomingRequest The JSON struct payload of the incoming request.
* @event The event object.
*
*
* @return A struct representing the response with updated component details or an error message.
*/
function handleRequest( incomingRequest, event ) {
Expand Down Expand Up @@ -121,15 +121,15 @@ component singleton {
/**
* Uploads all files from the request to the specified destination
* after verifying the signed URL.
*
*
* @incomingRequest The JSON struct payload of the incoming request.
* @event The event object.
*
*
* @return A struct representing the response with updated component details or an error message.
*/
function handleFileUpload( incomingRequest, event ) {
// Determine our storage path for temporary files
local.storagePath = getCanonicalPath( variables.moduleSettings.moduleRootPath & "/models/tmp" );
local.storagePath = getCanonicalPath( variables.moduleSettings.storagePath );

// Ensure the storage path exists
if( !directoryExists( local.storagePath ) ){
Expand Down Expand Up @@ -158,10 +158,10 @@ component singleton {

/**
* Handles the preview of a file by reading the file metadata and sending it back to the client.
*
*
* @incomingRequest The JSON struct payload of the incoming request.
* @event The event object.
*
*
* @return file contents
*/
function handleFilePreview( incomingRequest, event ){
Expand All @@ -170,10 +170,10 @@ component singleton {
return event.noRender();
}

local.metaPath = getCanonicalPath( variables.moduleSettings.moduleRootPath & "models/tmp/#local.uuid#.json" );
local.metaPath = getCanonicalPath( variables.moduleSettings.storagePath & "/#local.uuid#.json" );

local.metaJSON = deserializeJSON( fileRead( local.metaPath ) );
local.contents = fileReadBinary( getCanonicalPath( variables.moduleSettings.moduleRootPath & "models/tmp/#local.metaJSON.serverFile#" ) );
local.contents = fileReadBinary( getCanonicalPath( variables.moduleSettings.storagePath & "/#local.metaJSON.serverFile#" ) );
event
.sendFile(
file = local.contents,
Expand All @@ -191,18 +191,18 @@ component singleton {
* @componentName The name of the component to instantiate, possibly including a namespace.
* @params Optional parameters to pass to the component constructor.
* @key Optional key to use when retrieving the component from WireBox.
*
*
* @return The instantiated component object.
* @throws ApplicationException If the component cannot be found or instantiated.
*/
function createInstance( name ) {
// Determine if the component name traverses a valid namespace or directory structure
local.fullComponentPath = arguments.name;

if ( !local.fullComponentPath contains "wires." ) {
local.fullComponentPath = "wires." & local.fullComponentPath;
}

if ( find( "@", local.fullComponentPath ) ) {
// This is a module reference, find in our module
var params = listToArray( local.fullComponentPath, "@" );
Expand Down Expand Up @@ -243,9 +243,9 @@ component singleton {
}
}

/**
/**
* Returns the path to the modules folder.
*
*
* @module string | The name of the module.
*
* @return string
Expand Down Expand Up @@ -286,8 +286,8 @@ component singleton {
* Returns the path to the wires folder within a module path.
*
* @module string | The name of the module.
*
* @return string
*
* @return string
*/
function getModuleWiresPath( module ) {
local.moduleRegistry = moduleService.getModuleRegistry();
Expand All @@ -296,7 +296,7 @@ component singleton {

/**
* Returns the ColdBox RequestContext object.
*
*
* @return The ColdBox RequestContext object.
*/
function getEvent(){
Expand All @@ -305,7 +305,7 @@ component singleton {

/**
* Returns any request assets defined by components during the request.
*
*
* @return struct
*/
function getRequestAssets() {
Expand All @@ -316,7 +316,7 @@ component singleton {

/**
* Returns the ColdBox ConfigSettings object.
*
*
* @return struct
*/
function getConfigSettings(){
Expand All @@ -325,15 +325,15 @@ component singleton {

/**
* Returns an array of preprocessor instances.
*
*
* @return An array of preprocessor instances.
*/
function getPreprocessors(){
// Check if we've already scanned the folder
if( structKeyExists( variables, "preprocessors" ) ){
return variables.preprocessors;
}
// List of preprocesssors here. Had to hard code instead of using
// List of preprocesssors here. Had to hard code instead of using
// directoryList because of filesystem differences in various OSes
local.files = [
"TemplatePreprocessor.cfc",
Expand All @@ -351,18 +351,18 @@ component singleton {

/**
* Returns CSS styling needed by Livewire.
*
*
* @return string
*/
function getStyles( cache=true ) {
if (structKeyExists(variables, "styles") && arguments.cache ) {
return variables.styles;
}

savecontent variable="local.html" {
include "styles.cfm";
}

variables.styles = local.html;
return variables.styles;
}
Expand All @@ -372,10 +372,10 @@ component singleton {
* We don't cache the results like we do with
* styles because we need to generate a unique
* CSRF token for each request.
*
*
* @return string
*/
function getScripts() {
function getScripts() {
savecontent variable="local.html" {
include "scripts.cfm";
}
Expand All @@ -384,7 +384,7 @@ component singleton {

/**
* Returns HTML to persist the state of anything inside the call.
*
*
* @return string
*/
function persist( name ) {
Expand All @@ -393,7 +393,7 @@ component singleton {

/**
* Ends the persistence of the state of anything inside the call.
*
*
* @return string
*/
function endPersist() {
Expand All @@ -402,10 +402,10 @@ component singleton {

/**
* Generates a secure signature for the upload URL.
*
*
* @baseURL string | The base URL for the upload request.
* @expires string | The expiration time for the request.
*
*
* @return string
*/
function generateSignature(baseUrl, expires) {
Expand All @@ -419,7 +419,7 @@ component singleton {

/**
* Generates a CSRF token for the current request.
*
*
* @return string
*/
function generateCSRFToken() {
Expand All @@ -429,7 +429,7 @@ component singleton {

/**
* Returns the base URL for incoming requests.
*
*
* @return string
*/
function getBaseURL() {
Expand Down Expand Up @@ -457,7 +457,7 @@ component singleton {

/**
* Verifies signed upload URL.
*
*
* @return boolean
*/
function verifySignedUploadURL( expires, signature ) {
Expand Down Expand Up @@ -523,11 +523,11 @@ component singleton {

/**
* Returns the URI endpoint for updating CBWIRE components.
*
*
* @return string
*/
function getUpdateEndpoint() {
var settings = variables.moduleSettings;
var settings = variables.moduleSettings;
return settings.keyExists( "updateEndpoint") && settings.updateEndpoint.len() ? settings.updateEndpoint : "/cbwire/update";
}
}
}
Loading

0 comments on commit 8b379f5

Please sign in to comment.