use nip27 replacer instead of janky regex

This commit is contained in:
Siddharth Singh 2024-08-05 20:24:03 +05:30
parent e4f24c3b26
commit 9175596d5f
No known key found for this signature in database

View file

@ -1,6 +1,6 @@
import { NostrMetadata, NSchema as n } from '@nostrify/nostrify'; import { NostrMetadata, NSchema as n } from '@nostrify/nostrify';
import { getEvent } from '@/queries.ts'; import { getEvent } from '@/queries.ts';
import { nip19 } from 'nostr-tools'; import { nip19, nip27 } from 'nostr-tools';
import { match } from 'path-to-regexp'; import { match } from 'path-to-regexp';
import { lookupAccount, lookupPubkey } from '@/utils/lookup.ts'; import { lookupAccount, lookupPubkey } from '@/utils/lookup.ts';
@ -106,8 +106,10 @@ export async function getStatusInfo(id: string): Promise<StatusInfo> {
const handle = await getHandle(event.pubkey); const handle = await getHandle(event.pubkey);
const res: StatusInfo = { const res: StatusInfo = {
title: `View @${handle}'s post on Ditto`, title: `View @${handle}'s post on Ditto`,
description: event.content description: nip27.replaceAll(
.replace(/nostr:(npub1(?:[0-9]|[a-z]){58})/g, (_, key: string) => `@${key.slice(0, 8)}`), event.content,
({ decoded, value }) => decoded.type === 'npub' ? value.slice(0, 8) : '',
),
}; };
const data: string[][] = event.tags const data: string[][] = event.tags