diff --git a/dump.rdb b/dump.rdb index 05aad7e..4fdc889 100644 Binary files a/dump.rdb and b/dump.rdb differ diff --git a/src/api/index.ts b/src/api/index.ts index 4ab9a57..2d72731 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -7,7 +7,7 @@ import cors from 'cors' import { deleteCustomer } from "./routes/admin/delete-customer"; import { listDeletedCustomers } from "./routes/admin/list-deleted"; import { restoreCustomer } from "./routes/admin/restore-customer"; -import { uploadFile } from "./routes/store/uploads"; +import { uploadFile } from "./routes/global/uploads"; import { S3Client } from "@aws-sdk/client-s3"; export default (rootDirectory: string): Router | Router[] => { diff --git a/src/api/routes/store/uploads.ts b/src/api/routes/global/uploads.ts similarity index 86% rename from src/api/routes/store/uploads.ts rename to src/api/routes/global/uploads.ts index c052667..7f1b965 100644 --- a/src/api/routes/store/uploads.ts +++ b/src/api/routes/global/uploads.ts @@ -15,9 +15,13 @@ export const uploadFile = (router: Router, { s3Client }: { s3Client: S3Client }) return res.status(403).send() } } + const ext = req.query.ext as string + if (!ext) return res.status(422).send('Missing file extension!'); + + const id = req.user.customer_id || req.user.userId; - const key = `${id}/${ulid()}` + const key = `${id}/${ulid()}.${ext}` const command = new PutObjectCommand({ Bucket: process.env.AWS_BUCKET, Key: key }); const url = await getSignedUrl(s3Client, command, { expiresIn: 300 }); // 5 minutes