mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
Match every possible goddamn URL format in search
This commit is contained in:
parent
dbd40357af
commit
ff900341d5
3 changed files with 29 additions and 2 deletions
|
|
@ -65,6 +65,7 @@
|
|||
"nostr-relaypool": "npm:nostr-relaypool2@0.6.34",
|
||||
"nostr-tools": "npm:nostr-tools@2.5.1",
|
||||
"nostr-wasm": "npm:nostr-wasm@^0.1.0",
|
||||
"path-to-regexp": "npm:path-to-regexp@^7.1.0",
|
||||
"postgres": "https://raw.githubusercontent.com/xyzshantaram/postgres.js/8a9bbce88b3f6425ecaacd99a80372338b157a53/deno/mod.js",
|
||||
"prom-client": "npm:prom-client@^15.1.2",
|
||||
"question-deno": "https://raw.githubusercontent.com/ocpu/question-deno/10022b8e52555335aa510adb08b0a300df3cf904/mod.ts",
|
||||
|
|
|
|||
6
deno.lock
generated
6
deno.lock
generated
|
|
@ -73,6 +73,7 @@
|
|||
"npm:nostr-tools@^2.5.0": "npm:nostr-tools@2.5.1",
|
||||
"npm:nostr-tools@^2.7.0": "npm:nostr-tools@2.7.0",
|
||||
"npm:nostr-wasm@^0.1.0": "npm:nostr-wasm@0.1.0",
|
||||
"npm:path-to-regexp@^7.1.0": "npm:path-to-regexp@7.1.0",
|
||||
"npm:postgres@3.4.4": "npm:postgres@3.4.4",
|
||||
"npm:prom-client@^15.1.2": "npm:prom-client@15.1.2",
|
||||
"npm:tldts@^6.0.14": "npm:tldts@6.1.18",
|
||||
|
|
@ -947,6 +948,10 @@
|
|||
"integrity": "sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==",
|
||||
"dependencies": {}
|
||||
},
|
||||
"path-to-regexp@7.1.0": {
|
||||
"integrity": "sha512-ZToe+MbUF4lBqk6dV8GKot4DKfzrxXsplOddH8zN3YK+qw9/McvP7+4ICjZvOne0jQhN4eJwHsX6tT0Ns19fvw==",
|
||||
"dependencies": {}
|
||||
},
|
||||
"picomatch@2.3.1": {
|
||||
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
|
||||
"dependencies": {}
|
||||
|
|
@ -1856,6 +1861,7 @@
|
|||
"npm:nostr-relaypool2@0.6.34",
|
||||
"npm:nostr-tools@2.5.1",
|
||||
"npm:nostr-wasm@^0.1.0",
|
||||
"npm:path-to-regexp@^7.1.0",
|
||||
"npm:prom-client@^15.1.2",
|
||||
"npm:tldts@^6.0.14",
|
||||
"npm:tseep@^1.2.1",
|
||||
|
|
|
|||
24
src/utils.ts
24
src/utils.ts
|
|
@ -1,5 +1,6 @@
|
|||
import { NostrEvent, NSchema as n } from '@nostrify/nostrify';
|
||||
import { nip19 } from 'nostr-tools';
|
||||
import { match } from 'path-to-regexp';
|
||||
import { z } from 'zod';
|
||||
|
||||
/** Get the current time in Nostr format. */
|
||||
|
|
@ -37,9 +38,28 @@ function extractBech32(value: string): string | undefined {
|
|||
break;
|
||||
// Extract from URL, eg `https://njump.me/npub1q3sle0kvfsehgsuexttt3ugjd8xdklxfwwkh559wxckmzddywnws6cd26p`.
|
||||
case 'http:':
|
||||
case 'https:':
|
||||
bech32 = uri.pathname.replace(/^\/@?/, '');
|
||||
case 'https:': {
|
||||
const accountUriMatch = match<{ acct: string }>('/users/:acct')(uri.pathname);
|
||||
const accountUrlMatch = match<{ acct: string }>('/@:acct')(uri.pathname);
|
||||
const statusUriMatch = match<{ acct: string; id: string }>('/users/:acct/statuses/:id')(uri.pathname);
|
||||
const statusUrlMatch = match<{ acct: string; id: string }>('/@:acct/:id')(uri.pathname);
|
||||
const soapboxMatch = match<{ acct: string; id: string }>('/@:acct/posts/:id')(uri.pathname);
|
||||
const nostrMatch = match<{ bech32: string }>('/:bech32')(uri.pathname);
|
||||
if (accountUriMatch) {
|
||||
bech32 = accountUriMatch.params.acct;
|
||||
} else if (accountUrlMatch) {
|
||||
bech32 = accountUrlMatch.params.acct;
|
||||
} else if (statusUriMatch) {
|
||||
bech32 = nip19.noteEncode(statusUriMatch.params.id);
|
||||
} else if (statusUrlMatch) {
|
||||
bech32 = nip19.noteEncode(statusUrlMatch.params.id);
|
||||
} else if (soapboxMatch) {
|
||||
bech32 = nip19.noteEncode(soapboxMatch.params.id);
|
||||
} else if (nostrMatch) {
|
||||
bech32 = nostrMatch.params.bech32;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// do nothing
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue