Skip to content

Commit 933844d

Browse files
committed
fix pdfile over size
1 parent 76d0279 commit 933844d

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/app/dashboard/[fileid]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const Page = async ({ params }: PageProps) => {
2323
// title: 'need Signin'
2424
// })
2525

26-
redirect('/dashboard')
26+
redirect('/')
2727
}
2828

2929
const file = await db.file.findFirst({

src/components/button/UploadButton.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,26 @@ const UploadDropzone = ({ isSubscribed }: { isSubscribed: boolean }) => {
5151
onDrop={async (acceptedFile) => {
5252
setIsUploading(true)
5353

54-
const progressInterval = startSimulatedProgress()
54+
const fileSize = acceptedFile[0].size / 1024 / 1024
5555

56+
if (fileSize > (isSubscribed ? 16 : 4)) {
57+
setIsUploading(false)
58+
acceptedFile.splice(0, 1) // remove file
59+
return toast({
60+
title: 'The file size exceeds the limit.',
61+
description: `Files cannot exceed ${isSubscribed ? 16 : 4} MB or Upgrade the plan.`,
62+
variant: 'destructive'
63+
})
64+
}
65+
66+
const progressInterval = startSimulatedProgress()
5667
// handle file uploading
5768
const res = await startUpload(acceptedFile)
5869

5970
if (!res) {
71+
clearInterval(progressInterval)
72+
setUploadProgress(0)
73+
setIsUploading(false)
6074
return toast({
6175
title: 'Something went wrong',
6276
description: 'Please try again later',
@@ -69,6 +83,9 @@ const UploadDropzone = ({ isSubscribed }: { isSubscribed: boolean }) => {
6983
const key = fileResponse?.key
7084

7185
if (!key) {
86+
clearInterval(progressInterval)
87+
setUploadProgress(0)
88+
setIsUploading(false)
7289
return toast({
7390
title: 'Something went wrong',
7491
description: 'Please try again later',

0 commit comments

Comments
 (0)