mirror of
https://github.com/ReCloudStudio/WebHooker.git
synced 2026-09-23 00:21:28 +00:00
feat: migrate send logs and discord links to D1
This commit is contained in:
parent
5a98e45544
commit
3a6a2cbbc5
16 changed files with 139 additions and 79 deletions
|
|
@ -73,20 +73,27 @@ export async function findUserIdByToken(
|
|||
* as that GitHub account. The actual OAuth token lives under `token:{githubUserId}`.
|
||||
*/
|
||||
export async function saveDiscordLink(
|
||||
kv: KVNamespace,
|
||||
db: D1Database,
|
||||
discordUserId: string,
|
||||
githubUserId: string,
|
||||
): Promise<void> {
|
||||
await kv.put(`discord-link:${discordUserId}`, githubUserId);
|
||||
await db
|
||||
.prepare("INSERT OR REPLACE INTO discord_links (discord_user_id, github_user_id) VALUES (?, ?)")
|
||||
.bind(discordUserId, githubUserId)
|
||||
.run();
|
||||
}
|
||||
|
||||
export async function getDiscordLink(
|
||||
kv: KVNamespace,
|
||||
db: D1Database,
|
||||
discordUserId: string,
|
||||
): Promise<string | null> {
|
||||
return await kv.get(`discord-link:${discordUserId}`, "text");
|
||||
const { results } = await db
|
||||
.prepare("SELECT github_user_id FROM discord_links WHERE discord_user_id = ?")
|
||||
.bind(discordUserId)
|
||||
.all<{ github_user_id: string }>();
|
||||
return results[0]?.github_user_id ?? null;
|
||||
}
|
||||
|
||||
export async function removeDiscordLink(kv: KVNamespace, discordUserId: string): Promise<void> {
|
||||
await kv.delete(`discord-link:${discordUserId}`);
|
||||
export async function removeDiscordLink(db: D1Database, discordUserId: string): Promise<void> {
|
||||
await db.prepare("DELETE FROM discord_links WHERE discord_user_id = ?").bind(discordUserId).run();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue