import { layout, escHtml } from './layout.ts';
import type { FileRow } from '../db/files.ts';
export function fileListPage(files: FileRow[], baseUrl: string): string {
const rows = files.length === 0
? '
| No files yet. Upload one. |
'
: files.map((f) => {
const shareUrl = `${baseUrl}/f/${escHtml(f.id)}`;
return `
| ${escHtml(f.original_name)} |
${escHtml(f.mime_type)} |
${formatBytes(f.size)} |
${escHtml(f.created_at)} |
|
`;
}).join('');
return layout('My files', `
My files
Upload new file
| Name | Type | Size | Uploaded | |
${rows}
`, { authed: true });
}
function formatBytes(bytes: number): string {
if (bytes < 1024) return `${bytes} B`;
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
}