Skip to content

Commit

Permalink
fix pdfile over size
Browse files Browse the repository at this point in the history
  • Loading branch information
JiangShuuu committed Nov 17, 2023
1 parent 76d0279 commit 933844d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/app/dashboard/[fileid]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const Page = async ({ params }: PageProps) => {
// title: 'need Signin'
// })

redirect('/dashboard')
redirect('/')
}

const file = await db.file.findFirst({
Expand Down
19 changes: 18 additions & 1 deletion src/components/button/UploadButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,26 @@ const UploadDropzone = ({ isSubscribed }: { isSubscribed: boolean }) => {
onDrop={async (acceptedFile) => {
setIsUploading(true)

const progressInterval = startSimulatedProgress()
const fileSize = acceptedFile[0].size / 1024 / 1024

if (fileSize > (isSubscribed ? 16 : 4)) {
setIsUploading(false)
acceptedFile.splice(0, 1) // remove file
return toast({
title: 'The file size exceeds the limit.',
description: `Files cannot exceed ${isSubscribed ? 16 : 4} MB or Upgrade the plan.`,
variant: 'destructive'
})
}

const progressInterval = startSimulatedProgress()
// handle file uploading
const res = await startUpload(acceptedFile)

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

if (!key) {
clearInterval(progressInterval)
setUploadProgress(0)
setIsUploading(false)
return toast({
title: 'Something went wrong',
description: 'Please try again later',
Expand Down

0 comments on commit 933844d

Please sign in to comment.