diff options
author | Akshay <[email protected]> | 2024-11-22 19:48:31 +0000 |
---|---|---|
committer | Akshay <[email protected]> | 2024-11-22 19:48:31 +0000 |
commit | 622c5fee25e7d86914d343ca3f873dc4bd55ffad (patch) | |
tree | 6543c2ef3499eecee3842f433599aaae6c4c2f14 /scripts | |
parent | 3551ff7a202ad60362888888c42f88b37e32fc59 (diff) |
rework invite and admins a bit
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/gen-invite.js | 34 |
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 @@ | |||
1 | import { Database } from "bun:sqlite"; | ||
2 | |||
3 | const command = process.argv[2]; | ||
4 | |||
5 | const dbPath = process.argv[3] ? process.argv[3] : "readit.db"; | ||
6 | const db = new Database(dbPath, { | ||
7 | strict: true, | ||
8 | }); | ||
9 | |||
10 | db.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 | |||
19 | if (command === "create") { | ||
20 | createInvite(); | ||
21 | } else { | ||
22 | console.log("requires an arg"); | ||
23 | } | ||
24 | |||
25 | function 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 | |||
30 | function createInvite() { | ||
31 | const token = generateInviteToken(); | ||
32 | db.run("INSERT INTO invites (token) VALUES ($token)", { token }); | ||
33 | console.log(`Invite token created: ${token}`); | ||
34 | } | ||