From d46f1ce9f013058fe2b50c083c387b501413aaf9 Mon Sep 17 00:00:00 2001 From: Adrian Curtin <48138055+AdrianCurtin@users.noreply.github.com> Date: Thu, 16 Jan 2025 17:28:25 -0500 Subject: [PATCH 01/12] Allow file adapter to override file name and location + give createFile access to config to allow getFileLocation calls internally File adapter may specify a different filename or location during creation which should be returned after content storage. Example, adapter timestamps upload filenames. getFileLocation may result in a slightly different url than the one used to create the file. In the case where the url returned is identical this is not a problem. Additionally file adapter could call getFile location internally if it wanted to (and should probably have access to config for that reason) --- src/Controllers/FilesController.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Controllers/FilesController.js b/src/Controllers/FilesController.js index a88c527b00..59a3448962 100644 --- a/src/Controllers/FilesController.js +++ b/src/Controllers/FilesController.js @@ -29,11 +29,11 @@ export class FilesController extends AdaptableController { filename = randomHexString(32) + '_' + filename; } - const location = await this.adapter.getFileLocation(config, filename); - await this.adapter.createFile(filename, data, contentType, options); + const defaultLocation = await this.adapter.getFileLocation(config, filename); + const createResult = await this.adapter.createFile(filename, data, contentType, options, config); return { - url: location, - name: filename, + url: createResult?.url || defaultLocation, + name: createResult?.name || filename, } } From cc7027e07e36acfb64a0dc9ee8ae9dc8bf18d104 Mon Sep 17 00:00:00 2001 From: Adrian Curtin <48138055+AdrianCurtin@users.noreply.github.com> Date: Thu, 16 Jan 2025 18:39:04 -0500 Subject: [PATCH 02/12] Only call getFileLocation if no url is provided but use updated filename in getFileLocation --- src/Controllers/FilesController.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Controllers/FilesController.js b/src/Controllers/FilesController.js index 59a3448962..733b2544cd 100644 --- a/src/Controllers/FilesController.js +++ b/src/Controllers/FilesController.js @@ -29,11 +29,14 @@ export class FilesController extends AdaptableController { filename = randomHexString(32) + '_' + filename; } - const defaultLocation = await this.adapter.getFileLocation(config, filename); const createResult = await this.adapter.createFile(filename, data, contentType, options, config); + filename = createResult?.name || filename; // if createFile returns a new filename, use it + + const url = createResult?.url || await this.adapter.getFileLocation(config, filename); // if createFile returns a new url, use it otherwise get the url from the adapter + return { - url: createResult?.url || defaultLocation, - name: createResult?.name || filename, + url: url, + name: filename, } } From ff9441fc59ce58c150620ccabc81f95acb817fa1 Mon Sep 17 00:00:00 2001 From: Adrian Curtin <48138055+AdrianCurtin@users.noreply.github.com> Date: Thu, 16 Jan 2025 19:03:50 -0500 Subject: [PATCH 03/12] Modify description and typescript --- src/Adapters/Files/FilesAdapter.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Adapters/Files/FilesAdapter.js b/src/Adapters/Files/FilesAdapter.js index f06c52df89..4c269620c8 100644 --- a/src/Adapters/Files/FilesAdapter.js +++ b/src/Adapters/Files/FilesAdapter.js @@ -30,13 +30,14 @@ export class FilesAdapter { * @param {string} contentType - the supposed contentType * @discussion the contentType can be undefined if the controller was not able to determine it * @param {object} options - (Optional) options to be passed to file adapter (S3 File Adapter Only) + * @param {Config} config -(Optional) server configuration * - tags: object containing key value pairs that will be stored with file * - metadata: object containing key value pairs that will be sotred with file (https://docs.aws.amazon.com/AmazonS3/latest/user-guide/add-object-metadata.html) * @discussion options are not supported by all file adapters. Check the your adapter's documentation for compatibility * - * @return {Promise} a promise that should fail if the storage didn't succeed + * @return {Promise|Promise<{url?: string, name?: string}>} Either a plain promise that should fail if storage didn't succeed, or a promise resolving to an object containing url and/or an updated filename */ - createFile(filename: string, data, contentType: string, options: Object): Promise {} + createFile(filename: string, data, contentType: string, options: Object, config: Config): Promise {} /** Responsible for deleting the specified file * From 1578b7b658f8c6e743df518e638bbd52c773550d Mon Sep 17 00:00:00 2001 From: Adrian Curtin <48138055+AdrianCurtin@users.noreply.github.com> Date: Thu, 16 Jan 2025 19:06:12 -0500 Subject: [PATCH 04/12] Add optional location element too --- src/Adapters/Files/FilesAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adapters/Files/FilesAdapter.js b/src/Adapters/Files/FilesAdapter.js index 4c269620c8..a0285d95a8 100644 --- a/src/Adapters/Files/FilesAdapter.js +++ b/src/Adapters/Files/FilesAdapter.js @@ -35,7 +35,7 @@ export class FilesAdapter { * - metadata: object containing key value pairs that will be sotred with file (https://docs.aws.amazon.com/AmazonS3/latest/user-guide/add-object-metadata.html) * @discussion options are not supported by all file adapters. Check the your adapter's documentation for compatibility * - * @return {Promise|Promise<{url?: string, name?: string}>} Either a plain promise that should fail if storage didn't succeed, or a promise resolving to an object containing url and/or an updated filename + * @return {Promise|Promise<{url?: string, name?: string, location?: string}>} Either a plain promise that should fail if storage didn't succeed, or a promise resolving to an object containing url and/or an updated filename and/or location (if relevant) */ createFile(filename: string, data, contentType: string, options: Object, config: Config): Promise {} From e0015c163f1254b23413d2237dc50b1b741a140f Mon Sep 17 00:00:00 2001 From: Adrian Curtin <48138055+AdrianCurtin@users.noreply.github.com> Date: Thu, 16 Jan 2025 19:17:35 -0500 Subject: [PATCH 05/12] Update FilesAdapter.js --- src/Adapters/Files/FilesAdapter.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Adapters/Files/FilesAdapter.js b/src/Adapters/Files/FilesAdapter.js index a0285d95a8..6301f6acdf 100644 --- a/src/Adapters/Files/FilesAdapter.js +++ b/src/Adapters/Files/FilesAdapter.js @@ -30,10 +30,11 @@ export class FilesAdapter { * @param {string} contentType - the supposed contentType * @discussion the contentType can be undefined if the controller was not able to determine it * @param {object} options - (Optional) options to be passed to file adapter (S3 File Adapter Only) - * @param {Config} config -(Optional) server configuration * - tags: object containing key value pairs that will be stored with file - * - metadata: object containing key value pairs that will be sotred with file (https://docs.aws.amazon.com/AmazonS3/latest/user-guide/add-object-metadata.html) - * @discussion options are not supported by all file adapters. Check the your adapter's documentation for compatibility + * - metadata: object containing key value pairs that will be stored with file (https://docs.aws.amazon.com/AmazonS3/latest/user-guide/add-object-metadata.html) + * @discussion options are not supported by all file adapters. Check the your adapter's documentation for compatibility + * @param {Config} config -(Optional) server configuration + * @discussion config is not supported by all file adapters. Check the your adapter's documentation for compatibility * * @return {Promise|Promise<{url?: string, name?: string, location?: string}>} Either a plain promise that should fail if storage didn't succeed, or a promise resolving to an object containing url and/or an updated filename and/or location (if relevant) */ From a1ccce18ba65d0dca3de1a8666a840907c4f4a5b Mon Sep 17 00:00:00 2001 From: Adrian Curtin <48138055+AdrianCurtin@users.noreply.github.com> Date: Fri, 17 Jan 2025 13:26:50 -0500 Subject: [PATCH 06/12] Remove trialing space --- src/Adapters/Files/FilesAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adapters/Files/FilesAdapter.js b/src/Adapters/Files/FilesAdapter.js index 6301f6acdf..7520e24649 100644 --- a/src/Adapters/Files/FilesAdapter.js +++ b/src/Adapters/Files/FilesAdapter.js @@ -32,7 +32,7 @@ export class FilesAdapter { * @param {object} options - (Optional) options to be passed to file adapter (S3 File Adapter Only) * - tags: object containing key value pairs that will be stored with file * - metadata: object containing key value pairs that will be stored with file (https://docs.aws.amazon.com/AmazonS3/latest/user-guide/add-object-metadata.html) - * @discussion options are not supported by all file adapters. Check the your adapter's documentation for compatibility + * @discussion options are not supported by all file adapters. Check the your adapter's documentation for compatibility * @param {Config} config -(Optional) server configuration * @discussion config is not supported by all file adapters. Check the your adapter's documentation for compatibility * From 433423ce03ffac7dff915eafe68da23dd47b6f65 Mon Sep 17 00:00:00 2001 From: Adrian Curtin <48138055+AdrianCurtin@users.noreply.github.com> Date: Fri, 17 Jan 2025 13:33:58 -0500 Subject: [PATCH 07/12] change to undefined as a fallback --- src/Adapters/Files/FilesAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Adapters/Files/FilesAdapter.js b/src/Adapters/Files/FilesAdapter.js index 7520e24649..19846301fb 100644 --- a/src/Adapters/Files/FilesAdapter.js +++ b/src/Adapters/Files/FilesAdapter.js @@ -36,7 +36,7 @@ export class FilesAdapter { * @param {Config} config -(Optional) server configuration * @discussion config is not supported by all file adapters. Check the your adapter's documentation for compatibility * - * @return {Promise|Promise<{url?: string, name?: string, location?: string}>} Either a plain promise that should fail if storage didn't succeed, or a promise resolving to an object containing url and/or an updated filename and/or location (if relevant) + * @return {Promise<{url?: string, name?: string, location?: string}>|Promise} Either a plain promise that should fail if storage didn't succeed, or a promise resolving to an object containing url and/or an updated filename and/or location (if relevant) */ createFile(filename: string, data, contentType: string, options: Object, config: Config): Promise {} From 2c76b13010a4fac5829d1b9578428a01cf8e18e1 Mon Sep 17 00:00:00 2001 From: Adrian Curtin <48138055+AdrianCurtin@users.noreply.github.com> Date: Fri, 17 Jan 2025 13:48:38 -0500 Subject: [PATCH 08/12] Add tests for different return conditions --- spec/FilesController.spec.js | 107 +++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/spec/FilesController.spec.js b/spec/FilesController.spec.js index 30acf7d13c..2792290c58 100644 --- a/spec/FilesController.spec.js +++ b/spec/FilesController.spec.js @@ -218,4 +218,111 @@ describe('FilesController', () => { expect(gridFSAdapter.validateFilename(fileName)).not.toBe(null); done(); }); + + it('should return valid filename or url from createFile response when provided', async () => { + const config = Config.get(Parse.applicationId); + + // Test case 1: adapter returns new filename and url + const adapterWithReturn = { + createFile: () => { + return Promise.resolve({ + name: 'newfilename.txt', + url: 'http://new.url/newfilename.txt' + }); + }, + getFileLocation: () => { + return Promise.resolve('http://default.url/file.txt'); + }, + validateFilename: () => null + }; + + const controllerWithReturn = new FilesController(adapterWithReturn); + const result1 = await controllerWithReturn.createFile( + config, + 'originalfile.txt', + 'data', + 'text/plain' + ); + + expect(result1.name).toBe('newfilename.txt'); + expect(result1.url).toBe('http://new.url/newfilename.txt'); + + // Test case 2: adapter returns nothing, falling back to default behavior + const adapterWithoutReturn = { + createFile: () => { + return Promise.resolve(); + }, + getFileLocation: (config, filename) => { + return Promise.resolve(`http://default.url/${filename}`); + }, + validateFilename: () => null + }; + + const controllerWithoutReturn = new FilesController(adapterWithoutReturn); + const result2 = await controllerWithoutReturn.createFile( + config, + 'originalfile.txt', + 'data', + 'text/plain', + {}, + { preserveFileName: true } // To make filename predictable + ); + + expect(result2.name).toBe('originalfile.txt'); + expect(result2.url).toBe('http://default.url/originalfile.txt'); + + // Test case 3: adapter returns partial info (only url) + // This is a valid scenario, as the adapter may return a modified filename + // but may result in a mismatch between the filename and the resource URL + const adapterWithOnlyURL = { + createFile: () => { + return Promise.resolve({ + url: 'http://new.url/partialfile.txt' + }); + }, + getFileLocation: () => { + return Promise.resolve('http://default.url/file.txt'); + }, + validateFilename: () => null + }; + + const controllerWithPartial = new FilesController(adapterWithOnlyURL); + const result3 = await controllerWithPartial.createFile( + config, + 'originalfile.txt', + 'data', + 'text/plain', + {}, + { preserveFileName: true } // To make filename predictable + ); + + expect(result3.name).toBe('originalfile.txt'); + expect(result3.url).toBe('http://new.url/partialfile.txt'); // Technically, the resource does not need to match the filename + + // Test case 4: adapter returns only filename + const adapterWithOnlyFilename = { + createFile: () => { + return Promise.resolve({ + name: 'newname.txt' + }); + }, + getFileLocation: (config, filename) => { + return Promise.resolve(`http://default.url/${filename}`); + }, + validateFilename: () => null + }; + + const controllerWithOnlyFilename = new FilesController(adapterWithOnlyFilename); + const result4 = await controllerWithOnlyFilename.createFile( + config, + 'originalfile.txt', + 'data', + 'text/plain', + {}, + { preserveFileName: true } + ); + + expect(result4.name).toBe('newname.txt'); + expect(result4.url).toBe('http://default.url/newname.txt'); + }); }); From a6c260917e39425a9836f808af6cd04229d53c8f Mon Sep 17 00:00:00 2001 From: Adrian Curtin <48138055+AdrianCurtin@users.noreply.github.com> Date: Fri, 17 Jan 2025 13:51:59 -0500 Subject: [PATCH 09/12] Update description of config slightly --- src/Adapters/Files/FilesAdapter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Adapters/Files/FilesAdapter.js b/src/Adapters/Files/FilesAdapter.js index 19846301fb..aaccb49903 100644 --- a/src/Adapters/Files/FilesAdapter.js +++ b/src/Adapters/Files/FilesAdapter.js @@ -33,8 +33,8 @@ export class FilesAdapter { * - tags: object containing key value pairs that will be stored with file * - metadata: object containing key value pairs that will be stored with file (https://docs.aws.amazon.com/AmazonS3/latest/user-guide/add-object-metadata.html) * @discussion options are not supported by all file adapters. Check the your adapter's documentation for compatibility - * @param {Config} config -(Optional) server configuration - * @discussion config is not supported by all file adapters. Check the your adapter's documentation for compatibility + * @param {Config} config - (Optional) server configuration + * @discussion config may be passed to adapter to allow for more complex configuration and internal call of getFileLocation (if needed). This argument is not supported by all file adapters. Check the your adapter's documentation for compatibility * * @return {Promise<{url?: string, name?: string, location?: string}>|Promise} Either a plain promise that should fail if storage didn't succeed, or a promise resolving to an object containing url and/or an updated filename and/or location (if relevant) */ From 441c291fcac758b0b57e1050152f563f0c43bade Mon Sep 17 00:00:00 2001 From: Adrian Curtin <48138055+AdrianCurtin@users.noreply.github.com> Date: Sat, 1 Feb 2025 14:58:30 -0500 Subject: [PATCH 10/12] Modify mock adapter initialization to use struct in beginning --- spec/FilesController.spec.js | 96 ++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 53 deletions(-) diff --git a/spec/FilesController.spec.js b/spec/FilesController.spec.js index 2792290c58..71453523e3 100644 --- a/spec/FilesController.spec.js +++ b/spec/FilesController.spec.js @@ -221,101 +221,91 @@ describe('FilesController', () => { it('should return valid filename or url from createFile response when provided', async () => { const config = Config.get(Parse.applicationId); - + // Test case 1: adapter returns new filename and url - const adapterWithReturn = { - createFile: () => { - return Promise.resolve({ - name: 'newfilename.txt', - url: 'http://new.url/newfilename.txt' - }); - }, - getFileLocation: () => { - return Promise.resolve('http://default.url/file.txt'); - }, - validateFilename: () => null + const adapterWithReturn = { ...mockAdapter }; + adapterWithReturn.createFile = () => { + return Promise.resolve({ + name: 'newFilename.txt', + url: 'http://new.url/newFilename.txt' + }); + }; + adapterWithReturn.getFileLocation = () => { + return Promise.resolve('http://default.url/file.txt'); }; - const controllerWithReturn = new FilesController(adapterWithReturn); const result1 = await controllerWithReturn.createFile( config, - 'originalfile.txt', + 'originalFile.txt', 'data', 'text/plain' ); - - expect(result1.name).toBe('newfilename.txt'); - expect(result1.url).toBe('http://new.url/newfilename.txt'); + expect(result1.name).toBe('newFilename.txt'); + expect(result1.url).toBe('http://new.url/newFilename.txt'); // Test case 2: adapter returns nothing, falling back to default behavior - const adapterWithoutReturn = { - createFile: () => { - return Promise.resolve(); - }, - getFileLocation: (config, filename) => { - return Promise.resolve(`http://default.url/${filename}`); - }, - validateFilename: () => null + const adapterWithoutReturn = { ...mockAdapter }; + adapterWithoutReturn.createFile = () => { + return Promise.resolve(); }; - + adapterWithoutReturn.getFileLocation = (config, filename) => { + return Promise.resolve(`http://default.url/${filename}`); + }; + const controllerWithoutReturn = new FilesController(adapterWithoutReturn); const result2 = await controllerWithoutReturn.createFile( config, - 'originalfile.txt', + 'originalFile.txt', 'data', 'text/plain', {}, { preserveFileName: true } // To make filename predictable ); - expect(result2.name).toBe('originalfile.txt'); - expect(result2.url).toBe('http://default.url/originalfile.txt'); + expect(result2.name).toBe('originalFile.txt'); + expect(result2.url).toBe('http://default.url/originalFile.txt'); // Test case 3: adapter returns partial info (only url) // This is a valid scenario, as the adapter may return a modified filename // but may result in a mismatch between the filename and the resource URL - const adapterWithOnlyURL = { - createFile: () => { - return Promise.resolve({ - url: 'http://new.url/partialfile.txt' - }); - }, - getFileLocation: () => { - return Promise.resolve('http://default.url/file.txt'); - }, - validateFilename: () => null + const adapterWithOnlyURL = { ...mockAdapter }; + adapterWithOnlyURL.createFile = () => { + return Promise.resolve({ + url: 'http://new.url/partialFile.txt' + }); + }; + adapterWithOnlyURL.getFileLocation = () => { + return Promise.resolve('http://default.url/file.txt'); }; const controllerWithPartial = new FilesController(adapterWithOnlyURL); const result3 = await controllerWithPartial.createFile( config, - 'originalfile.txt', + 'originalFile.txt', 'data', 'text/plain', {}, { preserveFileName: true } // To make filename predictable ); - expect(result3.name).toBe('originalfile.txt'); - expect(result3.url).toBe('http://new.url/partialfile.txt'); // Technically, the resource does not need to match the filename + expect(result3.name).toBe('originalFile.txt'); + expect(result3.url).toBe('http://new.url/partialFile.txt'); // Technically, the resource does not need to match the filename // Test case 4: adapter returns only filename - const adapterWithOnlyFilename = { - createFile: () => { - return Promise.resolve({ - name: 'newname.txt' - }); - }, - getFileLocation: (config, filename) => { - return Promise.resolve(`http://default.url/${filename}`); - }, - validateFilename: () => null + const adapterWithOnlyFilename = { ...mockAdapter }; + adapterWithOnlyFilename.createFile = () => { + return Promise.resolve({ + name: 'newname.txt' + }); + }; + adapterWithOnlyFilename.getFileLocation = (config, filename) => { + return Promise.resolve(`http://default.url/${filename}`); }; const controllerWithOnlyFilename = new FilesController(adapterWithOnlyFilename); const result4 = await controllerWithOnlyFilename.createFile( config, - 'originalfile.txt', + 'originalFile.txt', 'data', 'text/plain', {}, From 10eb23e7d3b416bb5b138ca0e4bc940f0b9e4e49 Mon Sep 17 00:00:00 2001 From: Adrian Curtin <48138055+AdrianCurtin@users.noreply.github.com> Date: Sat, 1 Feb 2025 15:08:42 -0500 Subject: [PATCH 11/12] Update to include config in arguments for createFileSpy --- spec/CloudCode.spec.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/spec/CloudCode.spec.js b/spec/CloudCode.spec.js index 99ec4910d1..fbd6fd5324 100644 --- a/spec/CloudCode.spec.js +++ b/spec/CloudCode.spec.js @@ -3687,11 +3687,13 @@ describe('saveFile hooks', () => { foo: 'bar', }, }; + const config = Config.get('test'); expect(createFileSpy).toHaveBeenCalledWith( jasmine.any(String), newData, 'text/plain', - newOptions + newOptions, + config ); }); @@ -3719,11 +3721,13 @@ describe('saveFile hooks', () => { foo: 'bar', }, }; + const config = Config.get('test'); expect(createFileSpy).toHaveBeenCalledWith( jasmine.any(String), newData, newContentType, - newOptions + newOptions, + config ); const expectedFileName = 'donald_duck.pdf'; expect(file._name.indexOf(expectedFileName)).toBe(file._name.length - expectedFileName.length); @@ -3749,11 +3753,13 @@ describe('saveFile hooks', () => { metadata: { foo: 'bar' }, tags: { bar: 'foo' }, }; + const config = Config.get('test'); expect(createFileSpy).toHaveBeenCalledWith( jasmine.any(String), jasmine.any(Buffer), 'text/plain', - options + options, + config ); }); From 05810942a7aa8760a6c164b3ca599b1fae4b41d9 Mon Sep 17 00:00:00 2001 From: Adrian Curtin <48138055+AdrianCurtin@users.noreply.github.com> Date: Thu, 6 Feb 2025 20:46:14 -0500 Subject: [PATCH 12/12] Remove space + move preserve filename args to files controller initializer --- spec/FilesController.spec.js | 18 ++++++++---------- src/Controllers/FilesController.js | 2 +- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/spec/FilesController.spec.js b/spec/FilesController.spec.js index 71453523e3..b0442e74b5 100644 --- a/spec/FilesController.spec.js +++ b/spec/FilesController.spec.js @@ -233,7 +233,8 @@ describe('FilesController', () => { adapterWithReturn.getFileLocation = () => { return Promise.resolve('http://default.url/file.txt'); }; - const controllerWithReturn = new FilesController(adapterWithReturn); + const controllerWithReturn = new FilesController(adapterWithReturn, null, { preserveFileName: true }); + // preserveFileName is true to make filename behaviors predictable const result1 = await controllerWithReturn.createFile( config, 'originalFile.txt', @@ -252,14 +253,13 @@ describe('FilesController', () => { return Promise.resolve(`http://default.url/${filename}`); }; - const controllerWithoutReturn = new FilesController(adapterWithoutReturn); + const controllerWithoutReturn = new FilesController(adapterWithoutReturn, null, { preserveFileName: true }); const result2 = await controllerWithoutReturn.createFile( config, 'originalFile.txt', 'data', 'text/plain', - {}, - { preserveFileName: true } // To make filename predictable + {} ); expect(result2.name).toBe('originalFile.txt'); @@ -278,14 +278,13 @@ describe('FilesController', () => { return Promise.resolve('http://default.url/file.txt'); }; - const controllerWithPartial = new FilesController(adapterWithOnlyURL); + const controllerWithPartial = new FilesController(adapterWithOnlyURL, null, { preserveFileName: true }); const result3 = await controllerWithPartial.createFile( config, 'originalFile.txt', 'data', 'text/plain', - {}, - { preserveFileName: true } // To make filename predictable + {} ); expect(result3.name).toBe('originalFile.txt'); @@ -302,14 +301,13 @@ describe('FilesController', () => { return Promise.resolve(`http://default.url/${filename}`); }; - const controllerWithOnlyFilename = new FilesController(adapterWithOnlyFilename); + const controllerWithOnlyFilename = new FilesController(adapterWithOnlyFilename, null, { preserveFileName: true }); const result4 = await controllerWithOnlyFilename.createFile( config, 'originalFile.txt', 'data', 'text/plain', - {}, - { preserveFileName: true } + {} ); expect(result4.name).toBe('newname.txt'); diff --git a/src/Controllers/FilesController.js b/src/Controllers/FilesController.js index 733b2544cd..32924d6b26 100644 --- a/src/Controllers/FilesController.js +++ b/src/Controllers/FilesController.js @@ -33,7 +33,7 @@ export class FilesController extends AdaptableController { filename = createResult?.name || filename; // if createFile returns a new filename, use it const url = createResult?.url || await this.adapter.getFileLocation(config, filename); // if createFile returns a new url, use it otherwise get the url from the adapter - + return { url: url, name: filename,