diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2023-01-24 08:31:02 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2023-01-24 08:31:02 +0900 |
| commit | 238f923b419b487337fbcaa5ba415bf2f823f27e (patch) | |
| tree | 166ec8c3e1824f706ab9cb99be064c57939718b3 /packages/backend/src/core/DownloadService.ts | |
| parent | 13.2.0 (diff) | |
| download | sharkey-238f923b419b487337fbcaa5ba415bf2f823f27e.tar.gz sharkey-238f923b419b487337fbcaa5ba415bf2f823f27e.tar.bz2 sharkey-238f923b419b487337fbcaa5ba415bf2f823f27e.zip | |
refactor(server): httpRequestServiceのUndiciFetcher依存をなるべくカプセル化
Diffstat (limited to 'packages/backend/src/core/DownloadService.ts')
| -rw-r--r-- | packages/backend/src/core/DownloadService.ts | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/packages/backend/src/core/DownloadService.ts b/packages/backend/src/core/DownloadService.ts index a3078bff45..e4632f857a 100644 --- a/packages/backend/src/core/DownloadService.ts +++ b/packages/backend/src/core/DownloadService.ts @@ -6,6 +6,7 @@ import IPCIDR from 'ip-cidr'; import PrivateIp from 'private-ip'; import got, * as Got from 'got'; import chalk from 'chalk'; +import { buildConnector } from 'undici'; import { DI } from '@/di-symbols.js'; import type { Config } from '@/config.js'; import { HttpRequestService, UndiciFetcher } from '@/core/HttpRequestService.js'; @@ -13,7 +14,6 @@ import { createTemp } from '@/misc/create-temp.js'; import { StatusError } from '@/misc/status-error.js'; import { LoggerService } from '@/core/LoggerService.js'; import type Logger from '@/logger.js'; -import { buildConnector } from 'undici'; const pipeline = util.promisify(stream.pipeline); import { bindThis } from '@/decorators.js'; @@ -32,23 +32,20 @@ export class DownloadService { ) { this.logger = this.loggerService.getLogger('download'); - this.undiciFetcher = new UndiciFetcher(this.httpRequestService.getStandardUndiciFetcherOption( - { - connect: process.env.NODE_ENV === 'development' ? - this.httpRequestService.clientDefaults.connect - : - this.httpRequestService.getConnectorWithIpCheck( - buildConnector({ - ...this.httpRequestService.clientDefaults.connect, - }), - (ip) => !this.isPrivateIp(ip) - ), - bodyTimeout: 30 * 1000, - }, - { - connect: this.httpRequestService.clientDefaults.connect, - } - ), this.logger); + this.undiciFetcher = this.httpRequestService.createFetcher({ + connect: process.env.NODE_ENV === 'development' ? + this.httpRequestService.clientDefaults.connect + : + this.httpRequestService.getConnectorWithIpCheck( + buildConnector({ + ...this.httpRequestService.clientDefaults.connect, + }), + (ip) => !this.isPrivateIp(ip), + ), + bodyTimeout: 30 * 1000, + }, { + connect: this.httpRequestService.clientDefaults.connect, + }, this.logger); } @bindThis |