aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorAkshay <[email protected]>2024-11-22 19:48:31 +0000
committerAkshay <[email protected]>2024-11-22 19:48:31 +0000
commit622c5fee25e7d86914d343ca3f873dc4bd55ffad (patch)
tree6543c2ef3499eecee3842f433599aaae6c4c2f14 /scripts
parent3551ff7a202ad60362888888c42f88b37e32fc59 (diff)
rework invite and admins a bit
Diffstat (limited to 'scripts')
-rw-r--r--scripts/gen-invite.js34
1 files changed, 0 insertions, 34 deletions
diff --git a/scripts/gen-invite.js b/scripts/gen-invite.js
deleted file mode 100644
index 4c0cbee..0000000
--- a/scripts/gen-invite.js
+++ /dev/null
@@ -1,34 +0,0 @@
1import { Database } from "bun:sqlite";
2
3const command = process.argv[2];
4
5const dbPath = process.argv[3] ? process.argv[3] : "readit.db";
6const db = new Database(dbPath, {
7 strict: true,
8});
9
10db.run(`
11 CREATE TABLE IF NOT EXISTS invites (
12 id INTEGER PRIMARY KEY AUTOINCREMENT,
13 token TEXT NOT NULL,
14 createdAt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
15 usedAt TIMESTAMP
16 )
17`);
18
19if (command === "create") {
20 createInvite();
21} else {
22 console.log("requires an arg");
23}
24
25function generateInviteToken() {
26 const hasher = new Bun.CryptoHasher("sha256", "super-secret-invite-key");
27 return hasher.update(Math.random().toString()).digest("hex").slice(0, 10);
28}
29
30function createInvite() {
31 const token = generateInviteToken();
32 db.run("INSERT INTO invites (token) VALUES ($token)", { token });
33 console.log(`Invite token created: ${token}`);
34}