refactor(backend): validateNoteの引数の型を強くし、anyを除去 (#10325)

* refactor(backend): validateNoteの引数の型を推論する

* fix(backend): アサーションの内容から推論してエラーの内容を期待されるであろう式へと変更する

* refactor

Co-authored-by: Acid-Chicken <root@acid-chicken.com>

---------

Co-authored-by: tamaina <tamaina@hotmail.co.jp>
Co-authored-by: Acid-Chicken <root@acid-chicken.com>
This commit is contained in:
Kisaragi 2023-04-14 16:27:55 +09:00 committed by GitHub
parent c47a0f78ff
commit 83d0f819be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 4 deletions

View File

@ -71,7 +71,7 @@ export class ApNoteService {
} }
@bindThis @bindThis
public validateNote(object: any, uri: string) { public validateNote(object: IObject, uri: string) {
const expectHost = this.utilityService.extractDbHost(uri); const expectHost = this.utilityService.extractDbHost(uri);
if (object == null) { if (object == null) {
@ -85,9 +85,10 @@ export class ApNoteService {
if (object.id && this.utilityService.extractDbHost(object.id) !== expectHost) { if (object.id && this.utilityService.extractDbHost(object.id) !== expectHost) {
return new Error(`invalid Note: id has different host. expected: ${expectHost}, actual: ${this.utilityService.extractDbHost(object.id)}`); return new Error(`invalid Note: id has different host. expected: ${expectHost}, actual: ${this.utilityService.extractDbHost(object.id)}`);
} }
if (object.attributedTo && this.utilityService.extractDbHost(getOneApId(object.attributedTo)) !== expectHost) { const actualHost = object.attributedTo && this.utilityService.extractDbHost(getOneApId(object.attributedTo));
return new Error(`invalid Note: attributedTo has different host. expected: ${expectHost}, actual: ${this.utilityService.extractDbHost(object.attributedTo)}`); if (object.attributedTo && actualHost !== expectHost) {
return new Error(`invalid Note: attributedTo has different host. expected: ${expectHost}, actual: ${actualHost}`);
} }
return null; return null;