예제 소스
오목 좌표 LoRA: 15×15와 19×19 격자를 정확히 읽히기 · 파일 59개
guest.ts
const GUEST_KEY = "omook_guest_id";
const LAST_CODE_KEY = "omook_last_game_code";
const LAST_KEY_KEY = "omook_last_access_key";
function randomId(): string {
if (typeof crypto !== "undefined" && crypto.randomUUID) {
return crypto.randomUUID();
}
return `g_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 10)}`;
}
export function getOrCreateGuestId(): string {
if (typeof window === "undefined") return "";
let id = localStorage.getItem(GUEST_KEY);
if (!id) {
id = randomId();
localStorage.setItem(GUEST_KEY, id);
}
return id;
}
export function rememberGame(code: string, accessKey: string): void {
if (typeof window === "undefined") return;
localStorage.setItem(LAST_CODE_KEY, code.toUpperCase());
localStorage.setItem(LAST_KEY_KEY, accessKey);
localStorage.setItem(`omook_key_${code.toUpperCase()}`, accessKey);
}
export function loadRememberedGame(): { code: string; accessKey: string } | null {
if (typeof window === "undefined") return null;
const code = localStorage.getItem(LAST_CODE_KEY);
const accessKey = localStorage.getItem(LAST_KEY_KEY);
if (!code || !accessKey) return null;
return { code, accessKey };
}
export function loadAccessKeyForCode(code: string): string | null {
if (typeof window === "undefined") return null;
return localStorage.getItem(`omook_key_${code.toUpperCase()}`);
}
export function gameAuthQs(guestId: string, accessKey?: string | null): string {
const q = new URLSearchParams();
if (guestId) q.set("guestId", guestId);
if (accessKey) q.set("key", accessKey);
const s = q.toString();
return s ? `?${s}` : "";
}