diff --git a/src/actions/upload-to-cdn.ts b/src/actions/upload-to-cdn.ts index 8eb3c2dc..7c1a3d31 100644 --- a/src/actions/upload-to-cdn.ts +++ b/src/actions/upload-to-cdn.ts @@ -2,7 +2,9 @@ import { v4 as uuidv4 } from 'uuid'; -export async function uploadFileAction(formData: FormData) { +type FileType = 'webp' | 'pdf'; + +export async function uploadFileAction(formData: FormData, fileType: FileType) { const CDN_BASE_UPLOAD_URL = process.env.CDN_BASE_UPLOAD_URL!; const CDN_BASE_ACCESS_URL = process.env.CDN_BASE_ACCESS_URL!; const CDN_API_KEY = process.env.CDN_API_KEY!; @@ -14,7 +16,7 @@ export async function uploadFileAction(formData: FormData) { if (!file) { return { error: 'File is required', status: 400 }; } - const uploadUrl = `${CDN_BASE_UPLOAD_URL}/${uniqueFileName}.webp`; + const uploadUrl = `${CDN_BASE_UPLOAD_URL}/${uniqueFileName}.${fileType}`; const fileBuffer = Buffer.from(await file.arrayBuffer()); const response = await fetch(uploadUrl, { @@ -28,7 +30,7 @@ export async function uploadFileAction(formData: FormData) { if (response.ok) { return { message: 'File uploaded successfully', - url: `${CDN_BASE_ACCESS_URL}/${uniqueFileName}.webp`, + url: `${CDN_BASE_ACCESS_URL}/${uniqueFileName}.${fileType}`, }; } else { return { error: 'Failed to upload file', status: response.status }; diff --git a/src/components/job-form.tsx b/src/components/job-form.tsx index 1f22ccf0..79a4ee91 100644 --- a/src/components/job-form.tsx +++ b/src/components/job-form.tsx @@ -50,7 +50,7 @@ const PostJobForm = () => { useEffect(() => { if (session.status !== 'loading' && session.status === 'unauthenticated') router.push(`${APP_PATHS.SIGNIN}?redirectTo=/create`); - }, [session.status]); + }, [session.status, router]); const { toast } = useToast(); const companyLogoImg = useRef(null); @@ -116,7 +116,7 @@ const PostJobForm = () => { const uniqueFileName = `${Date.now()}-${file.name}`; formData.append('uniqueFileName', uniqueFileName); - const res = await uploadFileAction(formData); + const res = await uploadFileAction(formData, 'webp'); if (!res) { throw new Error('Failed to upload image'); } diff --git a/src/components/user-multistep-form/add-resume-form.tsx b/src/components/user-multistep-form/add-resume-form.tsx index e51f1a5f..9eb24616 100644 --- a/src/components/user-multistep-form/add-resume-form.tsx +++ b/src/components/user-multistep-form/add-resume-form.tsx @@ -58,7 +58,7 @@ export const AddResume = () => { const uniqueFileName = `${Date.now()}-${file.name}`; formData.append('uniqueFileName', uniqueFileName); - const res = await uploadFileAction(formData); + const res = await uploadFileAction(formData, 'pdf'); if (!res) { return toast({ title: 'Internal Server Error',