-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
107 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { Blob } from "blossom-client"; | ||
import { servers } from "../services/servers"; | ||
import { get } from "svelte/store"; | ||
import mime from "mime"; | ||
|
||
export function getBlobURL(blob: { sha256: string; type?: string }, server = get(servers)[0]) { | ||
return server | ||
? new URL(blob.sha256 + (blob.type ? "." + mime.getExtension(blob.type) : ""), server).toString() | ||
: undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copied from https://git.v0l.io/Kieran/dtan/src/branch/main/src/const.ts#L220 | ||
export const kiB = Math.pow(1024, 1); | ||
export const MiB = Math.pow(1024, 2); | ||
export const GiB = Math.pow(1024, 3); | ||
export const TiB = Math.pow(1024, 4); | ||
export const PiB = Math.pow(1024, 5); | ||
export const EiB = Math.pow(1024, 6); | ||
export const ZiB = Math.pow(1024, 7); | ||
export const YiB = Math.pow(1024, 8); | ||
|
||
export function formatBytes(b: number, f?: number) { | ||
f ??= 2; | ||
if (b >= YiB) return (b / YiB).toFixed(f) + " YiB"; | ||
if (b >= ZiB) return (b / ZiB).toFixed(f) + " ZiB"; | ||
if (b >= EiB) return (b / EiB).toFixed(f) + " EiB"; | ||
if (b >= PiB) return (b / PiB).toFixed(f) + " PiB"; | ||
if (b >= TiB) return (b / TiB).toFixed(f) + " TiB"; | ||
if (b >= GiB) return (b / GiB).toFixed(f) + " GiB"; | ||
if (b >= MiB) return (b / MiB).toFixed(f) + " MiB"; | ||
if (b >= kiB) return (b / kiB).toFixed(f) + " KiB"; | ||
return b.toFixed(f) + " B"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,60 @@ | ||
<script lang="ts"> | ||
import { Card } from "flowbite-svelte"; | ||
import { blobs, type Blob } from "../services/blobs"; | ||
import { Table, TableBody, TableBodyCell, TableBodyRow, TableHead, TableHeadCell } from "flowbite-svelte"; | ||
import { blobs } from "../services/blobs"; | ||
import { drives } from "../services/drives"; | ||
import { getDriveName } from "../helpers/drives"; | ||
import type { NDKEvent } from "@nostr-dev-kit/ndk"; | ||
import { formatBytes } from "../helpers/number"; | ||
import dayjs from "dayjs"; | ||
import { getBlobURL } from "../helpers/blob"; | ||
import type { Blob } from "blossom-client"; | ||
let miscBlobs: Blob[] = []; | ||
$: { | ||
miscBlobs = $blobs.map((s) => s.blobs).flat(); | ||
miscBlobs = $blobs | ||
.map((s) => s.blobs) | ||
.flat() | ||
.sort((a, b) => b.created - a.created); | ||
} | ||
function getBlobDrives(blob: Blob): NDKEvent[] { | ||
return Object.values($drives).filter((d) => d.tags.some((t) => t[0] === "x" && t[1] === blob.sha256)); | ||
} | ||
</script> | ||
|
||
<main class="flex flex-wrap gap-4 p-4"> | ||
{#each miscBlobs as blob} | ||
<Card> | ||
<h5 class="mb-2 text-xl font-bold tracking-tight text-gray-900 dark:text-white"> | ||
{blob.mimeType} | ||
<!-- {getFileName(file)} --> | ||
</h5> | ||
<p class="truncate text-xs">{blob.created}</p> | ||
<p class="font-normal leading-tight text-gray-700 dark:text-gray-400"> | ||
{blob.sha256} | ||
</p> | ||
</Card> | ||
{/each} | ||
</main> | ||
<Table hoverable={true}> | ||
<TableHead> | ||
<TableHeadCell>ID</TableHeadCell> | ||
<TableHeadCell>Type</TableHeadCell> | ||
<TableHeadCell>Size</TableHeadCell> | ||
<TableHeadCell>Created</TableHeadCell> | ||
<TableHeadCell>Drives</TableHeadCell> | ||
<TableHeadCell> | ||
<span class="sr-only">Edit</span> | ||
</TableHeadCell> | ||
</TableHead> | ||
<TableBody> | ||
{#each miscBlobs as blob} | ||
<TableBodyRow> | ||
<TableBodyCell> | ||
<a href={getBlobURL(blob)} target="_blank" class="hover:underline">{blob.sha256}</a> | ||
</TableBodyCell> | ||
<TableBodyCell>{blob.type}</TableBodyCell> | ||
<TableBodyCell>{formatBytes(blob.size)}</TableBodyCell> | ||
<TableBodyCell>{dayjs.unix(blob.created).format("ll")}</TableBodyCell> | ||
<TableBodyCell> | ||
{#each getBlobDrives(blob) as drive, i (drive.id)} | ||
{#if i !== 0}<span>, </span>{/if} | ||
<a href="#/drive/{drive.encode()}" class="text-primary-200 hover:underline">{getDriveName(drive)}</a> | ||
{/each} | ||
</TableBodyCell> | ||
<TableBodyCell> | ||
<div class="flex gap-4"> | ||
<a href={getBlobURL(blob)} target="_blank" class="font-medium text-blue-500 hover:underline">Open</a> | ||
<a href="/tables" class="font-medium text-red-600 hover:underline dark:text-red-500">Delete</a> | ||
</div> | ||
</TableBodyCell> | ||
</TableBodyRow> | ||
{/each} | ||
</TableBody> | ||
</Table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters