Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion scripts/import_zai_curl.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import fs from 'fs';
import path from 'path';
import os from 'os';
import crypto from 'crypto';

const inputPath = process.argv[2] || '';
const outPath = process.argv[3] || `/tmp/freeglm-auth-${crypto.randomUUID()}.json`;
const outPath = process.argv[3] || path.join(os.tmpdir(), `freeglm-auth-${crypto.randomUUID()}.json`);
const curl = inputPath ? fs.readFileSync(inputPath, 'utf8') : fs.readFileSync(0, 'utf8');

function unquoteShell(s) {
Expand Down
11 changes: 7 additions & 4 deletions scripts/zai_browser_auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import fs from 'fs';
import path from 'path';
import os from 'os';
import { pathToFileURL } from 'url';
import { defaultChromeExecutable } from '../src/providers/zaiBrowser.js';

const outPath = process.argv[2] || process.env.AUTH_PATH || './auth.json';
Expand Down Expand Up @@ -55,9 +56,11 @@ export function isUsableZaiAuthToken(token, { allowGuest = false } = {}) {
}

async function readToken(page) {
return page.evaluate(() => {
try { return localStorage.getItem('token') || ''; } catch { return ''; }
});
try {
return await page.evaluate(() => {
try { return localStorage.getItem('token') || ''; } catch { return ''; }
});
} catch { return ''; }
}

async function cookieHeader(page) {
Expand Down Expand Up @@ -117,6 +120,6 @@ async function main() {
process.exit(2);
}

if (import.meta.url === `file://${process.argv[1]}`) {
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
main().catch(err => { console.error(err); process.exit(1); });
}
24 changes: 17 additions & 7 deletions src/providers/zaiBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,22 @@ export function defaultChromeExecutable() {
const candidates = [
process.env.CHROME_PATH,
process.env.PUPPETEER_EXECUTABLE_PATH,
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
'/Applications/Chromium.app/Contents/MacOS/Chromium',
'/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge',
'/usr/bin/google-chrome',
'/usr/bin/chromium-browser',
'/usr/bin/chromium'
...(process.platform === 'win32' ? [
`${process.env.LOCALAPPDATA}\\Google\\Chrome\\Application\\chrome.exe`,
`${process.env.PROGRAMFILES}\\Google\\Chrome\\Application\\chrome.exe`,
`${process.env['PROGRAMFILES(X86)']}\\Google\\Chrome\\Application\\chrome.exe`,
`${process.env.USERPROFILE}\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe`,
`${process.env.LOCALAPPDATA}\\Chromium\\Application\\chrome.exe`,
`${process.env.LOCALAPPDATA}\\Microsoft\\Edge\\Application\\msedge.exe`,
`${process.env.PROGRAMFILES}\\Microsoft\\Edge\\Application\\msedge.exe`,
] : [
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
'/Applications/Chromium.app/Contents/MacOS/Chromium',
'/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge',
'/usr/bin/google-chrome',
'/usr/bin/chromium-browser',
'/usr/bin/chromium',
])
].filter(Boolean);
return candidates.find(p => fs.existsSync(p)) || undefined;
}
Expand All @@ -54,7 +64,7 @@ export function cleanChromeProfileLocks(profileDir) {
if (LOCK_FILES.includes(entry.name) || entry.name === 'LOCK') {
try {
fs.rmSync(entryPath, { force: true, recursive: true });
removed.push(path.relative(profileDir, entryPath) || entry.name);
removed.push((path.relative(profileDir, entryPath) || entry.name).replaceAll('\\', '/'));
} catch {}
} else if (entry.isDirectory() && ['Default', 'Profile 1', 'Profile 2'].includes(entry.name)) {
visit(entryPath, depth + 1);
Expand Down