// biome-ignore lint/correctness/noUnusedImports: Html is the JSX factory (tsconfig jsxFactory: Html.createElement) import { Html } from "@elysiajs/html"; import type { PropsWithChildren } from "@kitajs/html"; import { escapeHTML } from "bun"; import { fileTypeFromBuffer } from "file-type"; import hljs from "highlight.js"; import { humanFileSize, isValidUTF8 } from "./shared"; export const filetypes = ["none", "blob"].concat(hljs.listLanguages().sort()); function Template(props: PropsWithChildren<{ css: string }>) { return ( <> {""}
File not found
); } export function Index(hostname: string) { return (Reload page to try again
); } function humanReadableTime(minutes: number) { const years = Math.floor(minutes / 525600); minutes %= 525600; const days = Math.floor(minutes / 1440); minutes %= 1440; const hours = Math.floor(minutes / 60); minutes %= 60; let result = ""; if (years > 0) result += `${years} year${years > 1 ? "s" : ""} `; if (days > 0) result += `${days} day${days > 1 ? "s" : ""} `; if (hours > 0) result += `${hours} hour${hours > 1 ? "s" : ""} `; if (minutes > 0) result += `${minutes} minute${minutes > 1 ? "s" : ""} `; if (result === "") result = "0 minutes"; return result.trim(); } export async function ShowFile( filename: string, uuid: string, content: Uint8Array | null, filetype: string, delete_at: number | null, ) { //if content is null, this is for the js frontend let preview: JSX.Element; if (!content) { preview = <>Please wait for the file to load>; } else { preview = <>This file can't be previewed>; if (isValidUTF8(content) && filetype !== "blob") { if (filetype === "none") { preview = ({escapeHTML(new TextDecoder("utf-8").decode(content))}
);
} else {
preview = (
{
hljs.highlight(new TextDecoder("utf-8").decode(content), {
language: filetype,
}).value
}
);
}
} else {
const filetype = await fileTypeFromBuffer(content);
if (filetype) {
const base64Content = `data:${filetype.mime};base64,${Buffer.from(content).toString("base64")}`;
if (filetype.mime.startsWith("audio/")) {
preview = ;
} else if (filetype.mime.startsWith("video/")) {
preview = ;
} else if (filetype.mime.startsWith("image/")) {
preview =