Add the addFileNameHash option that allows users to remove the hash f… (#4915)
* Add the addFileNameHash option that allows users to remove the hash from file names * Change option name to preserveFileName * Revert changes to package-lock.json
This commit is contained in:
committed by
Florent Vilmart
parent
0363728b83
commit
6a151ee135
@@ -2,7 +2,7 @@
|
||||
import { randomHexString } from '../cryptoUtils';
|
||||
import AdaptableController from './AdaptableController';
|
||||
import { FilesAdapter } from '../Adapters/Files/FilesAdapter';
|
||||
import path from 'path';
|
||||
import path from 'path';
|
||||
import mime from 'mime';
|
||||
|
||||
const legacyFilesRegex = new RegExp("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}-.*");
|
||||
@@ -25,9 +25,11 @@ export class FilesController extends AdaptableController {
|
||||
contentType = mime.getType(filename);
|
||||
}
|
||||
|
||||
filename = randomHexString(32) + '_' + filename;
|
||||
if (!this.options.preserveFileName) {
|
||||
filename = randomHexString(32) + '_' + filename;
|
||||
}
|
||||
|
||||
var location = this.adapter.getFileLocation(config, filename);
|
||||
const location = this.adapter.getFileLocation(config, filename);
|
||||
return this.adapter.createFile(filename, data, contentType).then(() => {
|
||||
return Promise.resolve({
|
||||
url: location,
|
||||
|
||||
@@ -82,6 +82,7 @@ export function getFilesController(options: ParseServerOptions): FilesController
|
||||
databaseURI,
|
||||
filesAdapter,
|
||||
databaseAdapter,
|
||||
preserveFileName,
|
||||
} = options;
|
||||
if (!filesAdapter && databaseAdapter) {
|
||||
throw 'When using an explicit database adapter, you must also use an explicit filesAdapter.';
|
||||
@@ -89,7 +90,7 @@ export function getFilesController(options: ParseServerOptions): FilesController
|
||||
const filesControllerAdapter = loadAdapter(filesAdapter, () => {
|
||||
return new GridStoreAdapter(databaseURI);
|
||||
});
|
||||
return new FilesController(filesControllerAdapter, appId);
|
||||
return new FilesController(filesControllerAdapter, appId, { preserveFileName });
|
||||
}
|
||||
|
||||
export function getUserController(options: ParseServerOptions): UserController {
|
||||
|
||||
Reference in New Issue
Block a user