From 7860a0e3c27682f3854ba3051159d00a43811725 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 6 Apr 2024 19:36:12 -0500 Subject: [PATCH] Allow setting external URI on statuses --- src/config.ts | 8 ++++++++ src/views/mastodon/statuses.ts | 6 ++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/config.ts b/src/config.ts index 753a2a6..81bb7b6 100644 --- a/src/config.ts +++ b/src/config.ts @@ -48,6 +48,10 @@ class Conf { static get localDomain() { return Deno.env.get('LOCAL_DOMAIN') || 'http://localhost:8000'; } + /** URL to an external Nostr viewer. */ + static get externalDomain() { + return Deno.env.get('NOSTR_EXTERNAL') || Conf.localDomain; + } /** Path to the main SQLite database which stores users, events, and more. */ static get dbPath() { return Deno.env.get('DB_PATH') || 'data/db.sqlite3'; @@ -138,6 +142,10 @@ class Conf { static local(path: string): string { return mergePaths(Conf.localDomain, path); } + /** Get an external URL for the NIP-19 identifier. */ + static external(nip19: string): string { + return new URL(`/${nip19}`, Conf.externalDomain).toString(); + } /** URL to send Sentry errors to. */ static get sentryDsn() { return Deno.env.get('SENTRY_DSN'); diff --git a/src/views/mastodon/statuses.ts b/src/views/mastodon/statuses.ts index 172a2b6..5f8a0e4 100644 --- a/src/views/mastodon/statuses.ts +++ b/src/views/mastodon/statuses.ts @@ -15,6 +15,8 @@ import { DittoAttachment, renderAttachment } from '@/views/mastodon/attachments. import { renderEmojis } from '@/views/mastodon/emojis.ts'; async function renderStatus(event: DittoEvent, viewerPubkey?: string) { + const note = nip19.noteEncode(event.id); + const account = event.author ? await renderAccount({ ...event.author, author_stats: event.author_stats }) : await accountFromPubkey(event.pubkey); @@ -92,8 +94,8 @@ async function renderStatus(event: DittoEvent, viewerPubkey?: string) { tags: [], emojis: renderEmojis(event), poll: null, - uri: Conf.local(`/posts/${event.id}`), - url: Conf.local(`/posts/${event.id}`), + uri: Conf.external(note), + url: Conf.external(note), zapped: Boolean(zapEvent), }; }