feat: allows local update api to replace existing files with newly uploaded ones
This commit is contained in:
@@ -12,6 +12,7 @@ export type Options = {
|
||||
overrideAccess?: boolean
|
||||
showHiddenFields?: boolean
|
||||
filePath?: string
|
||||
overwriteExistingFiles?: boolean
|
||||
}
|
||||
|
||||
export default async function update(options: Options): Promise<Document> {
|
||||
@@ -26,6 +27,7 @@ export default async function update(options: Options): Promise<Document> {
|
||||
overrideAccess = true,
|
||||
showHiddenFields,
|
||||
filePath,
|
||||
overwriteExistingFiles = false,
|
||||
} = options;
|
||||
|
||||
const collection = this.collections[collectionSlug];
|
||||
@@ -37,6 +39,7 @@ export default async function update(options: Options): Promise<Document> {
|
||||
overrideAccess,
|
||||
id,
|
||||
showHiddenFields,
|
||||
overwriteExistingFiles,
|
||||
req: {
|
||||
user,
|
||||
payloadAPI: 'local',
|
||||
|
||||
@@ -27,6 +27,7 @@ export type Arguments = {
|
||||
disableVerificationEmail?: boolean
|
||||
overrideAccess?: boolean
|
||||
showHiddenFields?: boolean
|
||||
overwriteExistingFiles?: boolean
|
||||
}
|
||||
|
||||
async function update(incomingArgs: Arguments): Promise<Document> {
|
||||
@@ -60,6 +61,7 @@ async function update(incomingArgs: Arguments): Promise<Document> {
|
||||
},
|
||||
overrideAccess,
|
||||
showHiddenFields,
|
||||
overwriteExistingFiles = false,
|
||||
} = args;
|
||||
|
||||
if (!id) {
|
||||
@@ -135,7 +137,7 @@ async function update(incomingArgs: Arguments): Promise<Document> {
|
||||
const file = ((req.files && req.files.file) ? req.files.file : req.file) as UploadedFile;
|
||||
|
||||
if (file) {
|
||||
const fsSafeName = await getSafeFilename(staticPath, file.name);
|
||||
const fsSafeName = overwriteExistingFiles ? await getSafeFilename(staticPath, file.name) : file.name;
|
||||
|
||||
try {
|
||||
if (!disableLocalStorage) {
|
||||
|
||||
Reference in New Issue
Block a user