Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.
TypeScript ai-agentai-resume-analyzerapplication-trackerapplication-tracking-systematscareerjob-applicationjob-automationjob-huntingjob-searchjob-seeker-toolsjob-trackerjob-trackingjobsearchjobseekersmcpollamaresumeresume-reviewself-hosted
Add resume file upload when creating resume
Khuram Niaza775f0f6b634
diff --git a/Dockerfile b/Dockerfileindex a828212..bc13afe 100644--- a/Dockerfile+++ b/Dockerfile@@ -1,5 +1,5 @@# Use the official Node.js 18 image as the base image-FROM node:18.20-alpine AS base+FROM node:20-alpine AS base# Install dependencies only when neededFROM base AS deps@@ -67,6 +67,9 @@ RUN addgroup --system --gid 1001 nodejs && \RUN mkdir .nextRUN chown nextjs:nodejs .next+# Set up /data directory with the right permissions+RUN mkdir -p /data/files/resumes && chown -R nextjs:nodejs /data/files/resumes+# Automatically leverage output traces to reduce image size# https://nextjs.org/docs/advanced-features/output-file-tracingCOPY --from=builder /app/public ./publicdiff --git a/src/actions/profile.actions.ts b/src/actions/profile.actions.tsindex efa8c26..f4b193c 100644--- a/src/actions/profile.actions.ts+++ b/src/actions/profile.actions.ts@@ -10,6 +10,8 @@ import { ResumeSection, SectionType, Summary } from "@/models/profile.model";import { getCurrentUser } from "@/utils/user.utils";import { revalidatePath } from "next/cache";import { z } from "zod";+import path from "path";+import fs from "fs";export const getResumeList = async (page = 1,@@ -69,6 +71,7 @@ export const getResumeById = async (},include: {ContactInfo: true,+ File: true,ResumeSections: {include: {summary: true,@@ -258,7 +261,8 @@ export const editResume = async (};export const deleteResumeById = async (- resumeId: string+ resumeId: string,+ fileId?: string): Promise<any | undefined> => {try {const user = await getCurrentUser();@@ -266,8 +270,22 @@ export const deleteResumeById = async (if (!user) {throw new Error("Not authenticated");}+ if (fileId) {+ const file = await prisma.file.findFirst({+ where: {+ id: fileId,+ },+ });- // TODO: Check if resume is associated with any job+ const filePath = file?.filePath as string;++ const fullFilePath = path.join(filePath);+ if (!fs.existsSync(filePath)) {+ throw new Error("File not found");+ }+ fs.unlinkSync(filePath);+ console.log("file deleted successfully!");+ }await prisma.$transaction(async (prisma) => {await prisma.contactInfo.deleteMany({@@ -309,6 +327,14 @@ export const deleteResumeById = async (await prisma.resume.delete({where: { id: resumeId },});++ if (fileId) {+ await prisma.file.delete({+ where: {+ id: fileId,+ },+ });+ }});return { success: true };} catch (error) {diff --git a/src/app/api/profile/resume/route.ts b/src/app/api/profile/resume/route.tsindex 245f3e9..d429938 100644--- a/src/app/api/profile/resume/route.ts+++ b/src/app/api/profile/resume/route.ts@@ -7,14 +7,23 @@ import fs from "fs";import { writeFile } from "fs/promises";import { getTimestampedFileName } from "@/lib/utils";-export const POST = async (req: NextRequest, res: NextApiResponse) => {+export const POST = async (req: NextRequest, res: NextResponse) => {const session = await auth();const userId = session?.accessToken.sub;let filePath;+ // try using same endpoint to edit, use id and fileid to update+try {if (!session || !session.user) {- return res.status(401).json({ message: "Not Authenticated" });+ return NextResponse.json(+ {+ error: "Not Authenticated",+ },+ {+ status: 401,+ }+ );}const formData = await req.formData();const title = formData.get("title") as string;@@ -24,7 +33,9 @@ export const POST = async (req: NextRequest, res: NextApiResponse) => {const bytes = await file.arrayBuffer();const buffer = new Uint8Array(bytes);- const uploadDir = path.join("data", "files", "resumes");+ const dataPath = process.env.NODE_ENV !== "production" ? "data" : "/data";++ const uploadDir = path.join(dataPath, "files", "resumes");if (!fs.existsSync(uploadDir)) {fs.mkdirSync(uploadDir, { recursive: true });@@ -44,13 +55,88 @@ export const POST = async (req: NextRequest, res: NextApiResponse) => {return NextResponse.json(response, { status: 201 });} catch (error) {console.error(error);- return NextResponse.json(- {- error: "File upload failed",+ if (error instanceof Error) {+ return NextResponse.json(+ {+ error: error.message ?? "File upload failed",+ },+ {+ status: 500,+ }+ );+ }+ }+};++export const GET = async (req: NextRequest, res: NextApiResponse) => {+ const session = await auth();+ const userId = session?.accessToken.sub;++ try {+ if (!session || !session.user) {+ return NextResponse.json(+ {+ error: "Not Authenticated",+ },+ {+ status: 401,+ }+ );+ }++ const { searchParams } = new URL(req.url);+ const filePath = searchParams.get("filePath");++ if (!filePath) {+ return NextResponse.json(+ { error: "File path is required" },+ { status: 400 }+ );+ }++ const fullFilePath = path.join(filePath);+ if (!fs.existsSync(fullFilePath)) {+ return NextResponse.json({ error: "File not found" }, { status: 404 });+ }++ const fileType = path.extname(fullFilePath).toLowerCase();+ const fileName = path.basename(fullFilePath);++ let contentType;++ if (fileType === ".pdf") {+ contentType = "application/pdf";+ } else if (fileType === ".doc" || fileType === ".docx") {+ contentType =+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document";+ } else {+ return NextResponse.json(+ { error: "Unsupported file type" },+ { status: 400 }+ );+ }++ const fileContent = fs.readFileSync(fullFilePath);++ const response = new NextResponse(fileContent, {+ headers: {+ "Content-Type": contentType,+ "Content-Disposition": `attachment; filename="${fileName}"`,},- {- status: 500,- }- );+ });++ return response;+ } catch (error) {+ console.error(error);+ if (error instanceof Error) {+ return NextResponse.json(+ {+ error: error.message ?? "File download failed",+ },+ {+ status: 500,+ }+ );+ }}};diff --git a/src/components/profile/AiResumeReviewSection.tsx b/src/components/profile/AiResumeReviewSection.tsxindex 499c107..ce3755d 100644--- a/src/components/profile/AiResumeReviewSection.tsx+++ b/src/components/profile/AiResumeReviewSection.tsx@@ -122,7 +122,7 @@ const AiResumeReviewSection = ({ resume }: AiSectionProps) => {variant="outline"className="h-8 gap-1 cursor-pointer"onClick={() => triggerSheetChange(true)}- disabled={loading}+ disabled={loading || resume.ResumeSections?.length! < 2}><Sparkles className="h-3.5 w-3.5" /><span className="sr-only sm:not-sr-only sm:whitespace-nowrap">diff --git a/src/components/profile/CreateResume.tsx b/src/components/profile/CreateResume.tsxindex d906ab8..378d650 100644--- a/src/components/profile/CreateResume.tsx+++ b/src/components/profile/CreateResume.tsx@@ -46,6 +46,9 @@ function CreateResume({const form = useForm<z.infer<typeof CreateResumeFormSchema>>({resolver: zodResolver(CreateResumeFormSchema),mode: "onChange",+ defaultValues: {+ title: "",+ },});const {@@ -56,17 +59,14 @@ function CreateResume({const closeDialog = () => setResumeDialogOpen(false);useEffect(() => {- if (resumeToEdit) {- reset(- {- id: resumeToEdit.id,- title: resumeToEdit.title,- },- { keepDefaultValues: true }- );- } else {- reset();- }+ reset(+ {+ id: resumeToEdit?.id ?? undefined,+ title: resumeToEdit?.title ?? "",+ fileId: resumeToEdit?.FileId ?? undefined,+ },+ { keepDefaultValues: true }+ );}, [resumeToEdit, reset]);const onSubmit = (data: z.infer<typeof CreateResumeFormSchema>) => {@@ -82,12 +82,11 @@ function CreateResume({body: formData,});const response = await res.json();- console.log("Response: ", response);if (!response.success) {toast({variant: "destructive",title: "Error!",- description: response.message,+ description: response.error,});} else {reset();@@ -152,7 +151,9 @@ function CreateResume({<Inputtype="file"accept=".pdf,.doc,.docx"- onChange={(e) => field.onChange(e.target.files?.[0])}+ onChange={(e) => {+ field.onChange(e.target.files?.[0] || null);+ }}/></FormControl><FormMessage>diff --git a/src/components/profile/ResumeContainer.tsx b/src/components/profile/ResumeContainer.tsxindex b0da211..4d1b6cf 100644--- a/src/components/profile/ResumeContainer.tsx+++ b/src/components/profile/ResumeContainer.tsx@@ -8,11 +8,11 @@ import SummarySectionCard from "./SummarySectionCard";import ExperienceCard from "./ExperienceCard";import EducationCard from "./EducationCard";import AiResumeReviewSection from "./AiResumeReviewSection";+import { Paperclip } from "lucide-react";function ResumeContainer({ resume }: { resume: Resume }) {const resumeSectionRef = useRef<AddResumeSectionRef>(null);const { title, ContactInfo, ResumeSections } = resume ?? {};-const summarySection = ResumeSections?.find((section) => section.sectionType === SectionType.SUMMARY);@@ -47,12 +47,54 @@ function ResumeContainer({ resume }: { resume: Resume }) {resumeSectionRef.current?.openEducationDialog(section);};+ function DownloadFileButton(filePath: any, fileName: string) {+ const handleDownload = async () => {+ const response = await fetch(+ `/api/profile/resume?filePath=${encodeURIComponent(filePath)}`,+ {+ method: "GET",+ headers: {+ "Content-Type": "application/json",+ },+ }+ );++ if (response.ok) {+ const blob = await response.blob();+ const url = window.URL.createObjectURL(blob);+ const link = document.createElement("a");+ link.href = url;+ link.download = filePath.split("/").pop(); // Get the file name+ link.target = "_blank";+ link.click();+ window.URL.revokeObjectURL(url); // Clean up+ } else {+ console.error("Failed to download file");+ }+ };++ return (+ <button+ className="flex items-center"+ onClick={handleDownload}+ title="Download resume"+ >+ <div>{fileName}</div>+ <Paperclip className="h-3.5 w-3.5 ml-1" />+ </button>+ );+ }+return (<><Card><CardHeader className="flex-row justify-between items-center"><CardTitle>Resume</CardTitle>- <CardDescription>{title}</CardDescription>+ <CardDescription>+ {resume.FileId && resume.File?.filePath+ ? DownloadFileButton(resume.File?.filePath, title)+ : title}+ </CardDescription><div className="flex items-center"><AddResumeSection resume={resume} ref={resumeSectionRef} /><AiResumeReviewSection resume={resume} />diff --git a/src/components/profile/ResumeTable.tsx b/src/components/profile/ResumeTable.tsxindex e670d63..7fe50ca 100644--- a/src/components/profile/ResumeTable.tsx+++ b/src/components/profile/ResumeTable.tsx@@ -56,18 +56,23 @@ function ResumeTable({ResumeTableProps) {const [alertOpen, setAlertOpen] = useState(false);const [resumeIdToDelete, setResumeIdToDelete] = useState<string>();+ const [fileIdToDelete, setFileIdToDelete] = useState<string>();const onDeleteResume = useMemo(- () => (resumeId: string | undefined) => {+ () => (resumeId: string | undefined, fileId?: string) => {if (!resumeId) return;setAlertOpen(true);setResumeIdToDelete(resumeId);+ setFileIdToDelete(fileId);},[]);- const deleteResume = async (resumeId: string | undefined) => {+ const deleteResume = async (+ resumeId: string | undefined,+ fileId?: string+ ) => {if (!resumeId) return;- const { success, message } = await deleteResumeById(resumeId);+ const { success, message } = await deleteResumeById(resumeId, fileId);if (success) {toast({variant: "success",@@ -141,7 +146,7 @@ ResumeTableProps) {</Link><DropdownMenuItemclassName="text-red-600 cursor-pointer"- onClick={() => onDeleteResume(resume.id)}+ onClick={() => onDeleteResume(resume.id, resume.FileId)}><Trash className="mr-2 h-4 w-4" />Delete@@ -169,7 +174,7 @@ ResumeTableProps) {<AlertDialogCancel>Cancel</AlertDialogCancel><AlertDialogActionclassName={buttonVariants({ variant: "destructive" })}- onClick={() => deleteResume(resumeIdToDelete)}+ onClick={() => deleteResume(resumeIdToDelete, fileIdToDelete)}>Delete</AlertDialogAction>diff --git a/src/models/createResumeForm.schema.ts b/src/models/createResumeForm.schema.tsindex 4517b17..a571fb1 100644--- a/src/models/createResumeForm.schema.ts+++ b/src/models/createResumeForm.schema.ts@@ -25,4 +25,5 @@ export const CreateResumeFormSchema = z.object({message: "File size must be less than 5MB",}).optional(),+ fileId: z.string().optional(),});diff --git a/src/models/profile.model.ts b/src/models/profile.model.tsindex b5b7c93..83351d0 100644--- a/src/models/profile.model.ts+++ b/src/models/profile.model.ts@@ -8,6 +8,7 @@ export interface Resume {updatedAt?: Date;ContactInfo?: ContactInfo;ResumeSections?: ResumeSection[];+ FileId?: string;File?: File;}