Use default ID on file upload requests

This commit is contained in:
Rory& 2025-09-28 20:32:34 +02:00
parent f20dff80ef
commit d59bd1050b
2 changed files with 15 additions and 1 deletions

View File

@ -69,6 +69,20 @@ router.post(
const cdnUrl = Config.get().cdn.endpointPublic;
const batchId = `CLOUD_${user.id}_${randomString(128)}`;
// validate IDs
const seenIds: (string | undefined)[] = [];
for (const file of payload.files) {
file.id ??= "0";
if (seenIds.includes(file.id)) {
return res.status(400).json({
code: 400,
message: `Duplicate attachment ID: ${file.id}`,
});
}
seenIds.push(file.id);
}
const attachments = await Promise.all(
payload.files.map(async (attachment) => {
attachment.filename = attachment.filename.replaceAll(" ", "_").replace(/[^a-zA-Z0-9._]+/g, "");

View File

@ -22,7 +22,7 @@ export interface UploadAttachmentRequestSchema {
}
export interface UploadAttachmentRequest {
id: string;
id?: string;
filename: string;
file_size: number;
is_clip?: boolean;