mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 20:00:47 +00:00
feat(usage): implement timeout and error handling for antigravity usage and subscription requests
- Add a 10-second timeout for fetch requests in getAntigravityUsage and getAntigravitySubscriptionInfo functions. - Include error logging for fetch failures in both functions. - Update headers to include "x-request-source" for MITM bypass. - Enhance proxyFetch with DNS resolution and MITM bypass capabilities. - Ensure proxyFetch is loaded in the API route for proper fetch patching.
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
// Ensure proxyFetch is loaded to patch globalThis.fetch
|
||||
import "open-sse/index.js";
|
||||
|
||||
import { getProviderConnectionById, updateProviderConnection } from "@/lib/localDb";
|
||||
import { getUsageForProvider } from "open-sse/services/usage.js";
|
||||
import { getExecutor } from "open-sse/executors/index.js";
|
||||
|
||||
@@ -261,12 +261,16 @@ const PROVIDERS = {
|
||||
"User-Agent": ANTIGRAVITY_CONFIG.loadCodeAssistUserAgent,
|
||||
"X-Goog-Api-Client": ANTIGRAVITY_CONFIG.loadCodeAssistApiClient,
|
||||
"Client-Metadata": ANTIGRAVITY_CONFIG.loadCodeAssistClientMetadata,
|
||||
"x-request-source": "local", // MITM passthrough marker
|
||||
};
|
||||
const metadata = getOAuthClientMetadata();
|
||||
|
||||
// Fetch user info
|
||||
const userInfoRes = await fetch(`${ANTIGRAVITY_CONFIG.userInfoUrl}?alt=json`, {
|
||||
headers: { Authorization: `Bearer ${tokens.access_token}` },
|
||||
headers: {
|
||||
Authorization: `Bearer ${tokens.access_token}`,
|
||||
"x-request-source": "local", // MITM passthrough marker
|
||||
},
|
||||
});
|
||||
const userInfo = userInfoRes.ok ? await userInfoRes.json() : {};
|
||||
|
||||
|
||||
+1
-4
@@ -201,20 +201,17 @@ const server = https.createServer(sslOptions, async (req, res) => {
|
||||
}
|
||||
|
||||
const model = extractModel(req.url, bodyBuffer);
|
||||
console.log(`📡 intercepted: ${req.url} | model: ${model}`);
|
||||
const mappedModel = getMappedModel(model);
|
||||
|
||||
if (!mappedModel) {
|
||||
return passthrough(req, res, bodyBuffer);
|
||||
}
|
||||
|
||||
console.log(`🔀 ${model} → ${mappedModel}`);
|
||||
return intercept(req, res, bodyBuffer, mappedModel);
|
||||
});
|
||||
|
||||
server.listen(LOCAL_PORT, () => {
|
||||
console.log(`🚀 MITM ready on :${LOCAL_PORT} → ${ROUTER_URL}`);
|
||||
console.log(`📡 Intercepting: ${TARGET_HOSTS.join(", ")}`);
|
||||
console.log(`🚀 MITM ready on :${LOCAL_PORT}`);
|
||||
});
|
||||
|
||||
server.on("error", (error) => {
|
||||
|
||||
Reference in New Issue
Block a user