Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Generate text and images via the reverse-engineered Gemini Web API with multi-turn conversation support.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/gemini-webapi/utils/rotate-1psidts.ts
1import fs from 'node:fs';2import path from 'node:path';3import { mkdir, writeFile } from 'node:fs/promises';45import { Endpoint, Headers } from '../constants.js';6import { AuthError } from '../exceptions.js';7import { cookie_header, extract_set_cookie_value, fetch_with_timeout } from './http.js';8import { resolveGeminiWebDataDir } from './paths.js';910export async function rotate_1psidts(cookies: Record<string, string>, _proxy?: string | null): Promise<string | null> {11const p = resolveGeminiWebDataDir();12await mkdir(p, { recursive: true });1314const sid = cookies['__Secure-1PSID'];15if (!sid) throw new Error('Missing __Secure-1PSID cookie.');1617const cachePath = path.join(p, `.cached_1psidts_${sid}.txt`);1819try {20const st = fs.statSync(cachePath);21if (Date.now() - st.mtimeMs <= 60_000) return null;22} catch {}2324const res = await fetch_with_timeout(Endpoint.ROTATE_COOKIES, {25method: 'POST',26headers: { ...Headers.ROTATE_COOKIES, Cookie: cookie_header(cookies) },27body: '[000,"-0000000000000000000"]',28redirect: 'follow',29timeout_ms: 30_000,30});3132if (res.status === 401) throw new AuthError('Failed to refresh cookies (401).');33if (!res.ok) throw new Error(`RotateCookies failed: ${res.status} ${res.statusText}`);3435const setCookie = res.headers.get('set-cookie');36const v = extract_set_cookie_value(setCookie, '__Secure-1PSIDTS');37if (v) {38await writeFile(cachePath, v, 'utf8');39return v;40}4142return null;43}4445export const rotate1psidts = rotate_1psidts;4647