Add admin:role CLI task

This commit is contained in:
Alex Gleason 2024-04-23 18:13:18 -05:00
parent b73b964fda
commit cbf1e8f280
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 39 additions and 1 deletions

View File

@ -9,7 +9,8 @@
"check": "deno check src/server.ts", "check": "deno check src/server.ts",
"relays:sync": "deno run -A scripts/relays.ts sync", "relays:sync": "deno run -A scripts/relays.ts sync",
"nsec": "deno run scripts/nsec.ts", "nsec": "deno run scripts/nsec.ts",
"admin:event": "deno run -A scripts/admin-event.ts" "admin:event": "deno run -A scripts/admin-event.ts",
"admin:role": "deno run -A scripts/admin-role.ts"
}, },
"unstable": ["ffi", "kv"], "unstable": ["ffi", "kv"],
"exclude": ["./public"], "exclude": ["./public"],

37
scripts/admin-role.ts Normal file
View File

@ -0,0 +1,37 @@
import { NSchema } from '@nostrify/nostrify';
import { db } from '@/db.ts';
import { Conf } from '@/config.ts';
import { AdminSigner } from '@/signers/AdminSigner.ts';
import { EventsDB } from '@/storages/events-db.ts';
import { nostrNow } from '@/utils.ts';
const eventsDB = new EventsDB(db);
const [pubkey, role] = Deno.args;
if (!NSchema.id().safeParse(pubkey).success) {
console.error('Invalid pubkey');
Deno.exit(1);
}
if (!['admin', 'user'].includes(role)) {
console.error('Invalid role');
Deno.exit(1);
}
const event = await new AdminSigner().signEvent({
kind: 30361,
tags: [
['d', pubkey],
['role', role],
// NIP-31: https://github.com/nostr-protocol/nips/blob/master/31.md
['alt', `User's account was updated by the admins of ${Conf.url.host}`],
],
content: '',
created_at: nostrNow(),
});
await eventsDB.event(event);
Deno.exit(0);