Rename Conf.url() to Conf.local(), replace it with a URL of localDomain

This commit is contained in:
Alex Gleason 2023-07-09 18:26:33 -05:00
parent 5ec40f285d
commit be6aa89c39
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
7 changed files with 16 additions and 15 deletions

View File

@ -21,8 +21,11 @@ const Conf = {
get publishRelays() {
return ['wss://relay.mostr.pub'];
},
get url() {
return new URL(Conf.localDomain);
},
/** Merges the path with the localDomain. */
url(path: string): string {
local(path: string): string {
if (path.startsWith('/')) {
// Path is a path.
return new URL(path, Conf.localDomain).toString();

View File

@ -3,7 +3,7 @@ import { Conf } from '@/config.ts';
import type { Context } from '@/deps.ts';
function instanceController(c: Context) {
const { host, protocol } = new URL(Conf.localDomain);
const { host, protocol } = Conf.url;
return c.json({
uri: host,

View File

@ -31,7 +31,7 @@ const acctSchema = z.custom<URL>((value) => value instanceof URL)
.transform((uri) => uri.pathname)
.pipe(z.string().email('Invalid acct'))
.transform((acct) => acct.split('@') as [username: string, host: string])
.refine(([_username, host]) => host === new URL(Conf.localDomain).hostname, {
.refine(([_username, host]) => host === Conf.url.hostname, {
message: 'Host must be local',
path: ['resource', 'acct'],
});
@ -66,7 +66,7 @@ interface RenderWebfingerOpts {
/** Present Nostr user on Webfinger. */
function renderWebfinger({ pubkey, username, subject }: RenderWebfingerOpts): Webfinger {
const apId = Conf.url(`/users/${username}`);
const apId = Conf.local(`/users/${username}`);
return {
subject,
@ -92,7 +92,7 @@ function renderWebfinger({ pubkey, username, subject }: RenderWebfingerOpts): We
}
const hostMetaController: AppController = (c) => {
const template = Conf.url('/.well-known/webfinger?resource={uri}');
const template = Conf.local('/.well-known/webfinger?resource={uri}');
c.header('content-type', 'application/xrd+xml');
return c.body(

View File

@ -28,7 +28,7 @@ function auth98(opts: Auth98Opts = {}): AppMiddleware {
.refine((event) => {
const url = findTag(event.tags, 'u')?.[1];
try {
return url === Conf.url(c.req.url);
return url === Conf.local(c.req.url);
} catch (_e) {
return false;
}

View File

@ -8,7 +8,7 @@ const linkifyOpts: linkify.Opts = {
render: {
hashtag: ({ content }) => {
const tag = content.replace(/^#/, '');
const href = Conf.url(`/tags/${tag}`);
const href = Conf.local(`/tags/${tag}`);
return `<a class=\"mention hashtag\" href=\"${href}\" rel=\"tag\"><span>#</span>${tag}</a>`;
},
url: ({ content }) => {
@ -17,7 +17,7 @@ const linkifyOpts: linkify.Opts = {
const pubkey = getDecodedPubkey(decoded);
if (pubkey) {
const name = pubkey.substring(0, 8);
const href = Conf.url(`/users/${pubkey}`);
const href = Conf.local(`/users/${pubkey}`);
return `<span class="h-card"><a class="u-url mention" href="${href}" rel="ugc">@<span>${name}</span></a></span>`;
} else {
return '';

View File

@ -1,4 +1,4 @@
import { nip19, verifySignature, z } from '@/deps.ts';
import { verifySignature, z } from '@/deps.ts';
import type { Event } from './event.ts';

View File

@ -21,7 +21,6 @@ async function toAccount(event: Event<0>, opts: ToAccountOpts = {}) {
const { pubkey } = event;
const { name, nip05, picture, banner, about }: MetaContent = parseMetaContent(event);
const { origin } = new URL(Conf.localDomain);
const npub = nip19.npubEncode(pubkey);
let parsed05: Nip05 | undefined;
@ -65,7 +64,7 @@ async function toAccount(event: Event<0>, opts: ToAccountOpts = {}) {
}
: undefined,
statuses_count: 0,
url: `${origin}/users/${pubkey}`,
url: Conf.local(`/users/${pubkey}`),
username: parsed05?.nickname || npub.substring(0, 8),
};
}
@ -82,13 +81,12 @@ async function toMention(pubkey: string) {
url: account.url,
};
} else {
const { origin } = new URL(Conf.localDomain);
const npub = nip19.npubEncode(pubkey);
return {
id: pubkey,
acct: npub,
username: npub.substring(0, 8),
url: `${origin}/users/${pubkey}`,
url: Conf.local(`/users/${pubkey}`),
};
}
}
@ -147,8 +145,8 @@ async function toStatus(event: Event<1>) {
tags: [],
emojis: toEmojis(event),
poll: null,
uri: `${Conf.localDomain}/posts/${event.id}`,
url: `${Conf.localDomain}/posts/${event.id}`,
uri: Conf.local(`/posts/${event.id}`),
url: Conf.local(`/posts/${event.id}`),
};
}