/* ═══════════════════════════════════════════════════════════════ DRIVE FILES Files for the site to link to (server/src/routes/files.js), kept in the shared Google Drive and shared as "anyone with the link can view". The admin side, in one file: FileUploadButton upload one or more files FileList the list both the picker and Tools → Media → Files draw, each with its first-page preview or an icon for its type FilePicker the dialog behind a link field's "Choose a file" (a field with `files: true`, fields.tsx) A link field stores the file's Drive link, a plain URL, so nothing else needs to know where it came from. Files put in the Drive folder by hand are listed too (the server picks them up). ═══════════════════════════════════════════════════════════════ */ import { File as FileIcon, FileAudio, FileDoc, FilePdf, FilePpt, FileXls, FileZip, X, } from "@phosphor-icons/react"; import { useCallback, useEffect, useRef, useState, type ReactNode } from "react"; import { ApiError, get, upload } from "../../lib/api.ts"; import { useAuth } from "../../lib/auth.tsx"; import { canWrite as roleCanWrite } from "../../lib/roles.ts"; import { formatBytes } from "./MediaLibrary.tsx"; export type DriveFile = { id: number; name: string; title: string; mime: string; bytes: number; url: string; preview: string | null; uploaded_by: string | null; created_at: string; }; const button = "rounded-full border border-brand px-3 py-1 text-sm font-medium text-link " + "transition-colors hover:bg-tint disabled:cursor-default disabled:opacity-50"; export const FILE_HELP = "PDF, Word, Excel, PowerPoint (.docx, .xlsx, .pptx), MP3, M4A or zip, up to 50 MB. Stored in the shared Google Drive and viewable by anyone with the link."; const ACCEPT = ".pdf,.docx,.xlsx,.pptx,.mp3,.m4a,.zip"; /* An icon per kind of file; Google's own Docs, Sheets and Slides (application/vnd.google-apps.*) count as their Office kin. */ const TYPE_ICONS: [RegExp, typeof FileIcon][] = [ [/pdf$/, FilePdf], [/wordprocessing|google-apps\.document$/, FileDoc], [/spreadsheet/, FileXls], [/presentation/, FilePpt], [/^audio\//, FileAudio], [/zip$/, FileZip], ]; function TypeIcon({ mime }: { mime: string }) { const Icon = TYPE_ICONS.find(([test]) => test.test(mime))?.[1] ?? FileIcon; return