Allow setting external URI on statuses

This commit is contained in:
Alex Gleason 2024-04-06 19:36:12 -05:00
parent 9841c1767d
commit 7860a0e3c2
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 12 additions and 2 deletions

View File

@ -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');

View File

@ -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),
};
}