Skip to content

Commit

Permalink
refactor(backend): validateNoteの引数の型を強くし、anyを除去 (misskey-dev#10325)
Browse files Browse the repository at this point in the history
* refactor(backend): validateNoteの引数の型を推論する

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

* refactor

Co-authored-by: Acid-Chicken <[email protected]>

---------

Co-authored-by: tamaina <[email protected]>
Co-authored-by: Acid-Chicken <[email protected]>
  • Loading branch information
3 people authored and na2na-p committed May 10, 2023
1 parent 79b7a6a commit 212b6ba
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/backend/src/core/activitypub/models/ApNoteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class ApNoteService {
}

@bindThis
public validateNote(object: any, uri: string) {
public validateNote(object: IObject, uri: string) {
const expectHost = this.utilityService.extractDbHost(uri);

if (object == null) {
Expand All @@ -85,9 +85,10 @@ export class ApNoteService {
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)}`);
}

if (object.attributedTo && this.utilityService.extractDbHost(getOneApId(object.attributedTo)) !== expectHost) {
return new Error(`invalid Note: attributedTo has different host. expected: ${expectHost}, actual: ${this.utilityService.extractDbHost(object.attributedTo)}`);

const actualHost = object.attributedTo && this.utilityService.extractDbHost(getOneApId(object.attributedTo));
if (object.attributedTo && actualHost !== expectHost) {
return new Error(`invalid Note: attributedTo has different host. expected: ${expectHost}, actual: ${actualHost}`);
}

return null;
Expand Down

0 comments on commit 212b6ba

Please sign in to comment.