mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
feat: script to populate mime-type
This commit is contained in:
parent
e388925815
commit
f879315d34
2 changed files with 30 additions and 0 deletions
|
|
@ -22,6 +22,7 @@
|
||||||
"trends": "deno run -A --env-file --deny-read=.env scripts/trends.ts",
|
"trends": "deno run -A --env-file --deny-read=.env scripts/trends.ts",
|
||||||
"clean:deps": "deno cache --reload src/app.ts",
|
"clean:deps": "deno cache --reload src/app.ts",
|
||||||
"db:populate-search": "deno run -A --env-file --deny-read=.env scripts/db-populate-search.ts",
|
"db:populate-search": "deno run -A --env-file --deny-read=.env scripts/db-populate-search.ts",
|
||||||
|
"db:populate-mime-type": "deno run -A --env-file --deny-read=.env scripts/db-populate-mime-type.ts",
|
||||||
"vapid": "deno run scripts/vapid.ts"
|
"vapid": "deno run scripts/vapid.ts"
|
||||||
},
|
},
|
||||||
"unstable": [
|
"unstable": [
|
||||||
|
|
|
||||||
29
scripts/db-populate-mime-type.ts
Normal file
29
scripts/db-populate-mime-type.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
import { Storages } from '@/storages.ts';
|
||||||
|
|
||||||
|
const store = await Storages.db();
|
||||||
|
const kysely = await Storages.kysely();
|
||||||
|
|
||||||
|
for await (const msg of store.req([{ kinds: [1] }])) { // Only kind 1 can contain media in Ditto?
|
||||||
|
if (msg[0] === 'EVENT') {
|
||||||
|
const event = msg[2];
|
||||||
|
|
||||||
|
const imeta = event.tags.find(([value]) => value === 'imeta');
|
||||||
|
if (!imeta) continue;
|
||||||
|
|
||||||
|
const mime_type = imeta.find((value) => value?.split(' ')[0] === 'm')?.split(' ')[1];
|
||||||
|
if (!mime_type) continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await kysely.updateTable('nostr_events')
|
||||||
|
.set('mime_type', mime_type)
|
||||||
|
.where('id', '=', event.id)
|
||||||
|
.execute();
|
||||||
|
} catch {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Deno.exit();
|
||||||
Loading…
Add table
Reference in a new issue