fix: preserve invites on nickname lookup failure

This commit is contained in:
illusia committed 2026-10-09 00:26:21 +08:00
1 parent 75893339c5
commit efa0b85a0e
4 files changed
+45 -2

No files matched your search

+12
View File
@@ -333,6 +333,18 @@ export class WebSpeakDatabase {
return rows.map(mapManagedInviteRow);
}
getManagedInvite(tokenHash: string, now = Date.now()): ManagedInviteRecord | null {
const nowIso = new Date(now).toISOString();
const row = this.database.prepare(
`SELECT * FROM managed_invites
WHERE token_hash = ?
AND revoked_at IS NULL
AND expires_at > ?
AND (max_uses = 0 OR use_count < max_uses)`,
).get(tokenHash, nowIso) as ManagedInviteRow | undefined;
return row ? mapManagedInviteRow(row) : null;
}
revokeManagedInvite(id: string): boolean {
const result = this.database.prepare(
"UPDATE managed_invites SET revoked_at = ? WHERE id = ? AND revoked_at IS NULL",