diff --git a/src/Server.ts b/src/Server.ts index 82ff1a4..c7b22d1 100644 --- a/src/Server.ts +++ b/src/Server.ts @@ -17,7 +17,6 @@ import { HourlyStatsStorage } from './statistics/HourlyStats.js'; import cookieParser from 'cookie-parser'; import { Plugin } from './plugin/Plugin.js'; import { PluginLoader } from './plugin/PluginLoader.js'; -import {type Got} from 'got' import acme from 'acme-client' import { FileList } from './FileList.js'; import RateLimiter, { rateLimiter } from './RateLimiter.js'; @@ -69,7 +68,6 @@ export class Server { public centerStats: HourlyStatsStorage; public plugins: Plugin[]; protected pluginLoader: PluginLoader; - public got: Got; public sources: { name: string, count: number, lastUpdated: Date, isFromPlugin: boolean }[] = []; protected dns: DnsManager | null = null; protected acme: ACME | null = null; @@ -96,8 +94,6 @@ export class Server { this.plugins = []; this.pluginLoader = new PluginLoader(); - this.got = request; - // 创建 Express 应用 this.app = express(); diff --git a/src/Utilities.ts b/src/Utilities.ts index 91aecd5..e0e246b 100644 --- a/src/Utilities.ts +++ b/src/Utilities.ts @@ -10,9 +10,9 @@ import { exec, ExecException } from 'child_process'; import { ClusterEntity } from './database/Cluster.js'; import { SQLiteHelper } from './SQLiteHelper.js'; import { UserEntity } from './database/User.js'; -import got, { Got } from 'got'; import { Config } from './Config.js'; import os from 'os'; +import { request } from './Request.js'; export const FileListSchema = avsc.Type.forSchema({ type: 'array', @@ -191,7 +191,7 @@ export class Utilities { public static async checkUrl(url: string): Promise<{ url: string; hash: string }> { try { - const response = await got.get(url, { + const response = await request(url, { responseType: 'buffer' }); const responseData = response.body as Buffer; @@ -483,7 +483,7 @@ export class Utilities { public static async doMeasure(url: string): Promise { try { // 发出请求,接收下载数据 - const response = await got(url, { + const response = await request(url, { responseType: 'buffer', // 以二进制数据形式接收 timeout: { request: 60000 }, // 设置请求超时时间 (可选) }); diff --git a/src/routes/ApiAuth.ts b/src/routes/ApiAuth.ts index 73e5373..69fe255 100644 --- a/src/routes/ApiAuth.ts +++ b/src/routes/ApiAuth.ts @@ -2,6 +2,7 @@ import { Config } from "../Config.js"; import { GitHubUser } from "../database/GitHubUser.js"; import { UserEntity } from "../database/User.js"; import JwtHelper from "../JwtHelper.js"; +import { request } from "../Request.js"; import { Utilities } from "../Utilities.js"; import { ApiFactory } from "./ApiFactory.js"; import { NextFunction, Request, Response } from "express"; @@ -18,7 +19,7 @@ export class ApiAuth { const code = req.query.code as string || ''; // 请求GitHub获取access_token - const tokenData = await inst.got.post(`https://${Config.instance.githubUrl}/login/oauth/access_token`, { + const tokenData = await request.post(`https://${Config.instance.githubUrl}/login/oauth/access_token`, { form: { code, client_id: Config.instance.githubOAuthClientId, @@ -32,7 +33,7 @@ export class ApiAuth { const accessToken = tokenData.access_token; - let userResponse = await inst.got.get(`https://${Config.instance.githubApiUrl}/user`, { + let userResponse = await request.get(`https://${Config.instance.githubApiUrl}/user`, { headers: { 'Authorization': `token ${accessToken}`, 'Accept': 'application/json', diff --git a/src/routes/ApiFactory.ts b/src/routes/ApiFactory.ts index ecabf7c..fce9859 100644 --- a/src/routes/ApiFactory.ts +++ b/src/routes/ApiFactory.ts @@ -25,9 +25,6 @@ export class ApiFactory { public acme: ACME | null; public app: Express; - public get got(): Got { - return this.server.got; - } public get files(): File[] { return this.fileList.files; }