From 1ce8019188545298137face73c274e11826dc392 Mon Sep 17 00:00:00 2001 From: Labham Jain Date: Mon, 9 Oct 2023 14:22:39 +0530 Subject: [PATCH 1/2] feat: update upload route --- dump.rdb | Bin 102709 -> 102386 bytes src/api/index.ts | 2 +- src/api/routes/{store => global}/uploads.ts | 6 +++++- 3 files changed, 6 insertions(+), 2 deletions(-) rename src/api/routes/{store => global}/uploads.ts (86%) diff --git a/dump.rdb b/dump.rdb index 05aad7e07fa9ced45fe927337c786cd4798fbde2..4fdc889ea511fc7184e10b4a145f61b82257bff1 100644 GIT binary patch delta 1169 zcmZvbU2Icj7{||h+O=c-fPJu8$HqVwNMz*nYwa1RZBM__+S1dO^}`B1<{ZeDjeWF` zOii|3pms=@F?wzkvdIODPC=a}Uab&sdgI(?%%T_XyTe!vtd4dTL?fPc7&YO&d)_C{ zFaPJ4JTsHB!e!aG_Q0Rlp5Y!=o=I_RTQAppBiUMuJybG%C)@f5Ii~lO9&Q%<3;RO` z_{I#d^Y3JUr?P_OdYGYEj6ab9I{v2&(C~^ekbJhXf3T}>uq!RL)TuPn)5Eb;-@0a%^9#)-o<8du>HVR!JXw!r&DdC(=*fH=W{aZ z^P_XS=lJYlKz%*`1_*;;)!m9Bth=VFK$`qc(jPVJ{bWq5H9N_;$J0qff>AfB&yOTf z<2qCyx2}UCg0cy;y#Un|sw&{c*BX)=NU;Ic4s>;6MA-A2fb|Fx0WY5VfB`E&Ca6|K zZj6i(ZkNq#^J{&P_K?>R4A7{dlyoFeQwb`MGo_?mc>0%3sG}@BVYi6iIp9 zK~I|7eOl6G4#ud6T}M0g`^|UivY>c-Bq21e{Ub?4E6b9q&i$X3C|eSyzS^{8wc7%2 zLpVs2p=iwQrosf-z7?%$i-g@0qY2ezn7jnQqa7Fq&ewA02iW6x(-wD4?4FQg*fdtd z54-@Lt0x0b;=a#<&ssm)D?ySLDZ{cHo86Bj^149CZw&i7O)j4pl%4f&QhY|cYPBAIWoVfZqb zhBabog_U_J4(?rlz9qk`UV;j0`RbCiAYI3#%Z;!=0 z@+H(X50x)l=Ru(YR$NBa3-FZEhN>3uLh!!j9#Snrr5#Nz;#WcdNfrg{hOqBJwwt=2 zq>&^iEni`)1UA!5&hnnnbZJF-@Rt0-o*eixVp&D1TzNWYS-!1&T@-5neYC9f``+eW} z?cKvS-aGsjasJkLVD`(Gcq0x%4F&Qwj4*W=X;yGBOMEj;`7TVq&P&xFNAdDmJzUton745zq-J1bVopLFbrPf=PnNZ4V z&*3bqHD$Ah?eSpwnd7FV)M{!u)ZA!Ts?l>ywG6#!=+@}L9YE3p*LU|O)1^~Mu_UkM z+s#}Rq4}l6sz!?PI>8njTOyNQ>kIdVAMNkA0e5^qBEciVH;w%E%no4Zj&^6gL$gLv zFMHh2ZkR?95>hZ2Cd5p*z;XE?N|G=MLo^fcd*+-g8>ZE)_k5mX%f3_g`VM%K9(;MP z=bX?Lu4LmyHQicUEK;#{ZGLepMMpAty(&w{(n9gRa7lP$6zKFh+P{psXT55tr5md0 z<-G_Z5+@)InH<6J1mq#8>voCHR!CJjt?SdU$}|{r~jduIuc$O#Au{n4<@Kl{=Hz(a-{s&E|2| zdb!cWb-cxJkp+#iL{(4AMtYwR0zn9roxaTxL0BahS&Bh@vMocNC7c; zJ6@8i8Po}o9cuw5SK5KtczBOmrFe*j*T!5LJ+RELCc~*>BALQbT0|YWmiMP}tDDV> zY{e=?8!<7OlKa9(`F!_U2FvK2{Rl}a+BRg { 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..b2a1714 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 From bd58520f5dc9f36b1d8eba6262563679f485034f Mon Sep 17 00:00:00 2001 From: Labham Jain Date: Mon, 9 Oct 2023 14:29:32 +0530 Subject: [PATCH 2/2] feat: update upload route --- src/api/routes/global/uploads.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/routes/global/uploads.ts b/src/api/routes/global/uploads.ts index b2a1714..7f1b965 100644 --- a/src/api/routes/global/uploads.ts +++ b/src/api/routes/global/uploads.ts @@ -21,7 +21,7 @@ export const uploadFile = (router: Router, { s3Client }: { s3Client: S3Client }) const id = req.user.customer_id || req.user.userId; - const key = `${id}_${ulid()}.${ext}` + 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