Skip to content

Commit

Permalink
fix: 修正got升级带来的类型变化
Browse files Browse the repository at this point in the history
  • Loading branch information
bangbang93 committed Feb 25, 2024
1 parent c0a17a4 commit 8115df3
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 30 deletions.
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"morgan": "^1.9.1",
"ms": "^2.1.2",
"p-map": "^7.0.1",
"pino": "^8.18.0",
"pino": "^8.19.0",
"pino-pretty": "^10.3.1",
"pretty-bytes": "^6.1.1",
"progress": "^2.0.3",
Expand All @@ -53,7 +53,7 @@
"devDependencies": {
"@bangbang93/eslint-config-recommended": "^0.0.3",
"@tsconfig/esm": "^1.0.3",
"@tsconfig/node18": "^1.0.1",
"@tsconfig/node18": "^18.2.2",
"@types/bluebird": "^3.5.27",
"@types/dotenv": "^6.1.1",
"@types/express": "^4.17.13",
Expand Down
17 changes: 14 additions & 3 deletions src/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {logger} from './logger.js'
import MeasureRouteFactory from './measure.route.js'
import {getStorage, type IStorage} from './storage/base.storage.js'
import type {TokenManager} from './token.js'
import type {IFileList} from './types'
import type {IFileList} from './types.js'
import {checkSign, hashToFilename} from './util.js'

interface ICounters {
Expand Down Expand Up @@ -76,11 +76,22 @@ export class Cluster {
'user-agent': this.ua,
},
responseType: 'buffer',
timeout: ms('5m'),
timeout: {
request: ms('5m'),
},
hooks: {
beforeRequest: [
async (options) => {
if (options.url.hostname.includes('bmclapi.bangbang93.com')) {
const url = options.url
if (!url) return
if (typeof url === 'string') {
if (url.includes('bmclapi.bangbang93.com') || url.includes('bmclapi2.bangbang93.com')) {
options.headers.authorization = `Bearer ${await this.tokenManager.getToken()}`
}
} else if (
url.hostname.includes('bmclapi.bangbang93.com') ||
url.hostname.includes('bmclapi2.bangbang93.com')
) {
options.headers.authorization = `Bearer ${await this.tokenManager.getToken()}`
}
},
Expand Down
18 changes: 10 additions & 8 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import pino from 'pino'
import {pino} from 'pino'

export const logger = pino({
level: process.env.LOGLEVEL || 'info',
transport: process.env.PLAIN_LOG ? undefined : {
target: 'pino-pretty',
options: {
translateTime: 'SYS:standard',
singleLine: true,
},
},
transport: process.env.PLAIN_LOG
? undefined
: {
target: 'pino-pretty',
options: {
translateTime: 'SYS:standard',
singleLine: true,
},
},
})
2 changes: 1 addition & 1 deletion src/storage/base.storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {join} from 'path'
import {cwd} from 'process'
import type {Config} from '../config.js'
import {logger} from '../logger.js'
import type {IFileInfo} from '../types'
import type {IFileInfo} from '../types.js'
import {AlistWebdavStorage} from './alist-webdav.storage.js'
import {FileStorage} from './file.storage.js'
import {WebdavStorage} from './webdav.storage.js'
Expand Down
2 changes: 1 addition & 1 deletion src/storage/webdav.storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {createClient, type FileStat, type WebDAVClient} from 'webdav'
import {z} from 'zod'
import {fromZodError} from 'zod-validation-error'
import {logger} from '../logger.js'
import type {IFileInfo} from '../types'
import type {IFileInfo} from '../types.js'
import type {IStorage} from './base.storage.js'

const storageConfigSchema = z.object({
Expand Down
4 changes: 3 additions & 1 deletion src/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export class TokenManager {
headers: {
'user-agent': `openbmclapi-cluster/${version}`,
},
timeout: ms('5m'),
timeout: {
request: ms('5m'),
},
})
}

Expand Down

0 comments on commit 8115df3

Please sign in to comment.