mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
even better kind 0 handling
This commit is contained in:
parent
2283f64204
commit
166106b12b
2 changed files with 22 additions and 11 deletions
|
|
@ -37,18 +37,26 @@ async function buildTemplateOpts(params: PathParams, url: string): Promise<OpenG
|
|||
if (params.acct && !params.statusId) {
|
||||
const key = /^[a-f0-9]{64}$/.test(params.acct) ? 'pubkey' : 'handle';
|
||||
console.log(key);
|
||||
let handle = '';
|
||||
try {
|
||||
const profile = await fetchProfile({ [key]: params.acct });
|
||||
const handle = await getHandle(params.acct, profile);
|
||||
handle = await getHandle(params.acct, profile);
|
||||
res.description = profile.meta.about || `@${handle}'s Nostr profile`;
|
||||
if (profile.meta.picture) {
|
||||
res.image = { url: profile.meta.picture, h: 150, w: 150 };
|
||||
}
|
||||
} catch (e) {
|
||||
console.debug(e);
|
||||
// @ts-ignore we don't want getHandle trying to do a lookup here
|
||||
// but we do want it to give us a nice pretty npub
|
||||
handle = await getHandle(params.acct, {});
|
||||
res.description = `@${handle}'s Nostr profile`;
|
||||
}
|
||||
|
||||
Object.assign(res, {
|
||||
type: 'profile',
|
||||
title: `View @${handle}'s profile on Ditto`,
|
||||
description: profile.meta.about || `@${handle}'s Nostr profile`,
|
||||
});
|
||||
|
||||
if (profile.meta.picture) {
|
||||
Object.assign(res, { image: { url: profile.meta.picture, h: 150, w: 150 } });
|
||||
}
|
||||
} else if (params.statusId) {
|
||||
const { description, image, title } = await getStatusInfo(params.statusId);
|
||||
Object.assign(res, { description, title });
|
||||
|
|
@ -63,11 +71,14 @@ async function buildTemplateOpts(params: PathParams, url: string): Promise<OpenG
|
|||
return res;
|
||||
}
|
||||
|
||||
const SHOULD_INJECT_RE = new RegExp(Conf.opengraphRouteRegex, 'i');
|
||||
|
||||
export const frontendController: AppMiddleware = async (c, next) => {
|
||||
try {
|
||||
const content = await Deno.readTextFile(new URL('../../public/index.html', import.meta.url));
|
||||
const shouldInject = new RegExp(Conf.opengraphRouteRegex, 'i');
|
||||
if (!shouldInject) {
|
||||
const ua = c.req.header('User-Agent');
|
||||
console.debug('got ua', ua);
|
||||
if (!SHOULD_INJECT_RE.test(ua || '')) {
|
||||
return c.html(content);
|
||||
}
|
||||
if (content.includes(META_PLACEHOLDER)) {
|
||||
|
|
|
|||
|
|
@ -112,8 +112,8 @@ export async function getHandle(id: string, acc?: ProfileInfo) {
|
|||
const fallback = nip19.npubEncode(pubkey).slice(0, 8);
|
||||
try {
|
||||
const author = acc || await fetchProfile({ pubkey });
|
||||
if (author.meta.nip05) return parseNip05(author.meta.nip05).handle;
|
||||
else if (author.meta.name) return author.meta.name;
|
||||
if (author?.meta?.nip05) return parseNip05(author.meta.nip05).handle;
|
||||
else if (author?.meta?.name) return author.meta.name;
|
||||
} catch (e) {
|
||||
console.debug('Error in getHandle: ', e);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue