Null coalescing for file id

This commit is contained in:
Rory& 2025-09-28 20:36:07 +02:00
parent d59bd1050b
commit f8e4e8864f

View File

@ -73,7 +73,6 @@ router.post(
// validate IDs // validate IDs
const seenIds: (string | undefined)[] = []; const seenIds: (string | undefined)[] = [];
for (const file of payload.files) { for (const file of payload.files) {
file.id ??= "0";
if (seenIds.includes(file.id)) { if (seenIds.includes(file.id)) {
return res.status(400).json({ return res.status(400).json({
code: 400, code: 400,
@ -86,12 +85,12 @@ router.post(
const attachments = await Promise.all( const attachments = await Promise.all(
payload.files.map(async (attachment) => { payload.files.map(async (attachment) => {
attachment.filename = attachment.filename.replaceAll(" ", "_").replace(/[^a-zA-Z0-9._]+/g, ""); attachment.filename = attachment.filename.replaceAll(" ", "_").replace(/[^a-zA-Z0-9._]+/g, "");
const uploadFilename = `${channel_id}/${batchId}/${attachment.id}/${attachment.filename}`; const uploadFilename = `${channel_id}/${batchId}/${attachment.id ?? "0"}/${attachment.filename}`;
const newAttachment = CloudAttachment.create({ const newAttachment = CloudAttachment.create({
user: user, user: user,
channel: channel, channel: channel,
uploadFilename: uploadFilename, uploadFilename: uploadFilename,
userAttachmentId: attachment.id, userAttachmentId: attachment.id ?? "0",
userFilename: attachment.filename, userFilename: attachment.filename,
userFileSize: attachment.file_size, userFileSize: attachment.file_size,
userIsClip: attachment.is_clip, userIsClip: attachment.is_clip,