chore: upgrade snort libs

This commit is contained in:
Kieran 2024-03-19 10:57:58 +00:00
parent 01610ab846
commit c408e7462e
15 changed files with 3872 additions and 808 deletions

668
.yarn/releases/yarn-4.0.2.cjs → .yarn/releases/yarn-4.1.1.cjs vendored Executable file → Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,2 +1,3 @@
nodeLinker: pnp nodeLinker: pnp
yarnPath: .yarn/releases/yarn-4.0.2.cjs
yarnPath: .yarn/releases/yarn-4.1.1.cjs

View File

@ -12,10 +12,10 @@
}, },
"dependencies": { "dependencies": {
"@noble/hashes": "^1.3.2", "@noble/hashes": "^1.3.2",
"@snort/shared": "^1.0.10", "@snort/shared": "^1.0.14",
"@snort/system": "^1.1.5", "@snort/system": "^1.2.12",
"@snort/system-react": "^1.1.5", "@snort/system-react": "^1.2.12",
"@snort/system-web": "^1.0.3", "@snort/worker-relay": "^1.0.9",
"classnames": "^2.3.2", "classnames": "^2.3.2",
"react": "^18.2.0", "react": "^18.2.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
@ -35,9 +35,10 @@
"prettier": "^3.1.0", "prettier": "^3.1.0",
"tailwindcss": "^3.3.5", "tailwindcss": "^3.3.5",
"typescript": "^5.2.2", "typescript": "^5.2.2",
"vite": "^5.0.0" "vite": "^5.1.6",
"vite-plugin-pwa": "^0.19.4"
}, },
"packageManager": "yarn@4.0.2", "packageManager": "yarn@4.1.1",
"prettier": { "prettier": {
"printWidth": 120 "printWidth": 120
} }

View File

@ -1,72 +1,80 @@
/* latin-ext */ /* latin-ext */
@font-face { @font-face {
font-family: 'Outfit'; font-family: "Outfit";
font-style: normal; font-style: normal;
font-weight: 400; font-weight: 400;
font-display: swap; font-display: swap;
src: url(outfit_400_latin-ext.woff2) format('woff2'); src: url(outfit_400_latin-ext.woff2) format("woff2");
unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113,
U+2C60-2C7F, U+A720-A7FF;
} }
/* latin */ /* latin */
@font-face { @font-face {
font-family: 'Outfit'; font-family: "Outfit";
font-style: normal; font-style: normal;
font-weight: 400; font-weight: 400;
font-display: swap; font-display: swap;
src: url(outfit_400_latin.woff2) format('woff2'); src: url(outfit_400_latin.woff2) format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
} }
/* latin-ext */ /* latin-ext */
@font-face { @font-face {
font-family: 'Outfit'; font-family: "Outfit";
font-style: normal; font-style: normal;
font-weight: 500; font-weight: 500;
font-display: swap; font-display: swap;
src: url(outfit_500_latin-ext.woff2) format('woff2'); src: url(outfit_500_latin-ext.woff2) format("woff2");
unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113,
U+2C60-2C7F, U+A720-A7FF;
} }
/* latin */ /* latin */
@font-face { @font-face {
font-family: 'Outfit'; font-family: "Outfit";
font-style: normal; font-style: normal;
font-weight: 500; font-weight: 500;
font-display: swap; font-display: swap;
src: url(outfit_500_latin.woff2) format('woff2'); src: url(outfit_500_latin.woff2) format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
} }
/* latin-ext */ /* latin-ext */
@font-face { @font-face {
font-family: 'Outfit'; font-family: "Outfit";
font-style: normal; font-style: normal;
font-weight: 600; font-weight: 600;
font-display: swap; font-display: swap;
src: url(outfit_600_latin-ext.woff2) format('woff2'); src: url(outfit_600_latin-ext.woff2) format("woff2");
unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113,
U+2C60-2C7F, U+A720-A7FF;
} }
/* latin */ /* latin */
@font-face { @font-face {
font-family: 'Outfit'; font-family: "Outfit";
font-style: normal; font-style: normal;
font-weight: 600; font-weight: 600;
font-display: swap; font-display: swap;
src: url(outfit_600_latin.woff2) format('woff2'); src: url(outfit_600_latin.woff2) format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
} }
/* latin-ext */ /* latin-ext */
@font-face { @font-face {
font-family: 'Outfit'; font-family: "Outfit";
font-style: normal; font-style: normal;
font-weight: 700; font-weight: 700;
font-display: swap; font-display: swap;
src: url(outfit_700_latin-ext.woff2) format('woff2'); src: url(outfit_700_latin-ext.woff2) format("woff2");
unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113, U+2C60-2C7F, U+A720-A7FF; unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20CF, U+2113,
U+2C60-2C7F, U+A720-A7FF;
} }
/* latin */ /* latin */
@font-face { @font-face {
font-family: 'Outfit'; font-family: "Outfit";
font-style: normal; font-style: normal;
font-weight: 700; font-weight: 700;
font-display: swap; font-display: swap;
src: url(outfit_700_latin.woff2) format('woff2'); src: url(outfit_700_latin.woff2) format("woff2");
unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
} }

View File

@ -21,9 +21,9 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>((props, ref) =>
} }
} }
const colorScheme = const colorScheme = props.disabled
props.disabled ? "bg-neutral-900 text-neutral-600 border border-solid border-neutral-700" : ? "bg-neutral-900 text-neutral-600 border border-solid border-neutral-700"
props.type == "danger" : props.type == "danger"
? "bg-red-900 hover:bg-red-600" ? "bg-red-900 hover:bg-red-600"
: props.type == "primary" : props.type == "primary"
? "bg-indigo-800 hover:bg-indigo-700" ? "bg-indigo-800 hover:bg-indigo-700"

View File

@ -1,5 +1,5 @@
import { useState } from "react"; import { useState } from "react";
import { NostrLink, NoteCollection, RequestBuilder } from "@snort/system"; import { NostrLink, RequestBuilder } from "@snort/system";
import { useRequestBuilder } from "@snort/system-react"; import { useRequestBuilder } from "@snort/system-react";
import { unwrap } from "@snort/shared"; import { unwrap } from "@snort/shared";
@ -12,13 +12,13 @@ import { TorrentCommentKind } from "../const";
export function Comments({ link }: { link: NostrLink }) { export function Comments({ link }: { link: NostrLink }) {
const rb = new RequestBuilder(`replies:${link.encode()}`); const rb = new RequestBuilder(`replies:${link.encode()}`);
rb.withFilter().kinds([TorrentCommentKind]).replyToLink([link]); rb.withFilter().kinds([TorrentCommentKind]).replyToLink([link]);
const comments = useRequestBuilder(NoteCollection, rb); const comments = useRequestBuilder(rb);
return ( return (
<div className="flex flex-col gap-2"> <div className="flex flex-col gap-2">
<WriteComment link={link} /> <WriteComment link={link} />
{comments.data {comments
?.sort((a, b) => (a.created_at > b.created_at ? -1 : 1)) .sort((a, b) => (a.created_at > b.created_at ? -1 : 1))
.map((a, i) => ( .map((a, i) => (
<div key={i} className="flex flex-col gap-2 rounded-lg p-4 bg-neutral-900"> <div key={i} className="flex flex-col gap-2 rounded-lg p-4 bg-neutral-900">
<ProfileImage pubkey={a.pubkey} withName={true}> <ProfileImage pubkey={a.pubkey} withName={true}>
@ -63,7 +63,9 @@ function WriteComment({ link }: { link: NostrLink }) {
></textarea> ></textarea>
</div> </div>
<div> <div>
<Button type="primary" onClick={sendComment}>Send</Button> <Button type="primary" onClick={sendComment}>
Send
</Button>
</div> </div>
</div> </div>
); );

View File

@ -1,4 +1,4 @@
import { NoteCollection, RequestBuilder } from "@snort/system"; import { RequestBuilder } from "@snort/system";
import { TorrentKind } from "../const"; import { TorrentKind } from "../const";
import { useRequestBuilder } from "@snort/system-react"; import { useRequestBuilder } from "@snort/system-react";
import { TorrentList } from "./torrent-list"; import { TorrentList } from "./torrent-list";
@ -8,15 +8,14 @@ export function LatestTorrents({ author }: { author?: string }) {
sub sub
.withFilter() .withFilter()
.kinds([TorrentKind]) .kinds([TorrentKind])
.authors(author ? [author] : undefined) .authors(author ? [author] : undefined);
.limit(100);
const latest = useRequestBuilder(NoteCollection, sub); const latest = useRequestBuilder(sub);
return ( return (
<> <>
<h2>Latest Torrents</h2> <h2>Latest Torrents</h2>
<TorrentList items={latest.data ?? []} /> <TorrentList items={latest} />
</> </>
); );
} }

View File

@ -4,14 +4,14 @@
html, html,
body { body {
font-family: 'Outfit', Arial, Helvetica, sans-serif; font-family: "Outfit", Arial, Helvetica, sans-serif;
-webkit-font-smoothing: antialiased; -webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale; -moz-osx-font-smoothing: grayscale;
font-size: 16px; font-size: 16px;
color: #adadad; color: #adadad;
font-style: normal; font-style: normal;
font-weight: 500; font-weight: 500;
line-height: 24px; line-height: 24px;
background-color: black; background-color: black;
color: white; color: white;
} }
@ -37,4 +37,4 @@ a:not([href="/"], :has(button)) {
.file-list { .file-list {
font-size: 15px; font-size: 15px;
font-weight: 400; font-weight: 400;
} }

View File

@ -2,28 +2,22 @@ import "./index.css";
import React from "react"; import React from "react";
import ReactDOM from "react-dom/client"; import ReactDOM from "react-dom/client";
import { RouteObject, RouterProvider, createBrowserRouter } from "react-router-dom"; import { RouteObject, RouterProvider, createBrowserRouter } from "react-router-dom";
import { SnortContext } from "@snort/system-react";
import { Layout } from "./page/layout"; import { Layout } from "./page/layout";
import { HomePage } from "./page/home"; import { HomePage } from "./page/home";
import { NostrSystem } from "@snort/system";
import { SnortContext } from "@snort/system-react";
import { ProfilePage } from "./page/profile"; import { ProfilePage } from "./page/profile";
import { NewPage } from "./page/new"; import { NewPage } from "./page/new";
import { TorrentPage } from "./page/torrent"; import { TorrentPage } from "./page/torrent";
import { SnortSystemDb } from "@snort/system-web";
import { SearchPage } from "./page/search"; import { SearchPage } from "./page/search";
import { System, initSystem } from "./system";
const db = new SnortSystemDb();
const System = new NostrSystem({
db,
});
const Routes = [ const Routes = [
{ {
element: <Layout />, element: <Layout />,
loader: async () => { loader: async () => {
await System.Init(); await initSystem();
for (const r of ["wss://nos.lol", "wss://relay.damus.io"]) {
await System.ConnectToRelay(r, { read: true, write: true });
}
return null; return null;
}, },
children: [ children: [

View File

@ -23,8 +23,16 @@ export function Layout() {
<img src="/logo_256.jpg" className="rounded-full" height={40} width={40} /> <img src="/logo_256.jpg" className="rounded-full" height={40} width={40} />
<h1 className="font-bold uppercase">dtan.xyz</h1> <h1 className="font-bold uppercase">dtan.xyz</h1>
</Link> </Link>
<div className="w-1/2"><Search /></div> <div className="w-1/2">
{login ? <LoggedInHeader login={login} /> : <Button type="primary" onClick={DoLogin}>Login</Button>} <Search />
</div>
{login ? (
<LoggedInHeader login={login} />
) : (
<Button type="primary" onClick={DoLogin}>
Login
</Button>
)}
</header> </header>
<div> <div>
<Outlet /> <Outlet />

View File

@ -1,7 +1,7 @@
import { NoteCollection, RequestBuilder } from "@snort/system"; import { RequestBuilder } from "@snort/system";
import { useRequestBuilder } from "@snort/system-react";
import { useLocation, useParams } from "react-router-dom"; import { useLocation, useParams } from "react-router-dom";
import { TorrentKind } from "../const"; import { TorrentKind } from "../const";
import { useRequestBuilder } from "@snort/system-react";
import { TorrentList } from "../element/torrent-list"; import { TorrentList } from "../element/torrent-list";
export function SearchPage() { export function SearchPage() {
@ -22,12 +22,12 @@ export function SearchPage() {
f.tag("t", tags); f.tag("t", tags);
} }
const data = useRequestBuilder(NoteCollection, rb); const data = useRequestBuilder(rb);
return ( return (
<div className="flex flex-col gap-4"> <div className="flex flex-col gap-4">
<h2>Search Results</h2> <h2>Search Results</h2>
<TorrentList items={data.data ?? []} /> <TorrentList items={data} />
</div> </div>
); );
} }

View File

@ -1,5 +1,5 @@
import { unwrap } from "@snort/shared"; import { unwrap } from "@snort/shared";
import { NostrLink, NoteCollection, RequestBuilder, TaggedNostrEvent, parseNostrLink } from "@snort/system"; import { NostrLink, RequestBuilder, TaggedNostrEvent, parseNostrLink } from "@snort/system";
import { useRequestBuilder } from "@snort/system-react"; import { useRequestBuilder } from "@snort/system-react";
import { Link, useLocation, useNavigate, useParams } from "react-router-dom"; import { Link, useLocation, useNavigate, useParams } from "react-router-dom";
import { FormatBytes, TorrentKind } from "../const"; import { FormatBytes, TorrentKind } from "../const";
@ -21,9 +21,9 @@ export function TorrentPage() {
.kinds([TorrentKind]) .kinds([TorrentKind])
.link(parseNostrLink(unwrap(id))); .link(parseNostrLink(unwrap(id)));
const evNew = useRequestBuilder(NoteCollection, evState ? null : rb); const evNew = useRequestBuilder(evState ? null : rb);
const ev = evState ?? evNew.data?.at(0); const ev = evState ?? evNew?.at(0);
if (!ev) return; if (!ev) return;
return <TorrentDetail item={ev} />; return <TorrentDetail item={ev} />;
} }
@ -107,12 +107,12 @@ export function TorrentDetail({ item }: { item: TaggedNostrEvent }) {
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{sortedFiles.map((a, i) => ( {sortedFiles.map((a, i) => (
<tr key={i}> <tr key={i}>
<td className="pr-4">{a[1]}</td> <td className="pr-4">{a[1]}</td>
<td className="text-neutral-500 font-semibold text-right text-sm">{FormatBytes(Number(a[2]))}</td> <td className="text-neutral-500 font-semibold text-right text-sm">{FormatBytes(Number(a[2]))}</td>
</tr> </tr>
))} ))}
</tbody> </tbody>
</table> </table>
</div> </div>

24
src/system.ts Normal file
View File

@ -0,0 +1,24 @@
import { NostrSystem } from "@snort/system";
import { WorkerRelayInterface } from "@snort/worker-relay";
import WorkerVite from "@snort/worker-relay/src/worker?worker";
const workerScript = import.meta.env.DEV
? new URL("@snort/worker-relay/dist/esm/worker.mjs", import.meta.url)
: new WorkerVite();
const workerRelay = new WorkerRelayInterface(workerScript);
export const System = new NostrSystem({
cachingRelay: workerRelay,
});
let didInit = false;
export async function initSystem() {
if (didInit) return;
didInit = true;
await workerRelay.init("dtan.db");
await System.Init();
for (const r of ["wss://nos.lol", "wss://relay.damus.io", "wss://relay.nostr.band"]) {
await System.ConnectToRelay(r, { read: true, write: true });
}
}

View File

@ -1,7 +1,25 @@
import { defineConfig } from "vite"; import { defineConfig, searchForWorkspaceRoot } from "vite";
import react from "@vitejs/plugin-react"; import react from "@vitejs/plugin-react";
import { VitePWA } from "vite-plugin-pwa";
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [react()], plugins: [
react(),
VitePWA({
registerType: "autoUpdate",
devOptions: {
enabled: false,
type: "module",
},
}),
],
server: {
fs: {
strict: false,
},
},
worker: {
format: "es",
},
}); });

3807
yarn.lock

File diff suppressed because it is too large Load Diff