Skip to content

Commit 623d083

Browse files
committed
Limit the file adapter config to just the minimum it needs to get location
Strip down the config variables that get sent along with the file
1 parent 3fee23a commit 623d083

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

spec/CloudCode.spec.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3696,12 +3696,17 @@ describe('saveFile hooks', () => {
36963696
},
36973697
};
36983698
const config = Config.get('test');
3699+
const expectedConfig = {
3700+
applicationId: config.applicationId,
3701+
mount: config.mount,
3702+
fileKey: config.fileKey
3703+
};
36993704
expect(createFileSpy).toHaveBeenCalledWith(
37003705
jasmine.any(String),
37013706
newData,
37023707
'text/plain',
37033708
newOptions,
3704-
config
3709+
expectedConfig
37053710
);
37063711
});
37073712

@@ -3730,12 +3735,17 @@ describe('saveFile hooks', () => {
37303735
},
37313736
};
37323737
const config = Config.get('test');
3738+
const expectedConfig = {
3739+
applicationId: config.applicationId,
3740+
mount: config.mount,
3741+
fileKey: config.fileKey
3742+
};
37333743
expect(createFileSpy).toHaveBeenCalledWith(
37343744
jasmine.any(String),
37353745
newData,
37363746
newContentType,
37373747
newOptions,
3738-
config
3748+
expectedConfig
37393749
);
37403750
const expectedFileName = 'donald_duck.pdf';
37413751
expect(file._name.indexOf(expectedFileName)).toBe(file._name.length - expectedFileName.length);
@@ -3762,12 +3772,17 @@ describe('saveFile hooks', () => {
37623772
tags: { bar: 'foo' },
37633773
};
37643774
const config = Config.get('test');
3775+
const expectedConfig = {
3776+
applicationId: config.applicationId,
3777+
mount: config.mount,
3778+
fileKey: config.fileKey
3779+
};
37653780
expect(createFileSpy).toHaveBeenCalledWith(
37663781
jasmine.any(String),
37673782
jasmine.any(Buffer),
37683783
'text/plain',
37693784
options,
3770-
config
3785+
expectedConfig
37713786
);
37723787
});
37733788

src/Controllers/FilesController.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,17 @@ export class FilesController extends AdaptableController {
2929
filename = randomHexString(32) + '_' + filename;
3030
}
3131

32-
const createResult = await this.adapter.createFile(filename, data, contentType, options, config);
32+
// Create a clean config object with only the properties needed by file adapters
33+
const adapterConfig = {
34+
applicationId: config.applicationId,
35+
mount: config.mount,
36+
fileKey: config.fileKey
37+
};
38+
39+
const createResult = await this.adapter.createFile(filename, data, contentType, options, adapterConfig);
3340
filename = createResult?.name || filename; // if createFile returns a new filename, use it
3441

35-
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
42+
const url = createResult?.url || await this.adapter.getFileLocation(adapterConfig, filename); // if createFile returns a new url, use it otherwise get the url from the adapter
3643

3744
return {
3845
url: url,

0 commit comments

Comments
 (0)