Add Conf.url() function for producing local absolute URLs
This commit is contained in:
parent
a3323a2618
commit
215ff85b6d
|
@ -21,6 +21,17 @@ const Conf = {
|
|||
get publishRelays() {
|
||||
return ['wss://relay.mostr.pub'];
|
||||
},
|
||||
/** Merges the path with the localDomain. */
|
||||
url(path: string): string {
|
||||
if (path.startsWith('/')) {
|
||||
// Path is a path.
|
||||
return new URL(path, Conf.localDomain).toString();
|
||||
} else {
|
||||
// Path is possibly a full URL. Replace the domain.
|
||||
const { pathname } = new URL(path);
|
||||
return new URL(pathname, Conf.localDomain).toString();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export { Conf };
|
||||
|
|
|
@ -28,7 +28,7 @@ function auth98(opts: Auth98Opts = {}): AppMiddleware {
|
|||
.refine((event) => {
|
||||
const url = findTag(event.tags, 'u')?.[1];
|
||||
try {
|
||||
return url === localUrl(c.req.url);
|
||||
return url === Conf.url(c.req.url);
|
||||
} catch (_e) {
|
||||
return false;
|
||||
}
|
||||
|
@ -51,11 +51,6 @@ function auth98(opts: Auth98Opts = {}): AppMiddleware {
|
|||
};
|
||||
}
|
||||
|
||||
function localUrl(url: string): string {
|
||||
const { pathname } = new URL(url);
|
||||
return new URL(pathname, Conf.localDomain).toString();
|
||||
}
|
||||
|
||||
const requireProof: AppMiddleware = async (c, next) => {
|
||||
const pubkey = c.get('pubkey');
|
||||
const proof = c.get('proof');
|
||||
|
|
|
@ -4,13 +4,11 @@ import { linkify, linkifyStr, mime, nip19, nip21 } from '@/deps.ts';
|
|||
linkify.registerCustomProtocol('nostr', true);
|
||||
linkify.registerCustomProtocol('wss');
|
||||
|
||||
const url = (path: string) => new URL(path, Conf.localDomain).toString();
|
||||
|
||||
const linkifyOpts: linkify.Opts = {
|
||||
render: {
|
||||
hashtag: ({ content }) => {
|
||||
const tag = content.replace(/^#/, '');
|
||||
const href = url(`/tags/${tag}`);
|
||||
const href = Conf.url(`/tags/${tag}`);
|
||||
return `<a class=\"mention hashtag\" href=\"${href}\" rel=\"tag\"><span>#</span>${tag}</a>`;
|
||||
},
|
||||
url: ({ content }) => {
|
||||
|
@ -19,7 +17,7 @@ const linkifyOpts: linkify.Opts = {
|
|||
const pubkey = getDecodedPubkey(decoded);
|
||||
if (pubkey) {
|
||||
const name = pubkey.substring(0, 8);
|
||||
const href = url(`/users/${pubkey}`);
|
||||
const href = Conf.url(`/users/${pubkey}`);
|
||||
return `<span class="h-card"><a class="u-url mention" href="${href}" rel="ugc">@<span>${name}</span></a></span>`;
|
||||
} else {
|
||||
return '';
|
||||
|
|
Loading…
Reference in New Issue