mirror of
https://github.com/alexandernicholson/s3panoramic.git
synced 2026-05-05 06:20:41 +09:00
feature: v1
This commit is contained in:
parent
6b1e6c945f
commit
6d8acb2752
48
src/templates/components/object_list.ts
Normal file
48
src/templates/components/object_list.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { ListObjectsResult } from "../../types/mod.ts";
|
||||
|
||||
export function objectList(result: ListObjectsResult) {
|
||||
return `
|
||||
<div class="object-list">
|
||||
${result.prefixes.map(prefix => `
|
||||
<div class="folder">
|
||||
<a href="/?prefix=${prefix}"
|
||||
hx-get="/?prefix=${prefix}"
|
||||
hx-target="#browser-navigation, #browser-content"
|
||||
hx-swap="innerHTML"
|
||||
hx-push-url="true">
|
||||
📁 ${prefix}
|
||||
</a>
|
||||
</div>
|
||||
`).join("")}
|
||||
|
||||
${result.objects.map(obj => `
|
||||
<div class="object">
|
||||
<span class="name">📄 ${obj.key}</span>
|
||||
<span class="size">${formatSize(obj.size)}</span>
|
||||
<span class="modified">${formatDate(obj.lastModified)}</span>
|
||||
<a href="/api/download/${encodeURIComponent(obj.key)}"
|
||||
class="download">
|
||||
⬇️ Download
|
||||
</a>
|
||||
</div>
|
||||
`).join("")}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
function formatSize(bytes: number): string {
|
||||
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
|
||||
let size = bytes;
|
||||
let unit = 0;
|
||||
|
||||
while (size >= 1024 && unit < units.length - 1) {
|
||||
size /= 1024;
|
||||
unit++;
|
||||
}
|
||||
|
||||
return `${size.toFixed(1)} ${units[unit]}`;
|
||||
}
|
||||
|
||||
function formatDate(date: Date): string {
|
||||
return date.toLocaleDateString();
|
||||
}
|
||||
Reference in New Issue
Block a user