mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-05 21:12:49 +08:00
feat: add private expiring workspace invites and restore KAAK home
This commit is contained in:
1 parent
33ba062686
commit
72d7e6e013
39 files changed
+512
-53
No files matched your search
@@ -6,7 +6,7 @@ import type { AdminCredential } from "../security/admin-password.js";
|
||||
import type { TeamSpeakProtocol } from "../server/teamspeak-adapter.js";
|
||||
import { DEFAULT_WEBRTC_UDP_PORT_RANGE } from "../server/webrtc-config.js";
|
||||
|
||||
export const DATABASE_SCHEMA_VERSION = 12;
|
||||
export const DATABASE_SCHEMA_VERSION = 13;
|
||||
export type AccessMode = "fixed" | "open";
|
||||
|
||||
export interface PersistedSettings {
|
||||
@@ -190,6 +190,18 @@ export class WebSpeakDatabase {
|
||||
this.migrate(existed);
|
||||
}
|
||||
|
||||
saveWorkspaceInvite(tokenHash: string, encrypted: string, expiresAt: number, now = Date.now()): void {
|
||||
this.database.prepare("DELETE FROM workspace_invites WHERE expires_at <= ?").run(now);
|
||||
const count = this.database.prepare("SELECT COUNT(*) AS n FROM workspace_invites").get() as { n: number };
|
||||
if (count.n >= 4096) throw new Error("INVITE_LIMIT_REACHED");
|
||||
this.database.prepare("INSERT INTO workspace_invites(token_hash, payload_encrypted, expires_at) VALUES (?, ?, ?)").run(tokenHash, encrypted, expiresAt);
|
||||
}
|
||||
|
||||
getWorkspaceInvite(tokenHash: string, now = Date.now()): string | null {
|
||||
const row = this.database.prepare("SELECT payload_encrypted FROM workspace_invites WHERE token_hash = ? AND expires_at > ?").get(tokenHash, now) as { payload_encrypted: string } | undefined;
|
||||
return row?.payload_encrypted ?? null;
|
||||
}
|
||||
|
||||
close(): void {
|
||||
this.database.close();
|
||||
}
|
||||
@@ -731,6 +743,17 @@ export class WebSpeakDatabase {
|
||||
PRAGMA user_version = 12;
|
||||
`);
|
||||
});
|
||||
version = 12;
|
||||
}
|
||||
if (version === 12) {
|
||||
this.transaction(() => {
|
||||
this.database.exec(`CREATE TABLE workspace_invites (
|
||||
token_hash TEXT PRIMARY KEY,
|
||||
payload_encrypted TEXT NOT NULL,
|
||||
expires_at INTEGER NOT NULL
|
||||
); CREATE INDEX workspace_invites_expiry ON workspace_invites(expires_at);
|
||||
PRAGMA user_version = 13;`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user