From 7268403ca4bf7ff3f216d74fcfd6647f8eb69cdd Mon Sep 17 00:00:00 2001 From: maulanasdqn Date: Fri, 10 Apr 2026 14:24:18 +0700 Subject: [PATCH] fix: add image upload size limits for hackathon (#63) - useUploadFile: add 5MB limit + image type validation for team logo/banner uploads (was unrestricted) - useUploadAvatar: tighten limit from 5MB to 2MB per issue request - Submit page: switch from useUploadFile to useUploadSubmission which has proper 50MB limit + broader file type support Size limits: - Profile avatar: 2MB (JPEG, PNG, WebP, GIF) - Team logo/banner: 5MB (JPEG, PNG, WebP, GIF) - Team files: 20MB (images + PDF) - Submissions: 50MB (images, PDF, ZIP, video) Closes #63 Co-Authored-By: Claude Opus 4.6 (1M context) --- apps/hackathon/src/app/teams/[teamId]/submit/page.tsx | 4 ++-- libs/service/src/hooks/upload/index.ts | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/hackathon/src/app/teams/[teamId]/submit/page.tsx b/apps/hackathon/src/app/teams/[teamId]/submit/page.tsx index 47572d7..f54ef95 100644 --- a/apps/hackathon/src/app/teams/[teamId]/submit/page.tsx +++ b/apps/hackathon/src/app/teams/[teamId]/submit/page.tsx @@ -9,7 +9,7 @@ import { useSubmitProject, useTeamById, useTeamSubmission, - useUploadFile, + useUploadSubmission, useAuthStore, } from '@imphnen-frontend-service/service'; import { zodResolver } from '@hookform/resolvers/zod'; @@ -67,7 +67,7 @@ const SubmitProjectPage: FC = (): ReactElement => { const { data: submissionData } = useTeamSubmission(teamId || '', !!teamId); const { mutateAsync: submitProject, isPending: isSubmitting } = useSubmitProject(teamId || ''); - const { mutateAsync: uploadFile, isPending: isUploading } = useUploadFile(); + const { mutateAsync: uploadFile, isPending: isUploading } = useUploadSubmission(); const team = teamData?.data; const currentUserId = session?.user?.id; diff --git a/libs/service/src/hooks/upload/index.ts b/libs/service/src/hooks/upload/index.ts index e44fde1..1811567 100644 --- a/libs/service/src/hooks/upload/index.ts +++ b/libs/service/src/hooks/upload/index.ts @@ -14,6 +14,9 @@ export const useUploadFile = () => { mutationKey: ['upload-file'], mutationFn: async (file: File) => { if (!session?.user?.id) throw new Error('You must be logged in to upload files'); + const allowedTypes = ['image/jpeg', 'image/jpg', 'image/png', 'image/webp', 'image/gif']; + if (!allowedTypes.includes(file.type)) throw new Error('Invalid file type. Allowed: JPEG, PNG, WebP, GIF'); + if (file.size > 5 * 1024 * 1024) throw new Error('File too large. Maximum size: 5MB'); const data = await uploadHackathonTeamFile(file); return { data }; }, @@ -28,7 +31,7 @@ export const useUploadAvatar = () => { if (!session?.user?.id) throw new Error('You must be logged in to upload avatar'); const allowedTypes = ['image/jpeg', 'image/jpg', 'image/png', 'image/webp', 'image/gif']; if (!allowedTypes.includes(file.type)) throw new Error('Invalid file type. Allowed: JPEG, PNG, WebP, GIF'); - if (file.size > 5 * 1024 * 1024) throw new Error('File too large. Maximum size: 5MB'); + if (file.size > 2 * 1024 * 1024) throw new Error('File too large. Maximum size: 2MB'); const data = await uploadHackathonAvatar(file); return { data }; },