feat: 支持自托管的 remote-control-server (#214)

* feat: 支持自托管的 remote-control-server (#214)

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This commit is contained in:
claude-code-best
2026-04-09 17:40:50 +08:00
committed by GitHub
parent f17b7c7163
commit 2da6514095
81 changed files with 9875 additions and 40 deletions

View File

@@ -0,0 +1,24 @@
import { storeCreateToken, storeGetUserByToken } from "../store";
let tokenCounter = 0;
/** Generate a random session token and associate it with a user */
export function issueToken(username: string): { token: string; expires_in: number } {
// Use crypto.getRandomValues for uniqueness
const bytes = new Uint8Array(16);
crypto.getRandomValues(bytes);
const hex = Array.from(bytes)
.map((b) => b.toString(16).padStart(2, "0"))
.join("");
const token = `rct_${tokenCounter++}_${hex}`;
storeCreateToken(username, token);
return { token, expires_in: 86400 };
}
/** Resolve a token to a username. Returns null if invalid. */
export function resolveToken(token: string | undefined): string | null {
if (!token) return null;
const entry = storeGetUserByToken(token);
if (!entry) return null;
return entry.username;
}