summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/CaptchaService.ts
diff options
context:
space:
mode:
authortamaina <tamaina@hotmail.co.jp>2023-01-12 21:03:02 +0900
committerGitHub <noreply@github.com>2023-01-12 21:03:02 +0900
commit978a9bbb3beafb7322aaf81d097430de6dbf527e (patch)
tree9f14ca1c7f9c1ccffe08a215bc06c19729bccbf6 /packages/backend/src/core/CaptchaService.ts
parentRole (#9437) (diff)
downloadsharkey-978a9bbb3beafb7322aaf81d097430de6dbf527e.tar.gz
sharkey-978a9bbb3beafb7322aaf81d097430de6dbf527e.tar.bz2
sharkey-978a9bbb3beafb7322aaf81d097430de6dbf527e.zip
perf(backend): Use undici instead of node-fetch and got (#9459)
* Implement? HttpFetchService * :v: * remove node-fetch * fix * refactor * fix * gateway timeout * UndiciFetcherクラスを追加 (仮コミット, ビルドもstartもさせていない) * fix * add logger and fix url preview * fix ip check * enhance logger and error handling * fix * fix * clean up * Use custom fetcher for ApRequest / ApResolver * bypassProxyはproxyBypassHostsに判断を委譲するように * set maxRedirections (default 3, ApRequest/ApResolver: 0) * fix comment * handle error s3 upload * add debug message * no return await * Revert "no return await" This reverts commit b5b0dc58a342393d260492e3a6f58304372f53b2. * reduce maxSockets * apResolverのUndiciFetcherを廃止しapRequestのものを使う、 add ap logger * Revert "apResolverのUndiciFetcherを廃止しapRequestのものを使う、 add ap logger" This reverts commit 997243915c8e1f8472da64f607f88c36cb1d5cb4. * add logger * fix * change logger name * safe * デフォルトでUser-Agentを設定
Diffstat (limited to 'packages/backend/src/core/CaptchaService.ts')
-rw-r--r--packages/backend/src/core/CaptchaService.ts26
1 files changed, 10 insertions, 16 deletions
diff --git a/packages/backend/src/core/CaptchaService.ts b/packages/backend/src/core/CaptchaService.ts
index 0207cf58a0..1e98914052 100644
--- a/packages/backend/src/core/CaptchaService.ts
+++ b/packages/backend/src/core/CaptchaService.ts
@@ -1,7 +1,4 @@
-import { Inject, Injectable } from '@nestjs/common';
-import { DI } from '@/di-symbols.js';
-import type { UsersRepository } from '@/models/index.js';
-import type { Config } from '@/config.js';
+import { Injectable } from '@nestjs/common';
import { HttpRequestService } from '@/core/HttpRequestService.js';
import { bindThis } from '@/decorators.js';
@@ -13,9 +10,6 @@ type CaptchaResponse = {
@Injectable()
export class CaptchaService {
constructor(
- @Inject(DI.config)
- private config: Config,
-
private httpRequestService: HttpRequestService,
) {
}
@@ -27,16 +21,16 @@ export class CaptchaService {
response,
});
- const res = await fetch(url, {
- method: 'POST',
- body: params,
- headers: {
- 'User-Agent': this.config.userAgent,
+ const res = await this.httpRequestService.fetch(
+ url,
+ {
+ method: 'POST',
+ body: params,
},
- // TODO
- //timeout: 10 * 1000,
- agent: (url, bypassProxy) => this.httpRequestService.getAgentByUrl(url, bypassProxy),
- }).catch(err => {
+ {
+ noOkError: true,
+ }
+ ).catch(err => {
throw `${err.message ?? err}`;
});