diff --git a/src/actions/upload-to-cdn.ts b/src/actions/upload-to-cdn.ts new file mode 100644 index 00000000..935d0754 --- /dev/null +++ b/src/actions/upload-to-cdn.ts @@ -0,0 +1,42 @@ +'use server'; + +import { v4 as uuidv4 } from 'uuid'; + +export async function uploadFileAction(formData: FormData) { + 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!; + + try { + const file = formData.get('file') as File; + const uniqueFileName = formData.get('uniqueFileName') || uuidv4(); // Generate unique key if not provided + + if (!file) { + return { error: 'File is required', status: 400 }; + } + + const uploadUrl = `${CDN_BASE_UPLOAD_URL}/${uniqueFileName}`; + const fileBuffer = Buffer.from(await file.arrayBuffer()); + + const response = await fetch(uploadUrl, { + method: 'PUT', + headers: { + AccessKey: CDN_API_KEY, + 'Content-Type': 'application/octet-stream', + }, + body: fileBuffer, + }); + + if (response.ok) { + return { + message: 'File uploaded successfully', + url: `${CDN_BASE_ACCESS_URL}/${uniqueFileName}`, + }; + } else { + return { error: 'Failed to upload file', status: response.status }; + } + } catch (error) { + console.error('Error uploading file:', error); + return { error: 'Internal server error', status: 500 }; + } +} diff --git a/src/app/api/upload-to-cdn/route.ts b/src/app/api/upload-to-cdn/route.ts deleted file mode 100644 index 9f34d64a..00000000 --- a/src/app/api/upload-to-cdn/route.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { serverEnv } from '@/env/server'; -import { NextResponse } from 'next/server'; -import { v4 as uuidv4 } from 'uuid'; - -const CDN_BASE_UPLOAD_URL = serverEnv.CDN_BASE_UPLOAD_URL; -const CDN_BASE_ACCESS_URL = serverEnv.CDN_BASE_ACCESS_URL; -const CDN_API_KEY = serverEnv.CDN_API_KEY!; - -export async function POST(req: Request): Promise { - try { - const formData = await req.formData(); - const file = formData.get('file') as File; - const uniqueFileName = formData.get('uniqueFileName') || uuidv4(); // Generate unique key if not provided - - if (!file) { - return NextResponse.json({ error: 'File is required' }, { status: 400 }); - } - - const uploadUrl = `${CDN_BASE_UPLOAD_URL}/${uniqueFileName}`; - - const fileBuffer = Buffer.from(await file.arrayBuffer()); - - const response = await fetch(uploadUrl, { - method: 'PUT', - headers: { - AccessKey: CDN_API_KEY, - 'Content-Type': 'application/octet-stream', - }, - body: fileBuffer, - }); - - if (response.ok) { - return NextResponse.json({ - message: 'File uploaded successfully', - url: `${CDN_BASE_ACCESS_URL}/${uniqueFileName}`, - }); - } else { - return NextResponse.json( - { error: 'Failed to upload file' }, - { status: response.status } - ); - } - } catch (error) { - console.error('Error uploading file to BunnyCDN:', error); - return NextResponse.json( - { error: 'Internal server error' }, - { status: 500 } - ); - } -} diff --git a/src/layouts/header.tsx b/src/layouts/header.tsx index 2a6a1a87..e5c90389 100644 --- a/src/layouts/header.tsx +++ b/src/layouts/header.tsx @@ -45,58 +45,61 @@ const Header = () => { }, []); return ( - + +
+ ); }; diff --git a/src/lib/validators/jobs.validator.ts b/src/lib/validators/jobs.validator.ts index ab88d8f6..4162c949 100644 --- a/src/lib/validators/jobs.validator.ts +++ b/src/lib/validators/jobs.validator.ts @@ -8,7 +8,7 @@ export const JobPostSchema = z companyName: z.string().min(1, 'Company Name is required'), city: z.string().min(1, 'City Name is required'), address: z.string().min(1, 'Address is required'), - application: z.string(), + application: z.string().min(1, 'Application link is required'), type: z.nativeEnum(EmployementType, { message: 'Employment Type is Required', }), @@ -43,14 +43,14 @@ export const JobPostSchema = z if (data.hasSalaryRange) { if (!data.minSalary) { return ctx.addIssue({ - message: 'minSalary is required when hasSalaryRange is true', + message: 'minSalary is required ', path: ['minSalary'], code: z.ZodIssueCode.custom, }); } if (!data.maxSalary) { return ctx.addIssue({ - message: 'maxSalary is required when hasSalaryRange is true', + message: 'maxSalary is required ', path: ['maxSalary'], code: z.ZodIssueCode.custom, });