Skip to content

Commit

Permalink
fix: got 未统一
Browse files Browse the repository at this point in the history
  • Loading branch information
SALTWOOD committed Nov 2, 2024
1 parent 4853036 commit 8c248f2
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
4 changes: 0 additions & 4 deletions src/Server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand All @@ -96,8 +94,6 @@ export class Server {
this.plugins = [];
this.pluginLoader = new PluginLoader();

this.got = request;

// 创建 Express 应用
this.app = express();

Expand Down
6 changes: 3 additions & 3 deletions src/Utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -483,7 +483,7 @@ export class Utilities {
public static async doMeasure(url: string): Promise<number> {
try {
// 发出请求,接收下载数据
const response = await got(url, {
const response = await request(url, {
responseType: 'buffer', // 以二进制数据形式接收
timeout: { request: 60000 }, // 设置请求超时时间 (可选)
});
Expand Down
5 changes: 3 additions & 2 deletions src/routes/ApiAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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,
Expand All @@ -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',
Expand Down
3 changes: 0 additions & 3 deletions src/routes/ApiFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 8c248f2

Please sign in to comment.