joschan21 / quill

Quill - A Modern SaaS-Platform Built With Next.js 13
1.86k stars 490 forks source link

first file uploadstatus changed to 'FAILED' as required but then changes to 'SUCCESS' even the file is not eligible for 'SUCCESS' #20

Open nishchal27 opened 10 months ago

nishchal27 commented 10 months ago

path: https://github.com/joschan21/quill/blob/master/src/app/api/uploadthing/core.ts

file: core.ts

there is a potential flaw in the approach where the upload status is updated to "SUCCESS" without considering any condition. This means that regardless of whether the upload exceeded the allowed limit or not, the upload status will always be set to "SUCCESS" at the end of the function.

To address this flaw, it would be better to update the upload status to "SUCCESS" only if the upload did not exceed the allowed limit. Currently, the code only updates the upload status to "FAILED" if the limit is exceeded, but it does not provide a corresponding update to set the status to "SUCCESS" if the limit is not exceeded. This inconsistency could lead to incorrect status reporting in the database.

You can add an additional check before the last db.file.update() call to update the upload status to "SUCCESS" only when the limit is not exceeded. This can be done by negating the condition used to update the status to "FAILED". For example:

if (!(isSubscribed && isProExceeded) && !(isFreeExceeded)) { await db.file.update({ data: { uploadStatus: 'SUCCESS', }, where: { id: createdFile.id, }, }); }

raheemlawal commented 10 months ago

I second this! Great find.

PHANTOMGOD2OP commented 9 months ago

Send the whole core.ts file code here

inextdeve commented 9 months ago

you can just add a return after the db update:

if ((isSubscribed && isProExceeded) || (!isSubscribed && isFreeExceeded)) { await db.file.update({ where: { id: createdFile.id, }, data: { uploadStatus: "FAILED", }, }); return; }