优化路径分布
Browse files- package.json +4 -4
- oauth-server.js → scripts/oauth-server.js +17 -5
- api.js → src/api/client.js +2 -3
- token_manager.js → src/auth/token_manager.js +2 -2
- config.js → src/config/config.js +1 -1
- server.js → src/server/index.js +4 -4
- logger.js → src/utils/logger.js +0 -0
- utils.js → src/utils/utils.js +1 -1
- test-transform.js → test/test-transform.js +0 -0
package.json
CHANGED
|
@@ -3,11 +3,11 @@
|
|
| 3 |
"version": "1.0.0",
|
| 4 |
"description": "Antigravity API 转 OpenAI 格式的代理服务",
|
| 5 |
"type": "module",
|
| 6 |
-
"main": "server.js",
|
| 7 |
"scripts": {
|
| 8 |
-
"start": "node server.js",
|
| 9 |
-
"login": "node oauth-server.js",
|
| 10 |
-
"dev": "node --watch server.js"
|
| 11 |
},
|
| 12 |
"keywords": ["antigravity", "openai", "api", "proxy"],
|
| 13 |
"author": "",
|
|
|
|
| 3 |
"version": "1.0.0",
|
| 4 |
"description": "Antigravity API 转 OpenAI 格式的代理服务",
|
| 5 |
"type": "module",
|
| 6 |
+
"main": "src/server/index.js",
|
| 7 |
"scripts": {
|
| 8 |
+
"start": "node src/server/index.js",
|
| 9 |
+
"login": "node scripts/oauth-server.js",
|
| 10 |
+
"dev": "node --watch src/server/index.js"
|
| 11 |
},
|
| 12 |
"keywords": ["antigravity", "openai", "api", "proxy"],
|
| 13 |
"author": "",
|
oauth-server.js → scripts/oauth-server.js
RENAMED
|
@@ -3,7 +3,13 @@ import https from 'https';
|
|
| 3 |
import { URL } from 'url';
|
| 4 |
import crypto from 'crypto';
|
| 5 |
import fs from 'fs';
|
| 6 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
const CLIENT_ID = '1071006060591-tmhssin2h21lcre235vtolojh4g403ep.apps.googleusercontent.com';
|
| 9 |
const CLIENT_SECRET = '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';
|
|
@@ -93,17 +99,23 @@ const server = http.createServer((req, res) => {
|
|
| 93 |
|
| 94 |
let accounts = [];
|
| 95 |
try {
|
| 96 |
-
if (fs.existsSync(
|
| 97 |
-
accounts = JSON.parse(fs.readFileSync(
|
| 98 |
}
|
| 99 |
} catch (err) {
|
| 100 |
log.warn('读取 accounts.json 失败,将创建新文件');
|
| 101 |
}
|
| 102 |
|
| 103 |
accounts.push(account);
|
| 104 |
-
fs.writeFileSync('accounts.json', JSON.stringify(accounts, null, 2));
|
| 105 |
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
//log.info(`过期时间: ${account.expires_in}秒`);
|
| 108 |
|
| 109 |
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
|
|
|
| 3 |
import { URL } from 'url';
|
| 4 |
import crypto from 'crypto';
|
| 5 |
import fs from 'fs';
|
| 6 |
+
import path from 'path';
|
| 7 |
+
import { fileURLToPath } from 'url';
|
| 8 |
+
import log from '../src/utils/logger.js';
|
| 9 |
+
|
| 10 |
+
const __filename = fileURLToPath(import.meta.url);
|
| 11 |
+
const __dirname = path.dirname(__filename);
|
| 12 |
+
const ACCOUNTS_FILE = path.join(__dirname, '..', 'data', 'accounts.json');
|
| 13 |
|
| 14 |
const CLIENT_ID = '1071006060591-tmhssin2h21lcre235vtolojh4g403ep.apps.googleusercontent.com';
|
| 15 |
const CLIENT_SECRET = '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';
|
|
|
|
| 99 |
|
| 100 |
let accounts = [];
|
| 101 |
try {
|
| 102 |
+
if (fs.existsSync(ACCOUNTS_FILE)) {
|
| 103 |
+
accounts = JSON.parse(fs.readFileSync(ACCOUNTS_FILE, 'utf-8'));
|
| 104 |
}
|
| 105 |
} catch (err) {
|
| 106 |
log.warn('读取 accounts.json 失败,将创建新文件');
|
| 107 |
}
|
| 108 |
|
| 109 |
accounts.push(account);
|
|
|
|
| 110 |
|
| 111 |
+
const dir = path.dirname(ACCOUNTS_FILE);
|
| 112 |
+
if (!fs.existsSync(dir)) {
|
| 113 |
+
fs.mkdirSync(dir, { recursive: true });
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
fs.writeFileSync(ACCOUNTS_FILE, JSON.stringify(accounts, null, 2));
|
| 117 |
+
|
| 118 |
+
log.info(`Token 已保存到 ${ACCOUNTS_FILE}`);
|
| 119 |
//log.info(`过期时间: ${account.expires_in}秒`);
|
| 120 |
|
| 121 |
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
api.js → src/api/client.js
RENAMED
|
@@ -1,6 +1,5 @@
|
|
| 1 |
-
import tokenManager from '
|
| 2 |
-
import
|
| 3 |
-
import config from './config.js';
|
| 4 |
|
| 5 |
export async function generateAssistantResponse(requestBody, callback) {
|
| 6 |
const token = await tokenManager.getToken();
|
|
|
|
| 1 |
+
import tokenManager from '../auth/token_manager.js';
|
| 2 |
+
import config from '../config/config.js';
|
|
|
|
| 3 |
|
| 4 |
export async function generateAssistantResponse(requestBody, callback) {
|
| 5 |
const token = await tokenManager.getToken();
|
token_manager.js → src/auth/token_manager.js
RENAMED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import fs from 'fs';
|
| 2 |
import path from 'path';
|
| 3 |
import { fileURLToPath } from 'url';
|
| 4 |
-
import { log } from '
|
| 5 |
|
| 6 |
const __filename = fileURLToPath(import.meta.url);
|
| 7 |
const __dirname = path.dirname(__filename);
|
|
@@ -10,7 +10,7 @@ const CLIENT_ID = '1071006060591-tmhssin2h21lcre235vtolojh4g403ep.apps.googleuse
|
|
| 10 |
const CLIENT_SECRET = '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';
|
| 11 |
|
| 12 |
class TokenManager {
|
| 13 |
-
constructor(filePath = path.join(__dirname, 'accounts.json')) {
|
| 14 |
this.filePath = filePath;
|
| 15 |
this.tokens = [];
|
| 16 |
this.currentIndex = 0;
|
|
|
|
| 1 |
import fs from 'fs';
|
| 2 |
import path from 'path';
|
| 3 |
import { fileURLToPath } from 'url';
|
| 4 |
+
import { log } from '../utils/logger.js';
|
| 5 |
|
| 6 |
const __filename = fileURLToPath(import.meta.url);
|
| 7 |
const __dirname = path.dirname(__filename);
|
|
|
|
| 10 |
const CLIENT_SECRET = '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';
|
| 11 |
|
| 12 |
class TokenManager {
|
| 13 |
+
constructor(filePath = path.join(__dirname,'..','..','data' ,'accounts.json')) {
|
| 14 |
this.filePath = filePath;
|
| 15 |
this.tokens = [];
|
| 16 |
this.currentIndex = 0;
|
config.js → src/config/config.js
RENAMED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import fs from 'fs';
|
| 2 |
-
import log from '
|
| 3 |
|
| 4 |
const defaultConfig = {
|
| 5 |
server: { port: 8045, host: '127.0.0.1' },
|
|
|
|
| 1 |
import fs from 'fs';
|
| 2 |
+
import log from '../utils/logger.js';
|
| 3 |
|
| 4 |
const defaultConfig = {
|
| 5 |
server: { port: 8045, host: '127.0.0.1' },
|
server.js → src/server/index.js
RENAMED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
import express from 'express';
|
| 2 |
-
import { generateAssistantResponse, getAvailableModels } from '
|
| 3 |
-
import { generateRequestBody } from '
|
| 4 |
-
import logger from '
|
| 5 |
-
import config from '
|
| 6 |
|
| 7 |
const app = express();
|
| 8 |
|
|
|
|
| 1 |
import express from 'express';
|
| 2 |
+
import { generateAssistantResponse, getAvailableModels } from '../api/client.js';
|
| 3 |
+
import { generateRequestBody } from '../utils/utils.js';
|
| 4 |
+
import logger from '../utils/logger.js';
|
| 5 |
+
import config from '../config/config.js';
|
| 6 |
|
| 7 |
const app = express();
|
| 8 |
|
logger.js → src/utils/logger.js
RENAMED
|
File without changes
|
utils.js → src/utils/utils.js
RENAMED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
import { randomUUID } from 'crypto';
|
| 2 |
-
import config from '
|
| 3 |
|
| 4 |
function generateRequestId() {
|
| 5 |
return `agent-${randomUUID()}`;
|
|
|
|
| 1 |
import { randomUUID } from 'crypto';
|
| 2 |
+
import config from '../config/config.js';
|
| 3 |
|
| 4 |
function generateRequestId() {
|
| 5 |
return `agent-${randomUUID()}`;
|
test-transform.js → test/test-transform.js
RENAMED
|
File without changes
|