Skip to content

Commit

Permalink
update blossom-client
Browse files Browse the repository at this point in the history
  • Loading branch information
hzrd149 committed Feb 26, 2024
1 parent 607155d commit 683bcb1
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"@nostr-dev-kit/ndk-cache-dexie": "2.2.4",
"@nostr-dev-kit/ndk-svelte": "2.2.4",
"@nostr-dev-kit/ndk-svelte-components": "2.2.4",
"blossom-client": "^0.1.1",
"blossom-client": "^0.2.0",
"dayjs": "^1.11.10",
"flowbite": "^2.3.0",
"flowbite-svelte": "^0.44.23",
Expand Down
4 changes: 2 additions & 2 deletions src/components/UploadFileModal.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { Alert, Button, Input, Label, Modal, Select, Spinner } from "flowbite-svelte";
import { BlossomClient, type Blob } from "blossom-client";
import { BlossomClient, type BlobDescriptor } from "blossom-client";
import { handleEvent, drives } from "../services/drives";
import { NDKEvent } from "@nostr-dev-kit/ndk";
import { getFileTree, parsePath, setFile, setDriveFileTree } from "../helpers/tree";
Expand Down Expand Up @@ -37,7 +37,7 @@
loading = "Signing Auth";
const auth = await BlossomClient.getUploadAuth(file, signEventTemplate);
let blob: Blob | null = null;
let blob: BlobDescriptor | null = null;
for (const server of $servers) {
loading = `Uploading to ${server}`;
try {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Drive.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import SpeedDialMenu from "../components/SpeedDialMenu.svelte";
import { nip19 } from "nostr-tools";
import { Button, Spinner } from "flowbite-svelte";
import { BlossomClient, type Blob } from "blossom-client";
import { BlossomClient, type BlobDescriptor } from "blossom-client";
import {
cloneTree,
Expand Down Expand Up @@ -134,7 +134,7 @@
async function uploadFile(file: File) {
const auth = await BlossomClient.getUploadAuth(file, signEventTemplate);
let descriptor: Blob | undefined = undefined;
let descriptor: BlobDescriptor | undefined = undefined;
for (const server of $servers) {
try {
descriptor = await BlossomClient.uploadBlob(server, file, auth);
Expand Down
28 changes: 24 additions & 4 deletions src/pages/Misc.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<script lang="ts">
import { Select, Table, TableBody, TableBodyCell, TableBodyRow, TableHead, TableHeadCell } from "flowbite-svelte";
import { blobs } from "../services/blobs";
import { blobs, refreshBlobs } 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";
import { BlossomClient, type BlobDescriptor } from "blossom-client";
import { signEventTemplate } from "../services/ndk";
import { servers } from "../services/servers";
let selectedDrive = "";
let selectedType = "";
Expand All @@ -31,9 +33,20 @@
})
.sort((a, b) => b.created - a.created);
function getBlobDrives(blob: Blob): NDKEvent[] {
function getBlobDrives(blob: BlobDescriptor): NDKEvent[] {
return Object.values($drives).filter((d) => d.tags.some((t) => t[0] === "x" && t[1] === blob.sha256));
}
async function deleteBlob(blob: BlobDescriptor) {
try {
const auth = await BlossomClient.getDeleteAuth(blob.sha256, signEventTemplate);
for (const server of $servers) await BlossomClient.deleteBlob(server, blob.sha256, auth);
} catch (e) {
console.log(e);
if (e instanceof Error) alert(e.message);
}
refreshBlobs();
}
</script>

<div class="m-2 flex gap-2">
Expand Down Expand Up @@ -79,7 +92,14 @@
<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>
<a
href="/#"
on:click={(e) => {
e.preventDefault();
deleteBlob(blob);
}}
class="font-medium text-red-600 hover:underline dark:text-red-500">Delete</a
>
</div>
</TableBodyCell>
</TableBodyRow>
Expand Down
6 changes: 3 additions & 3 deletions src/services/blobs.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { get, writable } from "svelte/store";
import { activeUser } from "./ndk";
import { servers } from "./servers";
import type { Blob } from "blossom-client";
import { BlossomClient, type BlobDescriptor } from "blossom-client";

type ServerList = {
server: string;
blobs: Blob[];
blobs: BlobDescriptor[];
};

export const blobs = writable<ServerList[]>([]);
Expand All @@ -22,7 +22,7 @@ export async function refreshBlobs(urls: string[] = get(servers)) {

for (const server of urls) {
try {
const res = await fetch(new URL("/list?pubkey=" + user.pubkey, server)).then((res) => res.json());
const res = await BlossomClient.listBlobs(server, user.pubkey);
serverLists.push({ server, blobs: res });
} catch (e) {}
}
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1670,10 +1670,10 @@ binary-extensions@^2.0.0:
resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d"
integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==

blossom-client@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/blossom-client/-/blossom-client-0.1.1.tgz#823bc96b2fd810b2f54f2b1c9289b9bbc2d64804"
integrity sha512-VJbj2RigogDYHUAi1mM77knJoILdzkKljrapMB/mrUxvS9bblapxfiMLorBf2K2/tP2CxrZn6ry5lEONaMd3FQ==
blossom-client@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/blossom-client/-/blossom-client-0.2.0.tgz#fd5be18751c9649ce1d84b117d60582d9d043c57"
integrity sha512-Sq3gzCEZM4/JyWX73LtflzXws3gaZBlsXVniDWshhtnG7mSfroC1b+d3jHjjlnQUzivVdQ7yb0Q7FCCu+Ajl8A==
dependencies:
cross-fetch "^4.0.0"

Expand Down

0 comments on commit 683bcb1

Please sign in to comment.