mirror of
https://github.com/lWolvesl/antigravity-usage-monitor.git
synced 2026-11-26 17:09:28 +08:00
- Enable Windows multi-account sign-in via loopback PKCE OAuth and unified borderless quota cards with Ultra 5x/20x tier detection and instant cached-list preloading - Keep active-account quota strictly on live host telemetry while supporting configurable background OAuth refresh intervals (10m-24h, default 1h) for saved backup accounts - Add optional scrypt + AES-256-GCM secondary passphrase encryption with per-email AAD binding, unlock backoff, key zeroing, at-rest token minimization, and OAuth client_id allowlisting - Harden account mutations with inline two-step switch/remove confirmations, HMAC action nonces, Webview context checks, standalone web 403 isolation, and user-only vault directory ACLs
68 lines
2.6 KiB
JavaScript
68 lines
2.6 KiB
JavaScript
/** @fileoverview Google account requests using the panel's system proxy transport. */
|
|
|
|
import * as http from 'node:http';
|
|
import * as https from 'node:https';
|
|
import * as net from 'node:net';
|
|
import * as tls from 'node:tls';
|
|
import { detectSystemHttpsProxy, openCcProxyTunnelSocket } from './cloudcode-proxy.mjs';
|
|
|
|
export async function fetchGoogleAccount(url, { method = 'GET', body, headers = {}, signal } = {}) {
|
|
const target = new URL(url);
|
|
if (target.protocol !== 'https:' || !/^(?:oauth2|www|cloudcode-pa|daily-cloudcode-pa(?:\.sandbox)?)\.googleapis\.com$/.test(target.hostname)) {
|
|
throw new Error('Unsupported Google account endpoint');
|
|
}
|
|
signal?.throwIfAborted();
|
|
const proxy = await detectSystemHttpsProxy(target.hostname);
|
|
signal?.throwIfAborted();
|
|
const socket = proxy
|
|
? await openCcProxyTunnelSocket({ http, https, net, tls }, target.hostname, 443, proxy, { timeoutMs: 4500 })
|
|
: null;
|
|
if (signal?.aborted) {
|
|
socket?.destroy();
|
|
signal.throwIfAborted();
|
|
}
|
|
const textBody = body === undefined ? undefined : String(body);
|
|
const requestHeaders = { Accept: 'application/json', ...headers };
|
|
if (body instanceof URLSearchParams) requestHeaders['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
if (textBody !== undefined) requestHeaders['Content-Length'] = Buffer.byteLength(textBody);
|
|
let socketConsumed = false;
|
|
const agent = socket ? new https.Agent({ keepAlive: false }) : null;
|
|
if (agent) {
|
|
agent.createConnection = () => {
|
|
socketConsumed = true;
|
|
return socket;
|
|
};
|
|
}
|
|
const onAbort = () => {
|
|
if (!socketConsumed) socket?.destroy();
|
|
};
|
|
signal?.addEventListener?.('abort', onAbort, { once: true });
|
|
|
|
return new Promise((resolve, reject) => {
|
|
const request = https.request(target, { method, headers: requestHeaders, signal, ...(agent ? { agent } : {}) }, (response) => {
|
|
const chunks = [];
|
|
let bytes = 0;
|
|
response.on('data', (chunk) => {
|
|
bytes += chunk.length;
|
|
if (bytes > 4 * 1024 * 1024) return request.destroy(new Error('Account response too large'));
|
|
chunks.push(chunk);
|
|
});
|
|
response.on('error', reject);
|
|
response.on('end', () => {
|
|
const raw = Buffer.concat(chunks).toString('utf8');
|
|
const status = response.statusCode || 0;
|
|
resolve({ status, ok: status >= 200 && status < 300, json: async () => JSON.parse(raw) });
|
|
});
|
|
});
|
|
request.on('error', (err) => {
|
|
if (!socketConsumed) socket?.destroy();
|
|
reject(err);
|
|
});
|
|
request.on('close', () => {
|
|
signal?.removeEventListener?.('abort', onAbort);
|
|
agent?.destroy();
|
|
});
|
|
request.end(textBody);
|
|
});
|
|
}
|