Skip to content

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.

1.1 KB
Raw Blame
import { Paperclip } from "lucide-react";

export function DownloadFileButton(
  resumeId: string,
  filePath: any,
  fileTitle: string,
  fileName: string
) {
  const handleDownload = async () => {
    const response = await fetch(
      `/api/profile/resume?resumeId=${encodeURIComponent(resumeId)}`,
      {
        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;
      // Stored basename carries a timestamp and, after a restore, a file id
      link.download = fileName || filePath.split("/").pop();
      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 ${fileName}`}
    >
      <div>{fileTitle}</div>
      <Paperclip className="h-3.5 w-3.5 ml-1" />
    </button>
  );
}