Skip to content

Commit

Permalink
use "server" tag instead of "r"
Browse files Browse the repository at this point in the history
  • Loading branch information
hzrd149 committed Apr 30, 2024
1 parent 5c5ebde commit 7ad75a1
Show file tree
Hide file tree
Showing 15 changed files with 1,278 additions and 1,245 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
"@codemirror/language": "^6.10.1",
"@noble/ciphers": "^0.5.2",
"@noble/hashes": "^1.4.0",
"@nostr-dev-kit/ndk": "2.7.1",
"@nostr-dev-kit/ndk-cache-dexie": "2.3.1",
"@nostr-dev-kit/ndk-svelte": "2.2.12",
"@nostr-dev-kit/ndk-svelte-components": "2.2.13",
"@nostr-dev-kit/ndk": "^2.8.1",
"@nostr-dev-kit/ndk-cache-dexie": "^2.4.1",
"@nostr-dev-kit/ndk-svelte": "^2.2.14",
"@nostr-dev-kit/ndk-svelte-components": "^2.2.15",
"@scure/base": "^1.1.6",
"@uiw/codemirror-theme-github": "^4.21.25",
"blossom-client-sdk": "^0.4.0",
"blossom-drive-sdk": "^0.1.1",
"blossom-drive-sdk": "^0.2.0",
"codemirror": "^6.0.1",
"dayjs": "^1.11.10",
"events": "^3.3.0",
"file-saver": "^2.0.5",
"flowbite": "^2.3.0",
"flowbite-svelte": "^0.45.0",
"flowbite-svelte": "^0.46.1",
"flowbite-svelte-icons": "^1.5.0",
"highlight.js": "^11.9.0",
"idb": "^8.0.0",
Expand Down Expand Up @@ -60,8 +60,8 @@
"svelte": "^4.2.14",
"svelte-check": "^3.6.9",
"tslib": "^2.6.2",
"typescript": "^5.4.5",
"typescript": "^5.2.2",
"vite": "^5.2.9",
"vite-plugin-pwa": "^0.19.8"
"vite-plugin-pwa": "^0.20.0"
}
}
6 changes: 3 additions & 3 deletions src/components/LoginPage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@

<Button size="xl" on:click={extension}>Login with extension</Button>
<p class="text-lg">Or</p>
<form on:submit={login} class="flex flex-col w-full lg:w-full items-center">
<Label for="address" class="mb-2">Nostr Address / Bunker URI</Label>
<div class="flex gap-2 w-full lg:max-w-96">
<form on:submit={login} class="flex w-full flex-col items-center lg:w-full">
<Label for="address" class="mb-2">Nostr Address / Bunker URI / nsec</Label>
<div class="flex w-full gap-2 lg:max-w-96">
<Input type="text" id="address" required bind:value={address} />
<Button type="submit">Login</Button>
</div>
Expand Down
43 changes: 19 additions & 24 deletions src/components/Sidebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
SidebarDropdownWrapper,
Button,
Search,
DropdownItem,
Dropdown,
} from "flowbite-svelte";
import {
HomeSolid,
Expand All @@ -18,15 +16,15 @@
TagSolid,
DatabaseOutline,
InfoCircleOutline,
FileSolid
FileSolid,
} from "flowbite-svelte-icons";
import { type Drive } from "blossom-drive-sdk";
import {onMount} from "svelte";
import { EncryptedDrive, type Drive } from "blossom-drive-sdk";
import { onMount } from "svelte";
import { drives } from "../services/drives";
import { servers } from "../services/servers";
import NewDriveModal from "./NewDriveModal.svelte";
import { activeUser } from "../services/ndk";
import {doHideSidebar, doToggleSidebar} from "../helpers/sidebar";
import { doHideSidebar, doToggleSidebar } from "../helpers/sidebar";
import { searchForFiles, type FileResult } from "../services/search";
let newDriveModal = false;
Expand All @@ -41,7 +39,7 @@
function reset() {
results = [];
search = "";
};
}
onMount(() => doToggleSidebar());
onMount(() => doHideSidebar());
Expand All @@ -51,21 +49,24 @@
};
</script>

<Sidebar id="sidebar" class="flex -translate-x-56 lg:translate-x-0 fixed z-10 top-0 pt-14 left-0 flex-col flex-shrink-0 w-56 h-full duration-75 transition-transform">
<Sidebar
id="sidebar"
class="fixed left-0 top-0 z-10 flex h-full w-56 flex-shrink-0 -translate-x-56 flex-col pt-14 transition-transform duration-75 lg:translate-x-0"
>
<SidebarWrapper class="h-full rounded-none">
{#if $activeUser}
<div class="flex lg:hidden max-w-lg flex-1 flex-col mb-5">
<div class="mb-5 flex max-w-lg flex-1 flex-col lg:hidden">
<Search type="search" size="sm" placeholder="Search Drives" bind:value={search} />
{#if results.length > 0}
<div class="relative w-full">
<div
class="absolute left-0 right-0 top-1 z-50 flex flex-col gap-2 rounded-lg border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-900"
class="absolute left-0 right-0 top-1 z-50 flex flex-col gap-2 rounded-lg border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-900"
>
{#each results as result}
<a
class="flex items-center gap-2 px-2 py-1 hover:bg-gray-200 dark:hover:bg-gray-800"
href="#/drive/{result.drive.address}?path={encodeURIComponent(result.path)}"
on:click={reset}
class="flex items-center gap-2 px-2 py-1 hover:bg-gray-200 dark:hover:bg-gray-800"
href="#/drive/{result.drive.address}?path={encodeURIComponent(result.path)}"
on:click={reset}
>
<FileSolid class="h-4 w-4" />
<span>{result.filename}</span>
Expand All @@ -77,17 +78,9 @@
{/if}
</div>
{/if}
<Button size="lg" class="mb-2 w-full" disabled={$activeUser === undefined}>
<PlusOutline class="me-2 h-6 w-6" />New
<Button size="lg" class="mb-2 w-full" disabled={$activeUser === undefined} on:click={() => (newDriveModal = true)}>
<PlusOutline class="me-2 h-6 w-6" />New Drive
</Button>
<Dropdown class="w-60">
<DropdownItem on:click={() => (newDriveModal = true)}>
<ArchiveSolid class="inline-block h-6 w-6" /> Drive
</DropdownItem>
<!-- <DropdownDivider />
<DropdownItem><FileImportOutline class="inline-block h-6 w-6" /> Upload Files</DropdownItem>
<DropdownItem><FolderArrowRightOutline class="inline-block h-6 w-6" /> Upload Folder</DropdownItem> -->
</Dropdown>

{#if $activeUser}
<SidebarGroup>
Expand All @@ -97,7 +90,9 @@
<SidebarDropdownWrapper label="Drives">
<ArchiveSolid slot="icon" class="h-5 w-5" />
{#each Object.values($drives) as drive}
<SidebarDropdownItem label={drive.name} href="#/drive/{drive.address}" />
{#if !(drive instanceof EncryptedDrive) || !drive.locked}
<SidebarDropdownItem label={drive.name} href="#/drive/{drive.address}" />
{/if}
{/each}
</SidebarDropdownWrapper>
<!-- <SidebarItem label="Hosting" href="#/hosting">
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Blobs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import { Select, Table, TableBody, TableBodyCell, TableBodyRow, TableHead, TableHeadCell } from "flowbite-svelte";
import dayjs from "dayjs";
import { type Drive } from "blossom-drive-sdk";
import { BlossomClient, type BlobDescriptor } from "blossom-client-sdk";
import { blobs, refreshBlobs } from "../services/blobs";
import { drives } from "../services/drives";
import { formatBytes } from "../helpers/number";
import { getBlobURL } from "../helpers/blob";
import { BlossomClient, type BlobDescriptor } from "blossom-client-sdk";
import { activeUser, signEventTemplate } from "../services/ndk";
import { servers } from "../services/servers";
import LoginPage from "../components/LoginPage.svelte";
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Drive/Drive.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import { nip19 } from "nostr-tools";
import { Spinner } from "flowbite-svelte";
import { EncryptedDrive, type Drive } from "blossom-drive-sdk";
import type { Readable } from "svelte/store";
import { drives, getReadableDrive, handleEvent } from "../../services/drives";
import DrivePage from "./DrivePage.svelte";
import { ndk } from "../../services/ndk";
import UnlockDrive from "../../components/UnlockDrive.svelte";
import type { Readable } from "svelte/store";
export let params: Record<string, string>;
let drive: Readable<Drive>;
Expand Down
1 change: 1 addition & 0 deletions src/pages/Drive/Readme.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import { Alert } from "flowbite-svelte";
import { Upload, type TreeFile, type Drive } from "blossom-drive-sdk";
import { readFileAsText } from "../../services/file-reader";
import { servers } from "../../services/servers";
import MarkdownEditor from "./markdown/MarkdownEditor.svelte";
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Files.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<script lang="ts">
import { onDestroy } from "svelte";
import { Card } from "flowbite-svelte";
import { NDKKind } from "@nostr-dev-kit/ndk";
import { activeUser, ndk } from "../services/ndk";
import { onDestroy } from "svelte";
import { getFileHash, getFileName, getFileSummary } from "../helpers/files";
const files = ndk.storeSubscribe({ kinds: [NDKKind.Media], authors: [$activeUser.pubkey] });
Expand Down
2 changes: 1 addition & 1 deletion src/pages/History.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<script lang="ts">
import { get } from "svelte/store";
import type { NostrEvent } from "@nostr-dev-kit/ndk";
import { nip19 } from "nostr-tools";
import { Spinner, Timeline } from "flowbite-svelte";
import { type Drive } from "blossom-drive-sdk";
import { getDriveVersions } from "../services/db";
import { drives } from "../services/drives";
import { get } from "svelte/store";
import DriveHistoryEntry from "../components/DriveHistoryEntry.svelte";
export let params: Record<string, string | undefined> = {};
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Home.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script lang="ts">
import { Alert, Button } from "flowbite-svelte";
import { TagOutline } from "flowbite-svelte-icons";
import DriveCard from "../components/DriveCard.svelte";
import SimpleCard from "../components/SimpleCard.svelte";
import { drives } from "../services/drives";
import { TagOutline } from "flowbite-svelte-icons";
import { activeUser } from "../services/ndk";
import LoginPage from "../components/LoginPage.svelte";
import { servers } from "../services/servers";
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Hosting.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import { Button } from "flowbite-svelte";
import { onDestroy } from "svelte";
import { Button } from "flowbite-svelte";
import HostDriveModal from "../components/HostDriveModal.svelte";
import { activeUser, ndk } from "../services/ndk";
import HostRequestCard from "../components/HostRequestCard.svelte";
Expand Down
10 changes: 5 additions & 5 deletions src/pages/Servers.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
async function handleSubmit(e: SubmitEvent) {
e.preventDefault();
confirmModal = true;
if (!server.startsWith("http")) server = "https://" + server;
}
let loading = false;
Expand All @@ -32,10 +34,8 @@
try {
loading = true;
if (!server.startsWith("http")) server = "https://" + server;
const draft = cloneEvent($serverEvent, 10063);
draft.tags.push(["r", new URL(server).toString()]);
draft.tags.push(["server", new URL(server).toString()]);
await draft.sign();
await draft.publish();
loading = false;
Expand All @@ -50,7 +50,7 @@
try {
loading = true;
const draft = cloneEvent($serverEvent, 10063);
draft.tags = draft.tags.filter((t) => t[0] === "r" && t[1] !== server);
draft.tags = draft.tags.filter((t) => (t[0] === "r" || t[0] === "server") && t[1] !== server);
await draft.sign();
await draft.publish();
loading = false;
Expand Down Expand Up @@ -110,7 +110,7 @@
{/if}

<form class="flex gap-2" on:submit={handleSubmit}>
<Input placeholder="https://cdn.example.com" bind:value={server} required type="url" />
<Input placeholder="https://cdn.example.com" bind:value={server} required />
<Button class="shrink-0" disabled={loading} type="submit">Add Server</Button>
</form>

Expand Down
4 changes: 2 additions & 2 deletions src/services/ndk.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { writable } from "svelte/store";
import NDKSvelte from "@nostr-dev-kit/ndk-svelte";
import { NDKEvent, NDKNip07Signer, NDKNip46Signer, NDKPrivateKeySigner } from "@nostr-dev-kit/ndk";
import NDKCacheAdapterDexie from "@nostr-dev-kit/ndk-cache-dexie";
import { writable } from "svelte/store";
import type { EventTemplate, SignedEvent } from "blossom-client-sdk";
import { NDKEvent, NDKNip07Signer, NDKNip46Signer, NDKPrivateKeySigner } from "@nostr-dev-kit/ndk";
import { generateSecretKey, nip19 } from "nostr-tools";
import { decrypt } from "nostr-tools/nip49";
import { bytesToHex } from "@noble/hashes/utils";
Expand Down
3 changes: 2 additions & 1 deletion src/services/search.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { get } from "svelte/store";
import { drives } from "./drives";
import { walkTree, type Drive, formatPath } from "blossom-drive-sdk";

import { drives } from "./drives";

export type FileResult = { drive: Drive; filename: string; path: string };

export function searchForFiles(search: string): FileResult[] {
Expand Down
11 changes: 6 additions & 5 deletions src/services/servers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { get, writable } from "svelte/store";
import { activeUser, ndk } from "./ndk";
import type { NDKEvent, NDKSubscription } from "@nostr-dev-kit/ndk";

import { activeUser, ndk } from "./ndk";

export const serverEvent = writable<NDKEvent | null>(null);
export const servers = writable<string[]>([]);

let sub: NDKSubscription;
activeUser.subscribe((user) => {
if (sub) sub.stop();
Expand All @@ -16,7 +20,7 @@ activeUser.subscribe((user) => {
serverEvent.set(event);
const urls: string[] = [];
for (const tag of event.tags) {
if (tag[0] === "r" && tag[1]) {
if ((tag[0] === "r" || tag[0] === "server") && tag[1]) {
try {
urls.push(new URL(tag[1]).toString());
} catch (e) {}
Expand All @@ -27,6 +31,3 @@ activeUser.subscribe((user) => {
});
sub.start();
});

export const serverEvent = writable<NDKEvent | null>(null);
export const servers = writable<string[]>([]);
Loading

0 comments on commit 7ad75a1

Please sign in to comment.