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/paths.ts
1import { execSync } from 'node:child_process';2import os from 'node:os';3import path from 'node:path';4import process from 'node:process';56const APP_DATA_DIR = 'baoyu-skills';7const GEMINI_DATA_DIR = 'gemini-web';8const COOKIE_FILE_NAME = 'cookies.json';9const PROFILE_DIR_NAME = 'chrome-profile';1011export function resolveUserDataRoot(): string {12if (process.platform === 'win32') {13return process.env.APPDATA ?? path.join(os.homedir(), 'AppData', 'Roaming');14}15if (process.platform === 'darwin') {16return path.join(os.homedir(), 'Library', 'Application Support');17}18return process.env.XDG_DATA_HOME ?? path.join(os.homedir(), '.local', 'share');19}2021export function resolveGeminiWebDataDir(): string {22const override = process.env.GEMINI_WEB_DATA_DIR?.trim();23if (override) return path.resolve(override);24return path.join(resolveUserDataRoot(), APP_DATA_DIR, GEMINI_DATA_DIR);25}2627export function resolveGeminiWebCookiePath(): string {28const override = process.env.GEMINI_WEB_COOKIE_PATH?.trim();29if (override) return path.resolve(override);30return path.join(resolveGeminiWebDataDir(), COOKIE_FILE_NAME);31}3233let _wslHome: string | null | undefined;34function getWslWindowsHome(): string | null {35if (_wslHome !== undefined) return _wslHome;36if (!process.env.WSL_DISTRO_NAME) { _wslHome = null; return null; }37try {38const raw = execSync('cmd.exe /C "echo %USERPROFILE%"', { encoding: 'utf-8', timeout: 5000 }).trim().replace(/\r/g, '');39_wslHome = execSync(`wslpath -u "${raw}"`, { encoding: 'utf-8', timeout: 5000 }).trim() || null;40} catch { _wslHome = null; }41return _wslHome;42}4344export function resolveGeminiWebChromeProfileDir(): string {45const override = process.env.BAOYU_CHROME_PROFILE_DIR?.trim() || process.env.GEMINI_WEB_CHROME_PROFILE_DIR?.trim();46if (override) return path.resolve(override);47const wslHome = getWslWindowsHome();48if (wslHome) return path.join(wslHome, '.local', 'share', APP_DATA_DIR, PROFILE_DIR_NAME);49return path.join(resolveUserDataRoot(), APP_DATA_DIR, PROFILE_DIR_NAME);50}5152export function resolveGeminiWebSessionsDir(): string {53return path.join(resolveGeminiWebDataDir(), 'sessions');54}5556export function resolveGeminiWebSessionPath(name: string): string {57const sanitized = name.replace(/[^a-zA-Z0-9_-]/g, '_');58return path.join(resolveGeminiWebSessionsDir(), `${sanitized}.json`);59}6061