chore: upgrade got (#14913)

* chore: upgrade got

* fix: new got
This commit is contained in:
DIYgod 2024-03-22 14:42:29 +00:00 committed by GitHub
parent 2ed8e87a4d
commit 2789ed96e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 392 additions and 439 deletions

View File

@ -11,9 +11,6 @@ updates:
ignore:
- dependency-name: jsrsasign
versions: ['>=11.0.0'] # no longer includes KJUR.crypto.Cipher for RSA
# ESM only packages
- dependency-name: got
versions: ['>=12.0.0']
- dependency-name: unified
versions: ['>=10.0.0']

View File

@ -1,6 +1,6 @@
import logger from '@/utils/logger';
import { config } from '@/config';
import got, { CancelableRequest, Response as GotResponse, NormalizedOptions, Options, Got } from 'got';
import got, { CancelableRequest, Response as GotResponse, OptionsInit, Options, Got } from 'got';
type Response<T> = GotResponse<string> & {
data: T;
@ -25,22 +25,14 @@ const custom: {
delete: GotRequestFunction;
} & GotRequestFunction &
Got = got.extend({
get: got.get,
retry: {
limit: config.requestRetry,
statusCodes: [400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 421, 422, 423, 424, 426, 428, 429, 431, 451, 500, 501, 502, 503, 504, 505, 506, 507, 508, 510, 511, 521, 522, 524],
},
hooks: {
beforeRetry: [
(
options: NormalizedOptions & {
retryCount?: number;
},
err,
count
) => {
logger.error(`Request ${options.url} fail, retry attempt #${count}: ${err}`);
options.retryCount = count;
(err, count) => {
logger.error(`Request ${err.options.url} fail, retry attempt #${count}: ${err}`);
},
],
beforeRedirect: [
@ -63,7 +55,7 @@ const custom: {
],
init: [
(
options: Options & {
options: OptionsInit & {
data?: string;
}
) => {
@ -84,4 +76,4 @@ const custom: {
custom.all = (list) => Promise.all(list);
export default custom;
export type { Response, NormalizedOptions, Options } from 'got';
export type { Response, Options } from 'got';

View File

@ -45,6 +45,7 @@ const requestWrapper = (url: string, options: http.RequestOptions = {}) => {
if (config.proxyStrategy === 'all') {
prxied = proxyWrapper(url, optionsWithHeaders);
} else if (config.proxyStrategy === 'on_retry' && (optionsWithHeaders as any).retryCount) {
// TODO
prxied = proxyWrapper(url, optionsWithHeaders);
}
if (prxied) {

View File

@ -70,7 +70,7 @@
"fanfou-sdk": "5.0.0",
"git-rev-sync": "3.0.2",
"googleapis": "134.0.0",
"got": "11.8.6",
"got": "14.2.1",
"hono": "4.1.3",
"html-to-text": "9.0.5",
"https-proxy-agent": "7.0.4",

File diff suppressed because it is too large Load Diff