{filename}
{preview}
import { Html } from '@elysiajs/html' import { PropsWithChildren } from '@kitajs/html' import { escapeHTML } from 'bun' import { fileTypeFromBuffer } from 'file-type' import hljs from 'highlight.js' import isValidUTF8 from 'utf-8-validate' import { humanFileSize } from './shared' const filetypes = ["none", "blob"].concat(hljs.listLanguages().sort()) function Template(props: PropsWithChildren<{ css: string }>) { return ( <> {''}
File not found
) } export function Index(hostname: string, withJs: boolean) { let body = ( <> {withJs ?Reload page to try again
) } export async function ShowFile(filename: string, uuid: string, content: Uint8Array | null, filetype: string) { //if content is null, this is for the js frontend let preview; if (!content) { preview = <>Please wait for the file to load> } else { preview = <>This file can't be previewed> if (isValidUTF8(Buffer.from(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 =