fix(upload): scope original S3 keys under assetId to prevent collisions

Both /init and /simple were keying originals as
`originals/${projectId}/${filename}`.  Two uploads of the same filename
into the same project would share a key — the second upload would silently
overwrite the first file in S3 while both assets remained in the DB with
the same original_s3_key.

Changed to `originals/${assetId}/${filename}` (matching the proxies/
convention) so every asset has its own unique S3 prefix.
This commit is contained in:
Zac Gaetano 2026-05-19 00:08:13 -04:00
parent 4f8964e807
commit 58e2e539f8

View file

@ -103,7 +103,8 @@ router.post('/init', async (req, res, next) => {
} }
const assetId = uuidv4(); const assetId = uuidv4();
const s3Key = `originals/${projectId}/${filename}`; // Include assetId in the key so same-named files in a project never collide
const s3Key = `originals/${assetId}/${filename}`;
const tagsArray = tags ? (Array.isArray(tags) ? tags : [tags]) : []; const tagsArray = tags ? (Array.isArray(tags) ? tags : [tags]) : [];
await pool.query( await pool.query(
@ -259,7 +260,8 @@ router.post('/simple', upload.single('file'), async (req, res, next) => {
} }
const assetId = uuidv4(); const assetId = uuidv4();
const s3Key = `originals/${projectId}/${filename}`; // Include assetId in the key so same-named files in a project never collide
const s3Key = `originals/${assetId}/${filename}`;
const mimeType = contentType || req.file.mimetype; const mimeType = contentType || req.file.mimetype;
const tagsArray = tags ? (Array.isArray(tags) ? tags : [tags]) : []; const tagsArray = tags ? (Array.isArray(tags) ? tags : [tags]) : [];