Merge branch 'external-uri' into 'main'

Allow setting external URI on statuses

See merge request soapbox-pub/ditto!138
This commit is contained in:
Alex Gleason 2024-04-07 00:38:15 +00:00
commit d408b2000d
2 changed files with 12 additions and 2 deletions

View File

@ -48,6 +48,10 @@ class Conf {
static get localDomain() { static get localDomain() {
return Deno.env.get('LOCAL_DOMAIN') || 'http://localhost:8000'; 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. */ /** Path to the main SQLite database which stores users, events, and more. */
static get dbPath() { static get dbPath() {
return Deno.env.get('DB_PATH') || 'data/db.sqlite3'; return Deno.env.get('DB_PATH') || 'data/db.sqlite3';
@ -138,6 +142,10 @@ class Conf {
static local(path: string): string { static local(path: string): string {
return mergePaths(Conf.localDomain, path); 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. */ /** URL to send Sentry errors to. */
static get sentryDsn() { static get sentryDsn() {
return Deno.env.get('SENTRY_DSN'); 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'; import { renderEmojis } from '@/views/mastodon/emojis.ts';
async function renderStatus(event: DittoEvent, viewerPubkey?: string) { async function renderStatus(event: DittoEvent, viewerPubkey?: string) {
const note = nip19.noteEncode(event.id);
const account = event.author const account = event.author
? await renderAccount({ ...event.author, author_stats: event.author_stats }) ? await renderAccount({ ...event.author, author_stats: event.author_stats })
: await accountFromPubkey(event.pubkey); : await accountFromPubkey(event.pubkey);
@ -92,8 +94,8 @@ async function renderStatus(event: DittoEvent, viewerPubkey?: string) {
tags: [], tags: [],
emojis: renderEmojis(event), emojis: renderEmojis(event),
poll: null, poll: null,
uri: Conf.local(`/posts/${event.id}`), uri: Conf.external(note),
url: Conf.local(`/posts/${event.id}`), url: Conf.external(note),
zapped: Boolean(zapEvent), zapped: Boolean(zapEvent),
}; };
} }