From 21331e53fec869d445bd89056ed24ef235540d87 Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 9 Feb 2023 10:46:01 +0900 Subject: [PATCH] refactor: fix types --- .../src/server/ActivityPubServerService.ts | 16 ++++++++++------ .../backend/src/server/api/SigninApiService.ts | 4 ++-- packages/backend/src/server/api/SigninService.ts | 2 +- .../backend/src/server/api/SignupApiService.ts | 4 ++-- .../backend/src/server/api/endpoints/endpoint.ts | 2 +- .../src/server/web/ClientServerService.ts | 2 +- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/packages/backend/src/server/ActivityPubServerService.ts b/packages/backend/src/server/ActivityPubServerService.ts index bdd2e97508..632a2ccb2e 100644 --- a/packages/backend/src/server/ActivityPubServerService.ts +++ b/packages/backend/src/server/ActivityPubServerService.ts @@ -1,3 +1,4 @@ +import { IncomingMessage } from 'node:http'; import { Inject, Injectable } from '@nestjs/common'; import fastifyAccepts from '@fastify/accepts'; import httpSignature from '@peertube/http-signature'; @@ -19,6 +20,7 @@ import { QueryService } from '@/core/QueryService.js'; import { UtilityService } from '@/core/UtilityService.js'; import { UserEntityService } from '@/core/entities/UserEntityService.js'; import { bindThis } from '@/decorators.js'; +import { IActivity } from '@/core/activitypub/type.js'; import type { FastifyInstance, FastifyRequest, FastifyReply, FastifyPluginOptions } from 'fastify'; import type { FindOptionsWhere } from 'typeorm'; @@ -97,7 +99,8 @@ export class ActivityPubServerService { return; } - this.queueService.inbox(request.body, signature); + // TODO: request.bodyのバリデーション? + this.queueService.inbox(request.body as IActivity, signature); reply.code(202); } @@ -413,20 +416,21 @@ export class ActivityPubServerService { @bindThis public createServer(fastify: FastifyInstance, options: FastifyPluginOptions, done: (err?: Error) => void) { - fastify.addConstraintStrategy({ + // addConstraintStrategy の型定義がおかしいため + (fastify.addConstraintStrategy as any)({ name: 'apOrHtml', storage() { - const store = {}; + const store = {} as any; return { - get(key) { + get(key: string) { return store[key] ?? null; }, - set(key, value) { + set(key: string, value: any) { store[key] = value; }, }; }, - deriveConstraint(request, ctx) { + deriveConstraint(request: IncomingMessage) { const accepted = accepts(request).type(['html', ACTIVITY_JSON, LD_JSON]); const isAp = typeof accepted === 'string' && !accepted.match(/html/); return isAp ? 'ap' : 'html'; diff --git a/packages/backend/src/server/api/SigninApiService.ts b/packages/backend/src/server/api/SigninApiService.ts index 10f8423d44..d490097dea 100644 --- a/packages/backend/src/server/api/SigninApiService.ts +++ b/packages/backend/src/server/api/SigninApiService.ts @@ -10,9 +10,9 @@ import { getIpHash } from '@/misc/get-ip-hash.js'; import type { ILocalUser } from '@/models/entities/User.js'; import { IdService } from '@/core/IdService.js'; import { TwoFactorAuthenticationService } from '@/core/TwoFactorAuthenticationService.js'; +import { bindThis } from '@/decorators.js'; import { RateLimiterService } from './RateLimiterService.js'; import { SigninService } from './SigninService.js'; -import { bindThis } from '@/decorators.js'; import type { FastifyRequest, FastifyReply } from 'fastify'; @Injectable() @@ -131,7 +131,7 @@ export class SigninApiService { createdAt: new Date(), userId: user.id, ip: request.ip, - headers: request.headers, + headers: request.headers as any, success: false, }); diff --git a/packages/backend/src/server/api/SigninService.ts b/packages/backend/src/server/api/SigninService.ts index 89a8a9ff16..655bf51a16 100644 --- a/packages/backend/src/server/api/SigninService.ts +++ b/packages/backend/src/server/api/SigninService.ts @@ -33,7 +33,7 @@ export class SigninService { createdAt: new Date(), userId: user.id, ip: request.ip, - headers: request.headers, + headers: request.headers as any, success: true, }).then(x => this.signinsRepository.findOneByOrFail(x.identifiers[0])); diff --git a/packages/backend/src/server/api/SignupApiService.ts b/packages/backend/src/server/api/SignupApiService.ts index 4b676bb8b9..c46f71d934 100644 --- a/packages/backend/src/server/api/SignupApiService.ts +++ b/packages/backend/src/server/api/SignupApiService.ts @@ -162,7 +162,7 @@ export class SignupApiService { token: secret, }; } catch (err) { - throw new FastifyReplyError(400, err); + throw new FastifyReplyError(400, typeof err === 'string' ? err : (err as Error).toString()); } } } @@ -195,7 +195,7 @@ export class SignupApiService { return this.signinService.signin(request, reply, account as ILocalUser); } catch (err) { - throw new FastifyReplyError(400, err); + throw new FastifyReplyError(400, typeof err === 'string' ? err : (err as Error).toString()); } } } diff --git a/packages/backend/src/server/api/endpoints/endpoint.ts b/packages/backend/src/server/api/endpoints/endpoint.ts index a337a05f8c..13b91685a4 100644 --- a/packages/backend/src/server/api/endpoints/endpoint.ts +++ b/packages/backend/src/server/api/endpoints/endpoint.ts @@ -27,7 +27,7 @@ export default class extends Endpoint { return { params: Object.entries(ep.params.properties ?? {}).map(([k, v]) => ({ name: k, - type: v.type.charAt(0).toUpperCase() + v.type.slice(1), + type: v.type ? v.type.charAt(0).toUpperCase() + v.type.slice(1) : 'string', })), }; }); diff --git a/packages/backend/src/server/web/ClientServerService.ts b/packages/backend/src/server/web/ClientServerService.ts index 2a764a25b0..044cba8d1e 100644 --- a/packages/backend/src/server/web/ClientServerService.ts +++ b/packages/backend/src/server/web/ClientServerService.ts @@ -155,7 +155,7 @@ export class ClientServerService { }); serverAdapter.setBasePath(bullBoardPath); - fastify.register(serverAdapter.registerPlugin(), { prefix: bullBoardPath }); + (fastify.register as any)(serverAdapter.registerPlugin(), { prefix: bullBoardPath }); //#endregion fastify.register(fastifyView, {