From d66322c2b3210bc0a3b89f1edf595afb0915c39e Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 12:22:34 +0900 Subject: [PATCH 01/97] cleanup(`ApImageService.ts`) --- packages/backend/src/core/activitypub/models/ApImageService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApImageService.ts b/packages/backend/src/core/activitypub/models/ApImageService.ts index 0043907c212f..79c5ae958aa9 100644 --- a/packages/backend/src/core/activitypub/models/ApImageService.ts +++ b/packages/backend/src/core/activitypub/models/ApImageService.ts @@ -32,7 +32,7 @@ export class ApImageService { ) { this.logger = this.apLoggerService.logger; } - + /** * Imageを作成します。 */ From 1abb06d2cc3fab6306c5b380132c35d9abcb2c42 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 12:23:02 +0900 Subject: [PATCH 02/97] refactor(`ApImageService.ts`) --- .../src/core/activitypub/models/ApImageService.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApImageService.ts b/packages/backend/src/core/activitypub/models/ApImageService.ts index 79c5ae958aa9..e0e219244f38 100644 --- a/packages/backend/src/core/activitypub/models/ApImageService.ts +++ b/packages/backend/src/core/activitypub/models/ApImageService.ts @@ -10,9 +10,10 @@ import { DB_MAX_IMAGE_COMMENT_LENGTH } from '@/const.js'; import { DriveService } from '@/core/DriveService.js'; import type Logger from '@/logger.js'; import { bindThis } from '@/decorators.js'; +import { checkHttps } from '@/misc/check-https.js'; import { ApResolverService } from '../ApResolverService.js'; import { ApLoggerService } from '../ApLoggerService.js'; -import { checkHttps } from '@/misc/check-https.js'; +import type { IObject } from '../type.js'; @Injectable() export class ApImageService { @@ -37,18 +38,22 @@ export class ApImageService { * Imageを作成します。 */ @bindThis - public async createImage(actor: RemoteUser, value: any): Promise { + public async createImage(actor: RemoteUser, value: string | IObject): Promise { // 投稿者が凍結されていたらスキップ if (actor.isSuspended) { throw new Error('actor has been suspended'); } - const image = await this.apResolverService.createResolver().resolve(value) as any; + const image = await this.apResolverService.createResolver().resolve(value); if (image.url == null) { throw new Error('invalid image: url not privided'); } + if (typeof image.url !== 'string') { + throw new Error('invalid image: unexpected type of url: ' + JSON.stringify(image.url)); + } + if (!checkHttps(image.url)) { throw new Error('invalid image: unexpected schema of url: ' + image.url); } @@ -63,7 +68,7 @@ export class ApImageService { uri: image.url, sensitive: image.sensitive, isLink: !instance.cacheRemoteFiles, - comment: truncate(image.name, DB_MAX_IMAGE_COMMENT_LENGTH), + comment: truncate(image.name ?? undefined, DB_MAX_IMAGE_COMMENT_LENGTH), }); if (file.isLink) { @@ -89,7 +94,7 @@ export class ApImageService { * リモートサーバーからフェッチしてMisskeyに登録しそれを返します。 */ @bindThis - public async resolveImage(actor: RemoteUser, value: any): Promise { + public async resolveImage(actor: RemoteUser, value: string | IObject): Promise { // TODO // リモートサーバーからフェッチしてきて登録 From 16ffe727ccf337af20da3360bc85314ee2abbdf5 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 11:59:40 +0900 Subject: [PATCH 03/97] cleanup(`check-https.ts`) --- packages/backend/src/misc/check-https.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/misc/check-https.ts b/packages/backend/src/misc/check-https.ts index b33f0199735d..612032fe9756 100644 --- a/packages/backend/src/misc/check-https.ts +++ b/packages/backend/src/misc/check-https.ts @@ -1,4 +1,4 @@ -export function checkHttps(url: string) { - return url.startsWith('https://') || - (url.startsWith('http://') && process.env.NODE_ENV !== 'production'); +export function checkHttps(url: string): boolean { + return url.startsWith('https://') || + (url.startsWith('http://') && process.env.NODE_ENV !== 'production'); } From c9adcfa6fa91da31e5a2eb768549aa3ffccc48aa Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 12:24:14 +0900 Subject: [PATCH 04/97] cleanup(`ApMentionService.ts`) --- .../backend/src/core/activitypub/models/ApMentionService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApMentionService.ts b/packages/backend/src/core/activitypub/models/ApMentionService.ts index c581840ca948..9beefc8fcb10 100644 --- a/packages/backend/src/core/activitypub/models/ApMentionService.ts +++ b/packages/backend/src/core/activitypub/models/ApMentionService.ts @@ -29,10 +29,10 @@ export class ApMentionService { const mentionedUsers = (await Promise.all( hrefs.map(x => limit(() => this.apPersonService.resolvePerson(x, resolver).catch(() => null))), )).filter((x): x is User => x != null); - + return mentionedUsers; } - + @bindThis public extractApMentionObjects(tags: IObject | IObject[] | null | undefined): IApMention[] { if (tags == null) return []; From 9889ad6eb94a4c84230cf5dd38ef9b8f42fd9b61 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 12:24:24 +0900 Subject: [PATCH 05/97] refactor(`ApMentionService.ts`) --- .../backend/src/core/activitypub/models/ApMentionService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApMentionService.ts b/packages/backend/src/core/activitypub/models/ApMentionService.ts index 9beefc8fcb10..62ae3cf93d08 100644 --- a/packages/backend/src/core/activitypub/models/ApMentionService.ts +++ b/packages/backend/src/core/activitypub/models/ApMentionService.ts @@ -22,8 +22,8 @@ export class ApMentionService { } @bindThis - public async extractApMentions(tags: IObject | IObject[] | null | undefined, resolver: Resolver) { - const hrefs = unique(this.extractApMentionObjects(tags).map(x => x.href as string)); + public async extractApMentions(tags: IObject | IObject[] | null | undefined, resolver: Resolver): Promise { + const hrefs = unique(this.extractApMentionObjects(tags).map(x => x.href)); const limit = promiseLimit(2); const mentionedUsers = (await Promise.all( From fb459dee569f9a9f7055f86b49f91c49d4214d14 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 12:15:52 +0900 Subject: [PATCH 06/97] cleanup(`ApNoteService.ts`): unneeded `eslint-disable-next-line` --- packages/backend/src/core/activitypub/models/ApNoteService.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index 76757f530a6d..bad03e84ed41 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -20,7 +20,6 @@ import { UtilityService } from '@/core/UtilityService.js'; import { bindThis } from '@/decorators.js'; import { checkHttps } from '@/misc/check-https.js'; import { getOneApId, getApId, getOneApHrefNullable, validPost, isEmoji, getApType } from '../type.js'; -// eslint-disable-next-line @typescript-eslint/consistent-type-imports import { ApLoggerService } from '../ApLoggerService.js'; import { ApMfmService } from '../ApMfmService.js'; import { ApDbResolverService } from '../ApDbResolverService.js'; From 9dc2e98ef87f194c9890c16d87e84f58f37aaab3 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 12:16:47 +0900 Subject: [PATCH 07/97] cleanup(`ApNoteService.ts`) --- .../core/activitypub/models/ApNoteService.ts | 102 +++++++++--------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index bad03e84ed41..c6e93a0f67b3 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -54,7 +54,7 @@ export class ApNoteService { // 循環参照のため / for circular dependency @Inject(forwardRef(() => ApPersonService)) private apPersonService: ApPersonService, - + private utilityService: UtilityService, private apAudienceService: ApAudienceService, private apMentionService: ApMentionService, @@ -73,15 +73,15 @@ export class ApNoteService { @bindThis public validateNote(object: IObject, uri: string) { const expectHost = this.utilityService.extractDbHost(uri); - + if (object == null) { return new Error('invalid Note: object is null'); } - + if (!validPost.includes(getApType(object))) { return new Error(`invalid Note: invalid object type ${getApType(object)}`); } - + 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)}`); } @@ -90,10 +90,10 @@ export class ApNoteService { if (object.attributedTo && actualHost !== expectHost) { return new Error(`invalid Note: attributedTo has different host. expected: ${expectHost}, actual: ${actualHost}`); } - + return null; } - + /** * Noteをフェッチします。 * @@ -103,16 +103,16 @@ export class ApNoteService { public async fetchNote(object: string | IObject): Promise { return await this.apDbResolverService.getNoteFromApId(object); } - + /** * Noteを作成します。 */ @bindThis public async createNote(value: string | IObject, resolver?: Resolver, silent = false): Promise { if (resolver == null) resolver = this.apResolverService.createResolver(); - + const object = await resolver.resolve(value); - + const entryUri = getApId(value); const err = this.validateNote(object, entryUri); if (err) { @@ -125,9 +125,9 @@ export class ApNoteService { }); throw new Error('invalid note'); } - + const note = object as IPost; - + this.logger.debug(`Note fetched: ${JSON.stringify(note, null, 2)}`); if (note.id && !checkHttps(note.id)) { @@ -139,21 +139,21 @@ export class ApNoteService { if (url && !checkHttps(url)) { throw new Error('unexpected shcema of note url: ' + url); } - + this.logger.info(`Creating the Note: ${note.id}`); - + // 投稿者をフェッチ const actor = await this.apPersonService.resolvePerson(getOneApId(note.attributedTo!), resolver) as RemoteUser; - + // 投稿者が凍結されていたらスキップ if (actor.isSuspended) { throw new Error('actor has been suspended'); } - + const noteAudience = await this.apAudienceService.parseAudience(actor, note.to, note.cc, resolver); let visibility = noteAudience.visibility; const visibleUsers = noteAudience.visibleUsers; - + // Audience (to, cc) が指定されてなかった場合 if (visibility === 'specified' && visibleUsers.length === 0) { if (typeof value === 'string') { // 入力がstringならばresolverでGETが発生している @@ -161,23 +161,23 @@ export class ApNoteService { visibility = 'public'; } } - + const apMentions = await this.apMentionService.extractApMentions(note.tag, resolver); const apHashtags = await extractApHashtags(note.tag); - + // 添付ファイル // TODO: attachmentは必ずしもImageではない // TODO: attachmentは必ずしも配列ではない // Noteがsensitiveなら添付もsensitiveにする const limit = promiseLimit(2); - + note.attachment = Array.isArray(note.attachment) ? note.attachment : note.attachment ? [note.attachment] : []; const files = note.attachment .map(attach => attach.sensitive = note.sensitive) ? (await Promise.all(note.attachment.map(x => limit(() => this.apImageService.resolveImage(actor, x)) as Promise))) .filter(image => image != null) : []; - + // リプライ const reply: Note | null = note.inReplyTo ? await this.resolveNote(note.inReplyTo, resolver).then(x => { @@ -192,10 +192,10 @@ export class ApNoteService { throw err; }) : null; - + // 引用 let quote: Note | undefined | null; - + if (note._misskey_quote || note.quoteUrl) { const tryResolveNote = async (uri: string): Promise<{ status: 'ok'; @@ -222,10 +222,10 @@ export class ApNoteService { }; } }; - + const uris = unique([note._misskey_quote, note.quoteUrl].filter((x): x is string => typeof x === 'string')); const results = await Promise.all(uris.map(uri => tryResolveNote(uri))); - + quote = results.filter((x): x is { status: 'ok', res: Note | null } => x.status === 'ok').map(x => x.res).find(x => x); if (!quote) { if (results.some(x => x.status === 'temperror')) { @@ -233,9 +233,9 @@ export class ApNoteService { } } } - + const cw = note.summary === '' ? null : note.summary; - + // テキストのパース let text: string | null = null; if (note.source?.mediaType === 'text/x.misskeymarkdown' && typeof note.source.content === 'string') { @@ -245,38 +245,38 @@ export class ApNoteService { } else if (typeof note.content === 'string') { text = this.apMfmService.htmlToMfm(note.content, note.tag); } - + // vote if (reply && reply.hasPoll) { const poll = await this.pollsRepository.findOneByOrFail({ noteId: reply.id }); - + const tryCreateVote = async (name: string, index: number): Promise => { if (poll.expiresAt && Date.now() > new Date(poll.expiresAt).getTime()) { this.logger.warn(`vote to expired poll from AP: actor=${actor.username}@${actor.host}, note=${note.id}, choice=${name}`); } else if (index >= 0) { this.logger.info(`vote from AP: actor=${actor.username}@${actor.host}, note=${note.id}, choice=${name}`); await this.pollService.vote(actor, reply, index); - + // リモートフォロワーにUpdate配信 this.pollService.deliverQuestionUpdate(reply.id); } return null; }; - + if (note.name) { return await tryCreateVote(note.name, poll.choices.findIndex(x => x === note.name)); } } - + const emojis = await this.extractEmojis(note.tag ?? [], actor.host).catch(e => { this.logger.info(`extractEmojis: ${e}`); return [] as Emoji[]; }); - + const apEmojis = emojis.map(emoji => emoji.name); - + const poll = await this.apQuestionService.extractPollFromQuestion(note, resolver).catch(() => undefined); - + return await this.noteCreateService.create(actor, { createdAt: note.published ? new Date(note.published) : null, files, @@ -296,7 +296,7 @@ export class ApNoteService { url: url, }, silent); } - + /** * Noteを解決します。 * @@ -307,26 +307,26 @@ export class ApNoteService { public async resolveNote(value: string | IObject, resolver?: Resolver): Promise { const uri = typeof value === 'string' ? value : value.id; if (uri == null) throw new Error('missing uri'); - + // ブロックしてたら中断 const meta = await this.metaService.fetch(); if (this.utilityService.isBlockedHost(meta.blockedHosts, this.utilityService.extractDbHost(uri))) throw new StatusError('blocked host', 451); - + const unlock = await this.appLockService.getApLock(uri); - + try { //#region このサーバーに既に登録されていたらそれを返す const exist = await this.fetchNote(uri); - + if (exist) { return exist; } //#endregion - + if (uri.startsWith(this.config.url)) { throw new StatusError('cannot resolve local note', 400, 'cannot resolve local note'); } - + // リモートサーバーからフェッチしてきて登録 // ここでuriの代わりに添付されてきたNote Objectが指定されていると、サーバーフェッチを経ずにノートが生成されるが // 添付されてきたNote Objectは偽装されている可能性があるため、常にuriを指定してサーバーフェッチを行う。 @@ -335,26 +335,26 @@ export class ApNoteService { unlock(); } } - + @bindThis public async extractEmojis(tags: IObject | IObject[], host: string): Promise { host = this.utilityService.toPuny(host); - + if (!tags) return []; - + const eomjiTags = toArray(tags).filter(isEmoji); const existingEmojis = await this.emojisRepository.findBy({ host, name: In(eomjiTags.map(tag => tag.name!.replaceAll(':', ''))), }); - + return await Promise.all(eomjiTags.map(async tag => { const name = tag.name!.replaceAll(':', ''); tag.icon = toSingle(tag.icon); - + const exists = existingEmojis.find(x => x.name === name); - + if (exists) { if ((tag.updated != null && exists.updatedAt == null) || (tag.id != null && exists.uri == null) @@ -370,18 +370,18 @@ export class ApNoteService { publicUrl: tag.icon!.url, updatedAt: new Date(), }); - + return await this.emojisRepository.findOneBy({ host, name, }) as Emoji; } - + return exists; } - + this.logger.info(`register emoji host=${host}, name=${name}`); - + return await this.emojisRepository.insert({ id: this.idService.genId(), host, From aeefb843a8a688f8a356794e8981c58f8a2733af Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 13:30:12 +0900 Subject: [PATCH 08/97] =?UTF-8?q?WIP(`ApImageService.ts`):=20`image.url`?= =?UTF-8?q?=E3=82=92`getApHrefNullable()`=E3=81=AB=E9=80=9A=E3=81=99?= =?UTF-8?q?=E3=81=8B=E3=81=A9=E3=81=86=E3=81=8B=E6=82=A9=E3=82=93=E3=81=A7?= =?UTF-8?q?=E3=81=84=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/core/activitypub/models/ApImageService.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/backend/src/core/activitypub/models/ApImageService.ts b/packages/backend/src/core/activitypub/models/ApImageService.ts index e0e219244f38..b563f2c35f5f 100644 --- a/packages/backend/src/core/activitypub/models/ApImageService.ts +++ b/packages/backend/src/core/activitypub/models/ApImageService.ts @@ -50,6 +50,8 @@ export class ApImageService { throw new Error('invalid image: url not privided'); } + // TODO? + // const url = getOneApHrefNullable(image.url); if (typeof image.url !== 'string') { throw new Error('invalid image: unexpected type of url: ' + JSON.stringify(image.url)); } From 1246382de4c7aa702137a653eaad76d6b0beac26 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 13:35:55 +0900 Subject: [PATCH 09/97] refactor(`ApNoteService.ts`): function return type --- packages/backend/src/core/activitypub/models/ApNoteService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index c6e93a0f67b3..b93e6e245e1e 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -71,7 +71,7 @@ export class ApNoteService { } @bindThis - public validateNote(object: IObject, uri: string) { + public validateNote(object: IObject, uri: string): Error | null { const expectHost = this.utilityService.extractDbHost(uri); if (object == null) { From b203dab85278dadcd386a97318c246f96c4aef98 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 13:36:23 +0900 Subject: [PATCH 10/97] cleanup(`ApNoteService.ts`): deadcode --- packages/backend/src/core/activitypub/models/ApNoteService.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index b93e6e245e1e..38a097f6076d 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -74,10 +74,6 @@ export class ApNoteService { public validateNote(object: IObject, uri: string): Error | null { const expectHost = this.utilityService.extractDbHost(uri); - if (object == null) { - return new Error('invalid Note: object is null'); - } - if (!validPost.includes(getApType(object))) { return new Error(`invalid Note: invalid object type ${getApType(object)}`); } From acce210f7dcad858407dcbd594df952c2a207bae Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 13:38:29 +0900 Subject: [PATCH 11/97] refactor(`ApNoteService.ts`): `eslint-disable-next-line` --- packages/backend/src/core/activitypub/models/ApNoteService.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index 38a097f6076d..de9f97784004 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -105,6 +105,7 @@ export class ApNoteService { */ @bindThis public async createNote(value: string | IObject, resolver?: Resolver, silent = false): Promise { + // eslint-disable-next-line no-param-reassign if (resolver == null) resolver = this.apResolverService.createResolver(); const object = await resolver.resolve(value); From 47a07d37f3c89a04e4209063a20035540dff9a90 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 13:39:13 +0900 Subject: [PATCH 12/97] refactor(`ApNoteService.ts`): non-null assertion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit これまでは`getApId()`の方でエラーがスローされていた。 --- .../backend/src/core/activitypub/models/ApNoteService.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index de9f97784004..b82e577dfd0e 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -140,7 +140,11 @@ export class ApNoteService { this.logger.info(`Creating the Note: ${note.id}`); // 投稿者をフェッチ - const actor = await this.apPersonService.resolvePerson(getOneApId(note.attributedTo!), resolver) as RemoteUser; + if (note.attributedTo == null) { + throw new Error('invalid note.attributedTo: ' + note.attributedTo); + } + + const actor = await this.apPersonService.resolvePerson(getOneApId(note.attributedTo), resolver) as RemoteUser; // 投稿者が凍結されていたらスキップ if (actor.isSuspended) { From 370c1fb12ac4dff94e2bab1197b68aad9c34d738 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 13:41:54 +0900 Subject: [PATCH 13/97] cleanup(`ApNoteService.ts`): unneeded await --- packages/backend/src/core/activitypub/models/ApNoteService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index b82e577dfd0e..4d80f05fa1d3 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -164,7 +164,7 @@ export class ApNoteService { } const apMentions = await this.apMentionService.extractApMentions(note.tag, resolver); - const apHashtags = await extractApHashtags(note.tag); + const apHashtags = extractApHashtags(note.tag); // 添付ファイル // TODO: attachmentは必ずしもImageではない From dc291c593f755f2e926bb6d0ad4c714ab284f9f4 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 13:43:32 +0900 Subject: [PATCH 14/97] refactor(`ApNoteService.ts`): note.attachment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `toArray()`を使うように - よくわからない条件式を整理 - `as`をなくすために`promiseLimit()`でジェネリクスを使うように --- .../src/core/activitypub/models/ApNoteService.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index 4d80f05fa1d3..9c543bf92900 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -170,14 +170,11 @@ export class ApNoteService { // TODO: attachmentは必ずしもImageではない // TODO: attachmentは必ずしも配列ではない // Noteがsensitiveなら添付もsensitiveにする - const limit = promiseLimit(2); - - note.attachment = Array.isArray(note.attachment) ? note.attachment : note.attachment ? [note.attachment] : []; - const files = note.attachment - .map(attach => attach.sensitive = note.sensitive) - ? (await Promise.all(note.attachment.map(x => limit(() => this.apImageService.resolveImage(actor, x)) as Promise))) - .filter(image => image != null) - : []; + const limit = promiseLimit(2); + + note.attachment = toArray(note.attachment); + note.attachment.forEach(attach => attach.sensitive = note.sensitive); + const files = (await Promise.all(note.attachment.map(x => limit(() => this.apImageService.resolveImage(actor, x))))); // リプライ const reply: Note | null = note.inReplyTo From 1af9392914d2090fe1f3725f9ebec1a5752f69e3 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 13:50:06 +0900 Subject: [PATCH 15/97] cleanup(`ApNoteService.ts`) --- .../core/activitypub/models/ApNoteService.ts | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index 9c543bf92900..f5df823d21f6 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -178,17 +178,19 @@ export class ApNoteService { // リプライ const reply: Note | null = note.inReplyTo - ? await this.resolveNote(note.inReplyTo, resolver).then(x => { - if (x == null) { - this.logger.warn('Specified inReplyTo, but not found'); - throw new Error('inReplyTo not found'); - } else { + ? await this.resolveNote(note.inReplyTo, resolver) + .then(x => { + if (x == null) { + this.logger.warn('Specified inReplyTo, but not found'); + throw new Error('inReplyTo not found'); + } + return x; - } - }).catch(async err => { - this.logger.warn(`Error in inReplyTo ${note.inReplyTo} - ${err.statusCode ?? err}`); - throw err; - }) + }) + .catch(async err => { + this.logger.warn(`Error in inReplyTo ${note.inReplyTo} - ${err.statusCode ?? err}`); + throw err; + }) : null; // 引用 From c234f3afe195650385963cccb912d4c364a81849 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 13:56:13 +0900 Subject: [PATCH 16/97] =?UTF-8?q?refactor(`ApNoteService.ts`):=20=E3=82=88?= =?UTF-8?q?=E3=82=8A=E3=82=88=E3=81=84=E5=9E=8B=E5=AE=9A=E7=BE=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `res`が`null`でないことは確認されているようだったので`null`とのunionはなくした --- .../src/core/activitypub/models/ApNoteService.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index f5df823d21f6..acfab3aadc20 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -197,12 +197,10 @@ export class ApNoteService { let quote: Note | undefined | null; if (note._misskey_quote || note.quoteUrl) { - const tryResolveNote = async (uri: string): Promise<{ - status: 'ok'; - res: Note | null; - } | { - status: 'permerror' | 'temperror'; - }> => { + const tryResolveNote = async (uri: string): Promise< + | { status: 'ok'; res: Note } + | { status: 'permerror' | 'temperror' } + > => { if (typeof uri !== 'string' || !uri.match(/^https?:/)) return { status: 'permerror' }; try { const res = await this.resolveNote(uri); @@ -226,7 +224,7 @@ export class ApNoteService { const uris = unique([note._misskey_quote, note.quoteUrl].filter((x): x is string => typeof x === 'string')); const results = await Promise.all(uris.map(uri => tryResolveNote(uri))); - quote = results.filter((x): x is { status: 'ok', res: Note | null } => x.status === 'ok').map(x => x.res).find(x => x); + quote = results.filter((x): x is { status: 'ok', res: Note } => x.status === 'ok').map(x => x.res).at(0); if (!quote) { if (results.some(x => x.status === 'temperror')) { throw new Error('quote resolve failed'); From ad7b4e2527236ee3760c301f5d61317e1bd6ded6 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 13:58:11 +0900 Subject: [PATCH 17/97] =?UTF-8?q?refactor(`ApNoteService.ts`):=20=E4=B8=8D?= =?UTF-8?q?=E8=A6=81=E3=81=AA=E6=9D=A1=E4=BB=B6=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/core/activitypub/models/ApNoteService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index acfab3aadc20..2c8d04e4806c 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -201,7 +201,7 @@ export class ApNoteService { | { status: 'ok'; res: Note } | { status: 'permerror' | 'temperror' } > => { - if (typeof uri !== 'string' || !uri.match(/^https?:/)) return { status: 'permerror' }; + if (!uri.match(/^https?:/)) return { status: 'permerror' }; try { const res = await this.resolveNote(uri); if (res) { From 688ad27d080e7a61bf9c93ee18129ae2ca74874e Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 13:58:40 +0900 Subject: [PATCH 18/97] cleanup(`ApNoteService.ts`) --- .../src/core/activitypub/models/ApNoteService.ts | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index 2c8d04e4806c..413eb52f3ebe 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -204,16 +204,8 @@ export class ApNoteService { if (!uri.match(/^https?:/)) return { status: 'permerror' }; try { const res = await this.resolveNote(uri); - if (res) { - return { - status: 'ok', - res, - }; - } else { - return { - status: 'permerror', - }; - } + if (res == null) return { status: 'permerror' }; + return { status: 'ok', res }; } catch (e) { return { status: (e instanceof StatusError && e.isClientError) ? 'permerror' : 'temperror', From c2b184b085962424621d878281c4916c7e10240b Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 14:01:36 +0900 Subject: [PATCH 19/97] =?UTF-8?q?cleanup(`ApNoteService.ts`):=20=E9=87=8D?= =?UTF-8?q?=E8=A6=81=E3=81=A7=E3=81=AA=E3=81=84`as`=E3=82=92=E5=89=8A?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/core/activitypub/models/ApNoteService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index 413eb52f3ebe..f8e31eb99e8a 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -260,7 +260,7 @@ export class ApNoteService { const emojis = await this.extractEmojis(note.tag ?? [], actor.host).catch(e => { this.logger.info(`extractEmojis: ${e}`); - return [] as Emoji[]; + return []; }); const apEmojis = emojis.map(emoji => emoji.name); From 394678e44474abfdb30093c3460508afaae6aba8 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 14:07:32 +0900 Subject: [PATCH 20/97] refactor(`ApNoteService.ts`): `eslint-disable-next-line` --- packages/backend/src/core/activitypub/models/ApNoteService.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index f8e31eb99e8a..aa99d717a4c2 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -328,6 +328,7 @@ export class ApNoteService { @bindThis public async extractEmojis(tags: IObject | IObject[], host: string): Promise { + // eslint-disable-next-line no-param-reassign host = this.utilityService.toPuny(host); if (!tags) return []; From c788cbb195e308b60f2c2ba1a1539b2410744b8d Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 14:07:47 +0900 Subject: [PATCH 21/97] cleanup(`ApNoteService.ts`): deadcode --- packages/backend/src/core/activitypub/models/ApNoteService.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index aa99d717a4c2..478c6f9a77e6 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -331,8 +331,6 @@ export class ApNoteService { // eslint-disable-next-line no-param-reassign host = this.utilityService.toPuny(host); - if (!tags) return []; - const eomjiTags = toArray(tags).filter(isEmoji); const existingEmojis = await this.emojisRepository.findBy({ From ad92cb607a64e1919ef1d0029b2fbbbace26978e Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 14:08:45 +0900 Subject: [PATCH 22/97] cleanup(`ApNoteService.ts`): unneeded non-null assertion --- packages/backend/src/core/activitypub/models/ApNoteService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index 478c6f9a77e6..1cdd92655d21 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -335,11 +335,11 @@ export class ApNoteService { const existingEmojis = await this.emojisRepository.findBy({ host, - name: In(eomjiTags.map(tag => tag.name!.replaceAll(':', ''))), + name: In(eomjiTags.map(tag => tag.name.replaceAll(':', ''))), }); return await Promise.all(eomjiTags.map(async tag => { - const name = tag.name!.replaceAll(':', ''); + const name = tag.name.replaceAll(':', ''); tag.icon = toSingle(tag.icon); const exists = existingEmojis.find(x => x.name === name); From a24e709a06af6cde8b5ba9d7a32d73873a5eeb7d Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 14:09:53 +0900 Subject: [PATCH 23/97] =?UTF-8?q?refactor(`ApNoteService.ts`):=20=E4=B8=8D?= =?UTF-8?q?=E8=A6=81=E3=81=AA=E6=9D=A1=E4=BB=B6=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/core/activitypub/models/ApNoteService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index 1cdd92655d21..3a54aec536c0 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -345,9 +345,9 @@ export class ApNoteService { const exists = existingEmojis.find(x => x.name === name); if (exists) { - if ((tag.updated != null && exists.updatedAt == null) + if ((exists.updatedAt == null) || (tag.id != null && exists.uri == null) - || (tag.updated != null && exists.updatedAt != null && new Date(tag.updated) > exists.updatedAt) + || (new Date(tag.updated) > exists.updatedAt) || (tag.icon!.url !== exists.originalUrl) ) { await this.emojisRepository.update({ From f688d7a933d3f88a5d8e16bfc5770df839f12042 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 14:11:27 +0900 Subject: [PATCH 24/97] =?UTF-8?q?WIP(`ApNoteService.ts`):=20`as`=E3=82=92?= =?UTF-8?q?=E3=81=AA=E3=81=8F=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit エラーメッセージを考える --- .../backend/src/core/activitypub/models/ApNoteService.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index 3a54aec536c0..0d50adbf3011 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -360,10 +360,9 @@ export class ApNoteService { updatedAt: new Date(), }); - return await this.emojisRepository.findOneBy({ - host, - name, - }) as Emoji; + const emoji = await this.emojisRepository.findOneBy({ host, name }); + if (emoji == null) throw new Error(''); // TODO + return emoji; } return exists; From 8b3641eabef6fd513f0d1f8cbc3350c4a41a22c5 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 14:11:51 +0900 Subject: [PATCH 25/97] =?UTF-8?q?cleanup(`ApNoteService.ts`):=20=E4=B8=8D?= =?UTF-8?q?=E8=A6=81=E3=81=AA`as`=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/core/activitypub/models/ApNoteService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index 0d50adbf3011..f82e41a2cd26 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -379,7 +379,7 @@ export class ApNoteService { publicUrl: tag.icon!.url, updatedAt: new Date(), aliases: [], - } as Partial).then(x => this.emojisRepository.findOneByOrFail(x.identifiers[0])); + }).then(x => this.emojisRepository.findOneByOrFail(x.identifiers[0])); })); } } From 3c17a9b07d6d21d7364f22c7795cfe3adac3eab4 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 18:07:27 +0900 Subject: [PATCH 26/97] cleanup(`ApPersonService.ts`): `no-unused-vars` --- packages/backend/src/core/activitypub/models/ApPersonService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index f52ebed10753..da1ab9d742f8 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -3,7 +3,7 @@ import promiseLimit from 'promise-limit'; import { DataSource } from 'typeorm'; import { ModuleRef } from '@nestjs/core'; import { DI } from '@/di-symbols.js'; -import type { BlockingsRepository, MutingsRepository, FollowingsRepository, InstancesRepository, UserProfilesRepository, UserPublickeysRepository, UsersRepository } from '@/models/index.js'; +import type { FollowingsRepository, InstancesRepository, UserProfilesRepository, UserPublickeysRepository, UsersRepository } from '@/models/index.js'; import type { Config } from '@/config.js'; import type { LocalUser, RemoteUser } from '@/models/entities/User.js'; import { User } from '@/models/entities/User.js'; From 58abc86def713ff6b1ac22537615f3f7bf09e48b Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 18:07:56 +0900 Subject: [PATCH 27/97] cleanup(`ApPersonService.ts`): deadcode --- .../core/activitypub/models/ApPersonService.ts | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index da1ab9d742f8..37f5fc3d3485 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -94,24 +94,6 @@ export class ApPersonService implements OnModuleInit { @Inject(DI.followingsRepository) private followingsRepository: FollowingsRepository, - - //private utilityService: UtilityService, - //private userEntityService: UserEntityService, - //private idService: IdService, - //private globalEventService: GlobalEventService, - //private metaService: MetaService, - //private federatedInstanceService: FederatedInstanceService, - //private fetchInstanceMetadataService: FetchInstanceMetadataService, - //private cacheService: CacheService, - //private apResolverService: ApResolverService, - //private apNoteService: ApNoteService, - //private apImageService: ApImageService, - //private apMfmService: ApMfmService, - //private mfmService: MfmService, - //private hashtagService: HashtagService, - //private usersChart: UsersChart, - //private instanceChart: InstanceChart, - //private apLoggerService: ApLoggerService, ) { } From d3e23d98751639b207969c849f6aab84d9e48055 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 18:08:23 +0900 Subject: [PATCH 28/97] refactor(`ApPersonService.ts`): function return type --- packages/backend/src/core/activitypub/models/ApPersonService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 37f5fc3d3485..d40f26430005 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -97,7 +97,7 @@ export class ApPersonService implements OnModuleInit { ) { } - onModuleInit() { + onModuleInit(): void { this.utilityService = this.moduleRef.get('UtilityService'); this.userEntityService = this.moduleRef.get('UserEntityService'); this.driveFileEntityService = this.moduleRef.get('DriveFileEntityService'); From c7fd197efc5385756ec73ce7aa0b62cb3d962906 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 18:08:47 +0900 Subject: [PATCH 29/97] cleanup(`ApPersonService.ts`): deadcode --- .../backend/src/core/activitypub/models/ApPersonService.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index d40f26430005..5bc573932edb 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -135,10 +135,6 @@ export class ApPersonService implements OnModuleInit { private validateActor(x: IObject, uri: string): IActor { const expectHost = this.punyHost(uri); - if (x == null) { - throw new Error('invalid Actor: object is null'); - } - if (!isActor(x)) { throw new Error(`invalid Actor type '${x.type}'`); } From 50955427f6016e01fcece2932e0d342d16cdccb5 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 18:09:29 +0900 Subject: [PATCH 30/97] cleanup(`ApPersonService.ts`): deadcode --- packages/backend/src/core/activitypub/models/ApPersonService.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 5bc573932edb..886daf451800 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -196,8 +196,6 @@ export class ApPersonService implements OnModuleInit { */ @bindThis public async fetchPerson(uri: string): Promise { - if (typeof uri !== 'string') throw new Error('uri is not string'); - const cached = this.cacheService.uriPersonCache.get(uri) as LocalUser | RemoteUser | null; if (cached) return cached; From 39ad3da62d16fad830a862d89f6498d05c672c0c Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 18:20:18 +0900 Subject: [PATCH 31/97] =?UTF-8?q?WIP(`ApPersonService.ts`):=20`as`?= =?UTF-8?q?=E3=82=92=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `null`でないか確認する処理が続いていたので型アサーションは`null`とのunionにした。 より本質的な改善の余地があるように感じるのでひとまずWIPとしてコミット。 --- .../backend/src/core/activitypub/models/ApPersonService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 886daf451800..3d4afbb26d24 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -202,13 +202,13 @@ export class ApPersonService implements OnModuleInit { // URIがこのサーバーを指しているならデータベースからフェッチ if (uri.startsWith(`${this.config.url}/`)) { const id = uri.split('/').pop(); - const u = await this.usersRepository.findOneBy({ id }) as LocalUser; + const u = await this.usersRepository.findOneBy({ id }) as LocalUser | null; if (u) this.cacheService.uriPersonCache.set(uri, u); return u; } //#region このサーバーに既に登録されていたらそれを返す - const exist = await this.usersRepository.findOneBy({ uri }) as LocalUser | RemoteUser; + const exist = await this.usersRepository.findOneBy({ uri }) as LocalUser | RemoteUser | null; if (exist) { this.cacheService.uriPersonCache.set(uri, exist); From 44a1b6d5c033f571811dcd62eafa4c55cd2c6763 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 18:20:44 +0900 Subject: [PATCH 32/97] refactor(`ApPersonService.ts`): `eslint-disable-next-line` --- packages/backend/src/core/activitypub/models/ApPersonService.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 3d4afbb26d24..533e9d49995b 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -230,6 +230,7 @@ export class ApPersonService implements OnModuleInit { throw new StatusError('cannot resolve local user', 400, 'cannot resolve local user'); } + // eslint-disable-next-line no-param-reassign if (resolver == null) resolver = this.apResolverService.createResolver(); const object = await resolver.resolve(uri) as any; From b1ecaecf409c101f50c984100e1eea550385af9d Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 18:34:52 +0900 Subject: [PATCH 33/97] =?UTF-8?q?WIP(`ApPersonService.ts`):=20`as=20any`?= =?UTF-8?q?=E3=82=92=E3=81=AA=E3=81=8F=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit エラーをスローするようにせざるを得なかったのでエラーメッセージを考える必要がある。 --- .../backend/src/core/activitypub/models/ApPersonService.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 533e9d49995b..f366364bfd43 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -233,7 +233,8 @@ export class ApPersonService implements OnModuleInit { // eslint-disable-next-line no-param-reassign if (resolver == null) resolver = this.apResolverService.createResolver(); - const object = await resolver.resolve(uri) as any; + const object = await resolver.resolve(uri); + if (object.id == null) throw new Error(''); // TODO const person = this.validateActor(object, uri); From 71ca66e24e687fb7d7d1e9cf6c72ce69608c2354 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 19:05:23 +0900 Subject: [PATCH 34/97] WIP(`ApNoteService.ts`): non-null assertion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit non-nullアサーションを減らすために事前に存在確認をするようにした。 エラーをスローするようにしたのでメッセージを考えなければならない。 --- .../activitypub/models/ApPersonService.ts | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index f366364bfd43..1ab502b3b2c0 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -257,7 +257,7 @@ export class ApPersonService implements OnModuleInit { } // Create user - let user: RemoteUser; + let user: RemoteUser | null = null; try { // Start transaction await this.db.transaction(async transactionalEntityManager => { @@ -323,6 +323,8 @@ export class ApPersonService implements OnModuleInit { } } + if (user == null) throw new Error(''); // TODO + // Register host this.federatedInstanceService.fetch(host).then(async i => { this.instancesRepository.increment({ id: i.id }, 'usersCount', 1); @@ -332,10 +334,10 @@ export class ApPersonService implements OnModuleInit { } }); - this.usersChart.update(user!, true); + this.usersChart.update(user, true); // ハッシュタグ更新 - this.hashtagService.updateUsertags(user!, tags); + this.hashtagService.updateUsertags(user, tags); //#region アバターとヘッダー画像をフェッチ const [avatar, banner] = await Promise.all([ @@ -354,7 +356,7 @@ export class ApPersonService implements OnModuleInit { const avatarBlurhash = avatar ? avatar.blurhash : null; const bannerBlurhash = banner ? banner.blurhash : null; - await this.usersRepository.update(user!.id, { + await this.usersRepository.update(user.id, { avatarId, bannerId, avatarUrl, @@ -363,12 +365,12 @@ export class ApPersonService implements OnModuleInit { bannerBlurhash, }); - user!.avatarId = avatarId; - user!.bannerId = bannerId; - user!.avatarUrl = avatarUrl; - user!.bannerUrl = bannerUrl; - user!.avatarBlurhash = avatarBlurhash; - user!.bannerBlurhash = bannerBlurhash; + user.avatarId = avatarId; + user.bannerId = bannerId; + user.avatarUrl = avatarUrl; + user.bannerUrl = bannerUrl; + user.avatarBlurhash = avatarBlurhash; + user.bannerBlurhash = bannerBlurhash; //#endregion //#region カスタム絵文字取得 @@ -379,14 +381,12 @@ export class ApPersonService implements OnModuleInit { const emojiNames = emojis.map(emoji => emoji.name); - await this.usersRepository.update(user!.id, { - emojis: emojiNames, - }); + await this.usersRepository.update(user.id, { emojis: emojiNames }); //#endregion - await this.updateFeatured(user!.id, resolver).catch(err => this.logger.error(err)); + await this.updateFeatured(user.id, resolver).catch(err => this.logger.error(err)); - return user!; + return user; } /** From 8ee31e8002c28d48e89dd085282489483b4ac76f Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 19:06:24 +0900 Subject: [PATCH 35/97] refactor(`ApNoteService.ts`): non-null assertion -> optional chaining --- packages/backend/src/core/activitypub/models/ApPersonService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 1ab502b3b2c0..05c486d3a871 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -274,7 +274,7 @@ export class ApPersonService implements OnModuleInit { alsoKnownAs: person.alsoKnownAs, isExplorable: !!person.discoverable, username: person.preferredUsername, - usernameLower: person.preferredUsername!.toLowerCase(), + usernameLower: person.preferredUsername?.toLowerCase(), host, inbox: person.inbox, sharedInbox: person.sharedInbox ?? (person.endpoints ? person.endpoints.sharedInbox : undefined), From be415a96f9502b06c7a3be1b1b58ebb368795882 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 19:07:15 +0900 Subject: [PATCH 36/97] refactor(`ApPersonService.ts`): `eslint-disable-next-line` --- packages/backend/src/core/activitypub/models/ApPersonService.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 05c486d3a871..b496fe1b38cc 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -416,6 +416,7 @@ export class ApPersonService implements OnModuleInit { } //#endregion + // eslint-disable-next-line no-param-reassign if (resolver == null) resolver = this.apResolverService.createResolver(); const object = hint ?? await resolver.resolve(uri); From 45357286250877db44f498e84e9daf23e7514dbe Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 19:08:06 +0900 Subject: [PATCH 37/97] refactor(`ApPersonService.ts`): `eslint-disable-next-line` --- packages/backend/src/core/activitypub/models/ApPersonService.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index b496fe1b38cc..2161f6fc9c64 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -570,6 +570,7 @@ export class ApPersonService implements OnModuleInit { //#endregion // リモートサーバーからフェッチしてきて登録 + // eslint-disable-next-line no-param-reassign if (resolver == null) resolver = this.apResolverService.createResolver(); return await this.createPerson(uri, resolver); } From a40ea8163ee2521eb0172dec084b2de2d25bddd0 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 19:08:41 +0900 Subject: [PATCH 38/97] refactor(`ApPersonService.ts`): function return type --- packages/backend/src/core/activitypub/models/ApPersonService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 2161f6fc9c64..32e007703770 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -594,7 +594,7 @@ export class ApPersonService implements OnModuleInit { } @bindThis - public async updateFeatured(userId: User['id'], resolver?: Resolver) { + public async updateFeatured(userId: User['id'], resolver?: Resolver): Promise { const user = await this.usersRepository.findOneByOrFail({ id: userId }); if (!this.userEntityService.isRemoteUser(user)) return; if (!user.featured) return; From d276dabf26061fa6d4b8b6abfc99925da57bf874 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 19:11:00 +0900 Subject: [PATCH 39/97] =?UTF-8?q?refactor(`ApPersonService.ts`):=20type=20?= =?UTF-8?q?guard=E3=81=AB=E3=82=88=E3=82=8Bnon-null=20assertion=E3=81=AE?= =?UTF-8?q?=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/src/core/activitypub/models/ApPersonService.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 32e007703770..43a2142120be 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -623,13 +623,13 @@ export class ApPersonService implements OnModuleInit { // とりあえずidを別の時間で生成して順番を維持 let td = 0; - for (const note of featuredNotes.filter(note => note != null)) { + for (const note of featuredNotes.filter((note): note is Note => note != null)) { td -= 1000; transactionalEntityManager.insert(UserNotePining, { id: this.idService.genId(new Date(Date.now() + td)), createdAt: new Date(), userId: user.id, - noteId: note!.id, + noteId: note.id, }); } }); From 785a5f6f68565037223f4e796ccc4a79fd4c56c1 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sun, 2 Jul 2023 19:15:45 +0900 Subject: [PATCH 40/97] WIP(`ApPersonService.ts`): `analyzeAttachments` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Field型を事前に定義しておくように - `attachments`が`IObject`だった場合、返り値が`{ fields: [] }`になるようだが構わないのか? - `toArray()`を通すべきでは? --- .../src/core/activitypub/models/ApPersonService.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 43a2142120be..fae4ffbac31c 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -48,6 +48,8 @@ import type { IActor, IObject } from '../type.js'; const nameLength = 128; const summaryLength = 2048; +type Field = Record<'name' | 'value', string>; + @Injectable() export class ApPersonService implements OnModuleInit { private utilityService: UtilityService; @@ -576,11 +578,10 @@ export class ApPersonService implements OnModuleInit { } @bindThis - public analyzeAttachments(attachments: IObject | IObject[] | undefined) { - const fields: { - name: string, - value: string - }[] = []; + // TODO: `attachments`が`IObject`だった場合、返り値が`{ fields: [] }`になるようだが構わないのか? + public analyzeAttachments(attachments: IObject | IObject[] | undefined): { fields: Field[] } { + const fields: Field[] = []; + if (Array.isArray(attachments)) { for (const attachment of attachments.filter(isPropertyValue)) { fields.push({ From 41fe1b6b1f7db4cde9ccc80ebb1fec3608249785 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 05:39:07 +0900 Subject: [PATCH 41/97] =?UTF-8?q?Revert=20"WIP(`ApImageService.ts`):=20`im?= =?UTF-8?q?age.url`=E3=82=92`getApHrefNullable()`=E3=81=AB=E9=80=9A?= =?UTF-8?q?=E3=81=99=E3=81=8B=E3=81=A9=E3=81=86=E3=81=8B=E6=82=A9=E3=82=93?= =?UTF-8?q?=E3=81=A7=E3=81=84=E3=82=8B"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit aeefb843a8a688f8a356794e8981c58f8a2733af. --- packages/backend/src/core/activitypub/models/ApImageService.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApImageService.ts b/packages/backend/src/core/activitypub/models/ApImageService.ts index b563f2c35f5f..e0e219244f38 100644 --- a/packages/backend/src/core/activitypub/models/ApImageService.ts +++ b/packages/backend/src/core/activitypub/models/ApImageService.ts @@ -50,8 +50,6 @@ export class ApImageService { throw new Error('invalid image: url not privided'); } - // TODO? - // const url = getOneApHrefNullable(image.url); if (typeof image.url !== 'string') { throw new Error('invalid image: unexpected type of url: ' + JSON.stringify(image.url)); } From 1454d04c377eaf46013b0f3c3ce664a4034fd53a Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 05:40:12 +0900 Subject: [PATCH 42/97] cleanup(`ApImageService.ts`): `import` --- .../core/activitypub/models/ApImageService.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApImageService.ts b/packages/backend/src/core/activitypub/models/ApImageService.ts index e0e219244f38..f7b716a411d9 100644 --- a/packages/backend/src/core/activitypub/models/ApImageService.ts +++ b/packages/backend/src/core/activitypub/models/ApImageService.ts @@ -1,19 +1,19 @@ import { Inject, Injectable } from '@nestjs/common'; -import { DI } from '@/di-symbols.js'; import type { DriveFilesRepository } from '@/models/index.js'; -import type { Config } from '@/config.js'; import type { RemoteUser } from '@/models/entities/User.js'; import type { DriveFile } from '@/models/entities/DriveFile.js'; -import { MetaService } from '@/core/MetaService.js'; import { truncate } from '@/misc/truncate.js'; -import { DB_MAX_IMAGE_COMMENT_LENGTH } from '@/const.js'; -import { DriveService } from '@/core/DriveService.js'; +import { checkHttps } from '@/misc/check-https.js'; import type Logger from '@/logger.js'; +import { DI } from '@/di-symbols.js'; import { bindThis } from '@/decorators.js'; -import { checkHttps } from '@/misc/check-https.js'; -import { ApResolverService } from '../ApResolverService.js'; -import { ApLoggerService } from '../ApLoggerService.js'; +import type { MetaService } from '@/core/MetaService.js'; +import type { DriveService } from '@/core/DriveService.js'; +import { DB_MAX_IMAGE_COMMENT_LENGTH } from '@/const.js'; +import type { Config } from '@/config.js'; import type { IObject } from '../type.js'; +import type { ApResolverService } from '../ApResolverService.js'; +import type { ApLoggerService } from '../ApLoggerService.js'; @Injectable() export class ApImageService { From 67f9d9db4cf298dc26584c521755d295f938567e Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 05:41:51 +0900 Subject: [PATCH 43/97] =?UTF-8?q?refactor(`ApImageService.ts`):=20?= =?UTF-8?q?=E5=86=97=E9=95=B7=E3=81=A0=E3=81=A3=E3=81=9F=E9=83=A8=E5=88=86?= =?UTF-8?q?=E3=82=92=E7=9F=AD=E3=81=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/activitypub/models/ApImageService.ts | 20 +++++-------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApImageService.ts b/packages/backend/src/core/activitypub/models/ApImageService.ts index f7b716a411d9..0476e845eda9 100644 --- a/packages/backend/src/core/activitypub/models/ApImageService.ts +++ b/packages/backend/src/core/activitypub/models/ApImageService.ts @@ -62,7 +62,7 @@ export class ApImageService { const instance = await this.metaService.fetch(); - let file = await this.driveService.uploadFromUrl({ + const file = await this.driveService.uploadFromUrl({ url: image.url, user: actor, uri: image.url, @@ -70,21 +70,11 @@ export class ApImageService { isLink: !instance.cacheRemoteFiles, comment: truncate(image.name ?? undefined, DB_MAX_IMAGE_COMMENT_LENGTH), }); + if (!file.isLink || file.url === image.url) return file; - if (file.isLink) { - // URLが異なっている場合、同じ画像が以前に異なるURLで登録されていたということなので、 - // URLを更新する - if (file.url !== image.url) { - await this.driveFilesRepository.update({ id: file.id }, { - url: image.url, - uri: image.url, - }); - - file = await this.driveFilesRepository.findOneByOrFail({ id: file.id }); - } - } - - return file; + // URLが異なっている場合、同じ画像が以前に異なるURLで登録されていたということなので、URLを更新する + await this.driveFilesRepository.update({ id: file.id }, { url: image.url, uri: image.url }); + return await this.driveFilesRepository.findOneByOrFail({ id: file.id }); } /** From 244f6720c134a3434e33c1caf6e3e0c2c87b58f5 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 05:46:42 +0900 Subject: [PATCH 44/97] cleanup(`ApMentionService.ts`): `import` --- .../src/core/activitypub/models/ApMentionService.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApMentionService.ts b/packages/backend/src/core/activitypub/models/ApMentionService.ts index 62ae3cf93d08..672888849614 100644 --- a/packages/backend/src/core/activitypub/models/ApMentionService.ts +++ b/packages/backend/src/core/activitypub/models/ApMentionService.ts @@ -1,14 +1,13 @@ -import { Inject, Injectable } from '@nestjs/common'; import promiseLimit from 'promise-limit'; -import { DI } from '@/di-symbols.js'; +import { Inject, Injectable } from '@nestjs/common'; import type { User } from '@/models/index.js'; -import type { Config } from '@/config.js'; import { toArray, unique } from '@/misc/prelude/array.js'; +import { DI } from '@/di-symbols.js'; import { bindThis } from '@/decorators.js'; -import { isMention } from '../type.js'; -import { ApResolverService, Resolver } from '../ApResolverService.js'; -import { ApPersonService } from './ApPersonService.js'; -import type { IObject, IApMention } from '../type.js'; +import type { Config } from '@/config.js'; +import { isMention, type IApMention, type IObject } from '../type.js'; +import type { ApPersonService } from './ApPersonService.js'; +import type { ApResolverService, Resolver } from '../ApResolverService.js'; @Injectable() export class ApMentionService { From b651fb55dc9a24a6e90d3c5f758960bcd4d63155 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 06:10:35 +0900 Subject: [PATCH 45/97] =?UTF-8?q?refactor(`ApImageService.ts`):=20`JSON.st?= =?UTF-8?q?ringify()`=E3=81=A7=E3=81=AEindentation=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/core/activitypub/models/ApImageService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApImageService.ts b/packages/backend/src/core/activitypub/models/ApImageService.ts index 0476e845eda9..cd41867e4adf 100644 --- a/packages/backend/src/core/activitypub/models/ApImageService.ts +++ b/packages/backend/src/core/activitypub/models/ApImageService.ts @@ -51,7 +51,7 @@ export class ApImageService { } if (typeof image.url !== 'string') { - throw new Error('invalid image: unexpected type of url: ' + JSON.stringify(image.url)); + throw new Error('invalid image: unexpected type of url: ' + JSON.stringify(image.url, null, 2)); } if (!checkHttps(image.url)) { From d8f0d769733c4cb0629821b04e557a0ae6f5ff5b Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 06:12:03 +0900 Subject: [PATCH 46/97] cleanup(`ApNoteService.ts`): `import` --- .../core/activitypub/models/ApNoteService.ts | 48 +++++++++---------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index f82e41a2cd26..29abf997f47c 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -1,37 +1,35 @@ -import { forwardRef, Inject, Injectable } from '@nestjs/common'; -import promiseLimit from 'promise-limit'; import { In } from 'typeorm'; -import { DI } from '@/di-symbols.js'; +import promiseLimit from 'promise-limit'; +import { forwardRef, Inject, Injectable } from '@nestjs/common'; import type { PollsRepository, EmojisRepository } from '@/models/index.js'; -import type { Config } from '@/config.js'; import type { RemoteUser } from '@/models/entities/User.js'; import type { Note } from '@/models/entities/Note.js'; -import { toArray, toSingle, unique } from '@/misc/prelude/array.js'; import type { Emoji } from '@/models/entities/Emoji.js'; -import { MetaService } from '@/core/MetaService.js'; -import { AppLockService } from '@/core/AppLockService.js'; import type { DriveFile } from '@/models/entities/DriveFile.js'; -import { NoteCreateService } from '@/core/NoteCreateService.js'; -import type Logger from '@/logger.js'; -import { IdService } from '@/core/IdService.js'; -import { PollService } from '@/core/PollService.js'; import { StatusError } from '@/misc/status-error.js'; -import { UtilityService } from '@/core/UtilityService.js'; -import { bindThis } from '@/decorators.js'; +import { toArray, toSingle, unique } from '@/misc/prelude/array.js'; import { checkHttps } from '@/misc/check-https.js'; -import { getOneApId, getApId, getOneApHrefNullable, validPost, isEmoji, getApType } from '../type.js'; -import { ApLoggerService } from '../ApLoggerService.js'; -import { ApMfmService } from '../ApMfmService.js'; -import { ApDbResolverService } from '../ApDbResolverService.js'; -import { ApResolverService } from '../ApResolverService.js'; -import { ApAudienceService } from '../ApAudienceService.js'; -import { ApPersonService } from './ApPersonService.js'; +import type Logger from '@/logger.js'; +import { DI } from '@/di-symbols.js'; +import { bindThis } from '@/decorators.js'; +import type { UtilityService } from '@/core/UtilityService.js'; +import type { PollService } from '@/core/PollService.js'; +import type { NoteCreateService } from '@/core/NoteCreateService.js'; +import type { MetaService } from '@/core/MetaService.js'; +import type { IdService } from '@/core/IdService.js'; +import type { AppLockService } from '@/core/AppLockService.js'; +import type { Config } from '@/config.js'; +import { getOneApId, getApId, getOneApHrefNullable, validPost, isEmoji, getApType, type IObject, type IPost } from '../type.js'; import { extractApHashtags } from './tag.js'; -import { ApMentionService } from './ApMentionService.js'; -import { ApQuestionService } from './ApQuestionService.js'; -import { ApImageService } from './ApImageService.js'; -import type { Resolver } from '../ApResolverService.js'; -import type { IObject, IPost } from '../type.js'; +import { ApPersonService } from './ApPersonService.js'; +import type { ApQuestionService } from './ApQuestionService.js'; +import type { ApMentionService } from './ApMentionService.js'; +import type { ApImageService } from './ApImageService.js'; +import type { ApResolverService, Resolver } from '../ApResolverService.js'; +import type { ApMfmService } from '../ApMfmService.js'; +import type { ApLoggerService } from '../ApLoggerService.js'; +import type { ApDbResolverService } from '../ApDbResolverService.js'; +import type { ApAudienceService } from '../ApAudienceService.js'; @Injectable() export class ApNoteService { From bfc22e95180a16e521eef237efb4c58241271570 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 06:12:26 +0900 Subject: [PATCH 47/97] cleanup(`ApNoteService.ts`) --- .../src/core/activitypub/models/ApNoteService.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index 29abf997f47c..fc416872a91e 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -111,12 +111,10 @@ export class ApNoteService { const entryUri = getApId(value); const err = this.validateNote(object, entryUri); if (err) { - this.logger.error(`${err.message}`, { - resolver: { - history: resolver.getHistory(), - }, - value: value, - object: object, + this.logger.error(err.message, { + resolver: { history: resolver.getHistory() }, + value, + object, }); throw new Error('invalid note'); } From 42b90cd2f1c4fc8bbdde40ec84b94e92f1009d39 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 06:12:33 +0900 Subject: [PATCH 48/97] cleanup(`ApNoteService.ts`) --- packages/backend/src/core/activitypub/models/ApNoteService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index fc416872a91e..3c766a061a55 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -210,7 +210,7 @@ export class ApNoteService { }; const uris = unique([note._misskey_quote, note.quoteUrl].filter((x): x is string => typeof x === 'string')); - const results = await Promise.all(uris.map(uri => tryResolveNote(uri))); + const results = await Promise.all(uris.map(tryResolveNote)); quote = results.filter((x): x is { status: 'ok', res: Note } => x.status === 'ok').map(x => x.res).at(0); if (!quote) { From 7a825752f52bba2df2e8d405c3fa77e419b82a59 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 06:12:40 +0900 Subject: [PATCH 49/97] cleanup(`ApNoteService.ts`) --- .../src/core/activitypub/models/ApNoteService.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index 3c766a061a55..ff3ced0adc52 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -294,19 +294,18 @@ export class ApNoteService { const uri = typeof value === 'string' ? value : value.id; if (uri == null) throw new Error('missing uri'); - // ブロックしてたら中断 + // ブロックしていたら中断 const meta = await this.metaService.fetch(); - if (this.utilityService.isBlockedHost(meta.blockedHosts, this.utilityService.extractDbHost(uri))) throw new StatusError('blocked host', 451); + if (this.utilityService.isBlockedHost(meta.blockedHosts, this.utilityService.extractDbHost(uri))) { + throw new StatusError('blocked host', 451); + } const unlock = await this.appLockService.getApLock(uri); try { //#region このサーバーに既に登録されていたらそれを返す const exist = await this.fetchNote(uri); - - if (exist) { - return exist; - } + if (exist) return exist; //#endregion if (uri.startsWith(this.config.url)) { From 3bd784eac2a6a5ecde0c56f65aad1e053f1a2b42 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 06:13:39 +0900 Subject: [PATCH 50/97] =?UTF-8?q?cleanup(`ApNoteService.ts`):=20`any`?= =?UTF-8?q?=E3=81=AB=E5=AF=BE=E3=81=99=E3=82=8Bnon-null=20assertion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/core/activitypub/models/ApNoteService.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index ff3ced0adc52..1a05a376d671 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -343,15 +343,15 @@ export class ApNoteService { if ((exists.updatedAt == null) || (tag.id != null && exists.uri == null) || (new Date(tag.updated) > exists.updatedAt) - || (tag.icon!.url !== exists.originalUrl) + || (tag.icon.url !== exists.originalUrl) ) { await this.emojisRepository.update({ host, name, }, { uri: tag.id, - originalUrl: tag.icon!.url, - publicUrl: tag.icon!.url, + originalUrl: tag.icon.url, + publicUrl: tag.icon.url, updatedAt: new Date(), }); @@ -370,8 +370,8 @@ export class ApNoteService { host, name, uri: tag.id, - originalUrl: tag.icon!.url, - publicUrl: tag.icon!.url, + originalUrl: tag.icon.url, + publicUrl: tag.icon.url, updatedAt: new Date(), aliases: [], }).then(x => this.emojisRepository.findOneByOrFail(x.identifiers[0])); From 451a0e3b489930d0a35f4682decce5eb899228a0 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 06:14:48 +0900 Subject: [PATCH 51/97] =?UTF-8?q?refactor(`ApNoteService.ts`):=20=E6=B7=BB?= =?UTF-8?q?=E4=BB=98=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/core/activitypub/models/ApNoteService.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index 1a05a376d671..f1b8bf43eac0 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -165,12 +165,13 @@ export class ApNoteService { // 添付ファイル // TODO: attachmentは必ずしもImageではない // TODO: attachmentは必ずしも配列ではない - // Noteがsensitiveなら添付もsensitiveにする const limit = promiseLimit(2); - - note.attachment = toArray(note.attachment); - note.attachment.forEach(attach => attach.sensitive = note.sensitive); - const files = (await Promise.all(note.attachment.map(x => limit(() => this.apImageService.resolveImage(actor, x))))); + const files = (await Promise.all(toArray(note.attachment).map(attach => ( + limit(() => this.apImageService.resolveImage(actor, { + ...attach, + sensitive: note.sensitive, // Noteがsensitiveなら添付もsensitiveにする + })) + )))); // リプライ const reply: Note | null = note.inReplyTo From 5190ef954caf376da46c707f52e02208d53caafd Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 06:46:29 +0900 Subject: [PATCH 52/97] cleanup(`ApPersonService.ts`): `import` --- .../activitypub/models/ApPersonService.ts | 55 +++++++++---------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index fae4ffbac31c..1d206254c623 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -1,49 +1,48 @@ -import { Inject, Injectable } from '@nestjs/common'; import promiseLimit from 'promise-limit'; -import { DataSource } from 'typeorm'; import { ModuleRef } from '@nestjs/core'; -import { DI } from '@/di-symbols.js'; +import { Inject, Injectable } from '@nestjs/common'; import type { FollowingsRepository, InstancesRepository, UserProfilesRepository, UserPublickeysRepository, UsersRepository } from '@/models/index.js'; -import type { Config } from '@/config.js'; +import { UserPublickey } from '@/models/entities/UserPublickey.js'; +import { UserProfile } from '@/models/entities/UserProfile.js'; +import { UserNotePining } from '@/models/entities/UserNotePining.js'; import type { LocalUser, RemoteUser } from '@/models/entities/User.js'; import { User } from '@/models/entities/User.js'; +import type { Note } from '@/models/entities/Note.js'; +import type { Emoji } from '@/models/entities/Emoji.js'; import { truncate } from '@/misc/truncate.js'; -import type { CacheService } from '@/core/CacheService.js'; +import { StatusError } from '@/misc/status-error.js'; +import { toArray } from '@/misc/prelude/array.js'; import { normalizeForSearch } from '@/misc/normalize-for-search.js'; import { isDuplicateKeyValueError } from '@/misc/is-duplicate-key-value-error.js'; +import { checkHttps } from '@/misc/check-https.js'; import type Logger from '@/logger.js'; -import type { Note } from '@/models/entities/Note.js'; -import type { IdService } from '@/core/IdService.js'; -import type { MfmService } from '@/core/MfmService.js'; -import type { Emoji } from '@/models/entities/Emoji.js'; -import { toArray } from '@/misc/prelude/array.js'; -import type { GlobalEventService } from '@/core/GlobalEventService.js'; -import type { FederatedInstanceService } from '@/core/FederatedInstanceService.js'; -import type { FetchInstanceMetadataService } from '@/core/FetchInstanceMetadataService.js'; -import { UserProfile } from '@/models/entities/UserProfile.js'; -import { UserPublickey } from '@/models/entities/UserPublickey.js'; +import { DI } from '@/di-symbols.js'; +import { bindThis } from '@/decorators.js'; +import type { UserEntityService } from '@/core/entities/UserEntityService.js'; +import type { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js'; import type UsersChart from '@/core/chart/charts/users.js'; import type InstanceChart from '@/core/chart/charts/instance.js'; -import type { HashtagService } from '@/core/HashtagService.js'; -import { UserNotePining } from '@/models/entities/UserNotePining.js'; -import { StatusError } from '@/misc/status-error.js'; import type { UtilityService } from '@/core/UtilityService.js'; -import type { UserEntityService } from '@/core/entities/UserEntityService.js'; -import { bindThis } from '@/decorators.js'; -import { MetaService } from '@/core/MetaService.js'; -import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js'; +import type { MfmService } from '@/core/MfmService.js'; +import type { MetaService } from '@/core/MetaService.js'; +import type { IdService } from '@/core/IdService.js'; +import type { HashtagService } from '@/core/HashtagService.js'; +import type { GlobalEventService } from '@/core/GlobalEventService.js'; +import type { FetchInstanceMetadataService } from '@/core/FetchInstanceMetadataService.js'; +import type { FederatedInstanceService } from '@/core/FederatedInstanceService.js'; +import type { CacheService } from '@/core/CacheService.js'; import type { AccountMoveService } from '@/core/AccountMoveService.js'; -import { checkHttps } from '@/misc/check-https.js'; +import type { Config } from '@/config.js'; import { getApId, getApType, getOneApHrefNullable, isActor, isCollection, isCollectionOrOrderedCollection, isPropertyValue } from '../type.js'; import { extractApHashtags } from './tag.js'; -import type { OnModuleInit } from '@nestjs/common'; import type { ApNoteService } from './ApNoteService.js'; -import type { ApMfmService } from '../ApMfmService.js'; -import type { ApResolverService, Resolver } from '../ApResolverService.js'; -import type { ApLoggerService } from '../ApLoggerService.js'; -// eslint-disable-next-line @typescript-eslint/consistent-type-imports import type { ApImageService } from './ApImageService.js'; +import type { OnModuleInit } from '@nestjs/common'; +import type { DataSource } from 'typeorm'; import type { IActor, IObject } from '../type.js'; +import type { ApResolverService, Resolver } from '../ApResolverService.js'; +import type { ApMfmService } from '../ApMfmService.js'; +import type { ApLoggerService } from '../ApLoggerService.js'; const nameLength = 128; const summaryLength = 2048; From f20381d06b5902dfe485133f324f8949bb32c94c Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 06:47:28 +0900 Subject: [PATCH 53/97] =?UTF-8?q?refactor(`ApPersonService.ts`):=20?= =?UTF-8?q?=E3=82=88=E3=82=8A=E5=AE=9F=E6=83=85=E3=81=AB=E5=8D=B3=E3=81=97?= =?UTF-8?q?=E3=81=9F`as`=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/core/activitypub/models/ApPersonService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 1d206254c623..1f8933c8f0a2 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -197,7 +197,7 @@ export class ApPersonService implements OnModuleInit { */ @bindThis public async fetchPerson(uri: string): Promise { - const cached = this.cacheService.uriPersonCache.get(uri) as LocalUser | RemoteUser | null; + const cached = this.cacheService.uriPersonCache.get(uri) as LocalUser | RemoteUser | null | undefined; if (cached) return cached; // URIがこのサーバーを指しているならデータベースからフェッチ From 541429f16b3117e53f14a87225bb68f5647320be Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 06:48:10 +0900 Subject: [PATCH 54/97] cleanup(`ApPersonService.ts`) --- packages/backend/src/core/activitypub/models/ApPersonService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 1f8933c8f0a2..e1322bb26046 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -245,7 +245,7 @@ export class ApPersonService implements OnModuleInit { const { fields } = this.analyzeAttachments(person.attachment ?? []); - const tags = extractApHashtags(person.tag).map(tag => normalizeForSearch(tag)).splice(0, 32); + const tags = extractApHashtags(person.tag).map(normalizeForSearch).splice(0, 32); const isBot = getApType(object) === 'Service'; From a003fb27078f2a863c33d05c1a8e0b24bdb0e8fe Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 06:49:02 +0900 Subject: [PATCH 55/97] =?UTF-8?q?refactor(`ApPersonService.ts`):=20?= =?UTF-8?q?=E5=86=97=E9=95=B7=E3=81=A0=E3=81=A3=E3=81=9F=E9=83=A8=E5=88=86?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/core/activitypub/models/ApPersonService.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index e1322bb26046..c769d16b9e16 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -243,7 +243,7 @@ export class ApPersonService implements OnModuleInit { const host = this.punyHost(object.id); - const { fields } = this.analyzeAttachments(person.attachment ?? []); + const fields = this.analyzeAttachments(person.attachment ?? []); const tags = extractApHashtags(person.tag).map(normalizeForSearch).splice(0, 32); @@ -444,7 +444,7 @@ export class ApPersonService implements OnModuleInit { const emojiNames = emojis.map(emoji => emoji.name); - const { fields } = this.analyzeAttachments(person.attachment ?? []); + const fields = this.analyzeAttachments(person.attachment ?? []); const tags = extractApHashtags(person.tag).map(tag => normalizeForSearch(tag)).splice(0, 32); @@ -577,8 +577,8 @@ export class ApPersonService implements OnModuleInit { } @bindThis - // TODO: `attachments`が`IObject`だった場合、返り値が`{ fields: [] }`になるようだが構わないのか? - public analyzeAttachments(attachments: IObject | IObject[] | undefined): { fields: Field[] } { + // TODO: `attachments`が`IObject`だった場合、返り値が`[]`になるようだが構わないのか? + public analyzeAttachments(attachments: IObject | IObject[] | undefined): Field[] { const fields: Field[] = []; if (Array.isArray(attachments)) { @@ -590,7 +590,7 @@ export class ApPersonService implements OnModuleInit { } } - return { fields }; + return fields; } @bindThis From 8cd1152705fd72084e462216d5b6dcd86068d438 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 06:49:24 +0900 Subject: [PATCH 56/97] cleanup(`ApPersonService.ts`): deadcode --- packages/backend/src/core/activitypub/models/ApPersonService.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index c769d16b9e16..07031feb1033 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -560,8 +560,6 @@ export class ApPersonService implements OnModuleInit { */ @bindThis public async resolvePerson(uri: string, resolver?: Resolver): Promise { - if (typeof uri !== 'string') throw new Error('uri is not string'); - //#region このサーバーに既に登録されていたらそれを返す const exist = await this.fetchPerson(uri); From f4a8e744bf7df4fff93f249eaf5c2e9bd03ba8d9 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 06:49:32 +0900 Subject: [PATCH 57/97] cleanup(`ApPersonService.ts`) --- .../backend/src/core/activitypub/models/ApPersonService.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 07031feb1033..c52f223d5adc 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -562,10 +562,7 @@ export class ApPersonService implements OnModuleInit { public async resolvePerson(uri: string, resolver?: Resolver): Promise { //#region このサーバーに既に登録されていたらそれを返す const exist = await this.fetchPerson(uri); - - if (exist) { - return exist; - } + if (exist) return exist; //#endregion // リモートサーバーからフェッチしてきて登録 From 778585e2882477fec5f11fabf398b4b89cf26da2 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 07:10:01 +0900 Subject: [PATCH 58/97] cleanup(`ApQuestionService.ts`): `import` --- .../src/core/activitypub/models/ApQuestionService.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApQuestionService.ts b/packages/backend/src/core/activitypub/models/ApQuestionService.ts index 13a2f0fa5c55..240c37f64e0e 100644 --- a/packages/backend/src/core/activitypub/models/ApQuestionService.ts +++ b/packages/backend/src/core/activitypub/models/ApQuestionService.ts @@ -1,15 +1,13 @@ import { Inject, Injectable } from '@nestjs/common'; -import { DI } from '@/di-symbols.js'; import type { NotesRepository, PollsRepository } from '@/models/index.js'; -import type { Config } from '@/config.js'; import type { IPoll } from '@/models/entities/Poll.js'; import type Logger from '@/logger.js'; -import { isQuestion } from '../type.js'; -import { ApLoggerService } from '../ApLoggerService.js'; -import { ApResolverService } from '../ApResolverService.js'; -import type { Resolver } from '../ApResolverService.js'; -import type { IObject, IQuestion } from '../type.js'; +import { DI } from '@/di-symbols.js'; import { bindThis } from '@/decorators.js'; +import type { Config } from '@/config.js'; +import { isQuestion, type IObject, type IQuestion } from '../type.js'; +import type { ApResolverService, Resolver } from '../ApResolverService.js'; +import type { ApLoggerService } from '../ApLoggerService.js'; @Injectable() export class ApQuestionService { From fcc60421e215a2c3e274438a41da4c77fe6e3a0a Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 07:10:47 +0900 Subject: [PATCH 59/97] refactor(`ApQuestionService.ts`): `eslint-disable-next-line` --- .../backend/src/core/activitypub/models/ApQuestionService.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/backend/src/core/activitypub/models/ApQuestionService.ts b/packages/backend/src/core/activitypub/models/ApQuestionService.ts index 240c37f64e0e..78b803bf0405 100644 --- a/packages/backend/src/core/activitypub/models/ApQuestionService.ts +++ b/packages/backend/src/core/activitypub/models/ApQuestionService.ts @@ -31,6 +31,7 @@ export class ApQuestionService { @bindThis public async extractPollFromQuestion(source: string | IObject, resolver?: Resolver): Promise { + // eslint-disable-next-line no-param-reassign if (resolver == null) resolver = this.apResolverService.createResolver(); const question = await resolver.resolve(source); From f70fd08306c39e12fddd864fba60df3c466db1a7 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 07:11:37 +0900 Subject: [PATCH 60/97] refactor(`ApQuestionService.ts`): `eslint-disable-next-line` --- .../backend/src/core/activitypub/models/ApQuestionService.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/backend/src/core/activitypub/models/ApQuestionService.ts b/packages/backend/src/core/activitypub/models/ApQuestionService.ts index 78b803bf0405..3e37b45452a0 100644 --- a/packages/backend/src/core/activitypub/models/ApQuestionService.ts +++ b/packages/backend/src/core/activitypub/models/ApQuestionService.ts @@ -82,6 +82,7 @@ export class ApQuestionService { //#endregion // resolve new Question object + // eslint-disable-next-line no-param-reassign if (resolver == null) resolver = this.apResolverService.createResolver(); const question = await resolver.resolve(value) as IQuestion; this.logger.debug(`fetched question: ${JSON.stringify(question, null, 2)}`); From 279321e8410b88df393a612c0df9ccabeec8b3c5 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 07:12:03 +0900 Subject: [PATCH 61/97] cleanup(`ApQuestionService.ts`) --- .../backend/src/core/activitypub/models/ApQuestionService.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApQuestionService.ts b/packages/backend/src/core/activitypub/models/ApQuestionService.ts index 3e37b45452a0..de8ad0ae0e4d 100644 --- a/packages/backend/src/core/activitypub/models/ApQuestionService.ts +++ b/packages/backend/src/core/activitypub/models/ApQuestionService.ts @@ -103,9 +103,7 @@ export class ApQuestionService { } } - await this.pollsRepository.update({ noteId: note.id }, { - votes: poll.votes, - }); + await this.pollsRepository.update({ noteId: note.id }, { votes: poll.votes }); return changed; } From 0f8686dd5782fc03485db5939b148e7de0bcdf86 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 07:13:51 +0900 Subject: [PATCH 62/97] =?UTF-8?q?refactor(`ApQuestionService.ts`):=20non-n?= =?UTF-8?q?ull=20assertion=E3=82=92=E6=B6=88=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/activitypub/models/ApQuestionService.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApQuestionService.ts b/packages/backend/src/core/activitypub/models/ApQuestionService.ts index de8ad0ae0e4d..35abdaf24be8 100644 --- a/packages/backend/src/core/activitypub/models/ApQuestionService.ts +++ b/packages/backend/src/core/activitypub/models/ApQuestionService.ts @@ -47,11 +47,17 @@ export class ApQuestionService { throw new Error('invalid question'); } - const choices = question[multiple ? 'anyOf' : 'oneOf']! - .map((x, i) => x.name!); - - const votes = question[multiple ? 'anyOf' : 'oneOf']! - .map((x, i) => x.replies && x.replies.totalItems || x._misskey_votes || 0); + const choices = question[multiple ? 'anyOf' : 'oneOf'] + ?.map((x) => x.name) + .filter((x): x is string => typeof x === 'string') + ?? []; + + const votes = question[multiple ? 'anyOf' : 'oneOf'] + ?.map((x) => { + if (x.replies) return x.replies.totalItems; + if (x._misskey_votes) return x._misskey_votes; + return 0; + }); return { choices, From 5e715b210504220638885798ea54fe20473a9ab5 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 07:14:11 +0900 Subject: [PATCH 63/97] cleanup(`ApQuestionService.ts`) --- .../src/core/activitypub/models/ApQuestionService.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApQuestionService.ts b/packages/backend/src/core/activitypub/models/ApQuestionService.ts index 35abdaf24be8..e3ded452cf16 100644 --- a/packages/backend/src/core/activitypub/models/ApQuestionService.ts +++ b/packages/backend/src/core/activitypub/models/ApQuestionService.ts @@ -59,12 +59,7 @@ export class ApQuestionService { return 0; }); - return { - choices, - votes, - multiple, - expiresAt, - }; + return { choices, votes, multiple, expiresAt }; } /** From d0e00c8d17057fcdf510d102fc2a79c69aa8fe32 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 07:15:09 +0900 Subject: [PATCH 64/97] =?UTF-8?q?WIP(`ApQuestionService.ts`):=20non-null?= =?UTF-8?q?=20assertion=E3=82=92=E6=B6=88=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit エラーメッセージを考える必要がある。 --- .../backend/src/core/activitypub/models/ApQuestionService.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApQuestionService.ts b/packages/backend/src/core/activitypub/models/ApQuestionService.ts index e3ded452cf16..c5cec5a3962c 100644 --- a/packages/backend/src/core/activitypub/models/ApQuestionService.ts +++ b/packages/backend/src/core/activitypub/models/ApQuestionService.ts @@ -91,12 +91,14 @@ export class ApQuestionService { if (question.type !== 'Question') throw new Error('object is not a Question'); const apChoices = question.oneOf ?? question.anyOf; + if (apChoices == null) throw new Error(''); // TODO let changed = false; for (const choice of poll.choices) { const oldCount = poll.votes[poll.choices.indexOf(choice)]; - const newCount = apChoices!.filter(ap => ap.name === choice)[0].replies!.totalItems; + const newCount = apChoices.filter(ap => ap.name === choice).at(0)?.replies?.totalItems; + if (newCount == null) throw new Error(''); // TODO if (oldCount !== newCount) { changed = true; From 630078f92ef5f2c4be25ca1eb6bd0d7980c479f4 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 07:17:56 +0900 Subject: [PATCH 65/97] =?UTF-8?q?refactor(`ApQuestionService.ts`):=20`any`?= =?UTF-8?q?=E3=82=92=E6=B6=88=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/src/core/activitypub/models/ApQuestionService.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApQuestionService.ts b/packages/backend/src/core/activitypub/models/ApQuestionService.ts index c5cec5a3962c..0397ddf435ea 100644 --- a/packages/backend/src/core/activitypub/models/ApQuestionService.ts +++ b/packages/backend/src/core/activitypub/models/ApQuestionService.ts @@ -68,8 +68,9 @@ export class ApQuestionService { * @returns true if updated */ @bindThis - public async updateQuestion(value: any, resolver?: Resolver) { + public async updateQuestion(value: string | IObject, resolver?: Resolver) { const uri = typeof value === 'string' ? value : value.id; + if (uri == null) throw new Error(''); // TODO // URIがこのサーバーを指しているならスキップ if (uri.startsWith(this.config.url + '/')) throw new Error('uri points local'); From afe16d702ced6be70ca554fa9b1beb445d270907 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 07:18:09 +0900 Subject: [PATCH 66/97] refactor(`ApQuestionService.ts`): function return type --- .../backend/src/core/activitypub/models/ApQuestionService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApQuestionService.ts b/packages/backend/src/core/activitypub/models/ApQuestionService.ts index 0397ddf435ea..6c6481f30d7a 100644 --- a/packages/backend/src/core/activitypub/models/ApQuestionService.ts +++ b/packages/backend/src/core/activitypub/models/ApQuestionService.ts @@ -68,7 +68,7 @@ export class ApQuestionService { * @returns true if updated */ @bindThis - public async updateQuestion(value: string | IObject, resolver?: Resolver) { + public async updateQuestion(value: string | IObject, resolver?: Resolver): Promise { const uri = typeof value === 'string' ? value : value.id; if (uri == null) throw new Error(''); // TODO From 09f67204b1f7e433e3309a7526adc3d9c03cb847 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 20:22:59 +0900 Subject: [PATCH 67/97] =?UTF-8?q?WIP(`ApPersonService.ts`):=20=E5=8F=AF?= =?UTF-8?q?=E8=AA=AD=E6=80=A7=E3=81=AE=E4=BD=8E=E3=81=84=E4=B8=89=E9=A0=85?= =?UTF-8?q?=E6=BC=94=E7=AE=97=E5=AD=90=E3=82=92=E5=89=8A=E9=99=A4=E3=81=97?= =?UTF-8?q?=E3=81=A4=E3=81=A4non-null=20assertion=E3=82=92=E5=9B=9E?= =?UTF-8?q?=E9=81=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit エラーメッセージを考える必要がある。 --- .../activitypub/models/ApPersonService.ts | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index c52f223d5adc..ad72dbba5506 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -341,14 +341,11 @@ export class ApPersonService implements OnModuleInit { this.hashtagService.updateUsertags(user, tags); //#region アバターとヘッダー画像をフェッチ - const [avatar, banner] = await Promise.all([ - person.icon, - person.image, - ].map(img => - img == null - ? Promise.resolve(null) - : this.apImageService.resolveImage(user!, img).catch(() => null), - )); + const [avatar, banner] = await Promise.all([person.icon, person.image].map(img => { + if (img == null) return null; + if (user == null) throw new Error(''); // TODO + return this.apImageService.resolveImage(user, img).catch(() => null); + })); const avatarId = avatar ? avatar.id : null; const bannerId = banner ? banner.id : null; @@ -427,14 +424,10 @@ export class ApPersonService implements OnModuleInit { this.logger.info(`Updating the Person: ${person.id}`); // アバターとヘッダー画像をフェッチ - const [avatar, banner] = await Promise.all([ - person.icon, - person.image, - ].map(img => - img == null - ? Promise.resolve(null) - : this.apImageService.resolveImage(exist, img).catch(() => null), - )); + const [avatar, banner] = await Promise.all([person.icon, person.image].map(img => { + if (img == null) return null; + return this.apImageService.resolveImage(exist, img).catch(() => null); + })); // カスタム絵文字取得 const emojis = await this.apNoteService.extractEmojis(person.tag ?? [], exist.host).catch(e => { From eb0607ec8b4cad5df2fd9caaa955869e1cca9974 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 20:24:34 +0900 Subject: [PATCH 68/97] =?UTF-8?q?cleanup(`ApPersonService.ts`):=20?= =?UTF-8?q?=E4=B8=8D=E5=BF=85=E8=A6=81=E3=81=AA=E4=B8=89=E9=A0=85=E6=BC=94?= =?UTF-8?q?=E7=AE=97=E5=AD=90=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/core/activitypub/models/ApPersonService.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index ad72dbba5506..e21dd0eac711 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -347,12 +347,12 @@ export class ApPersonService implements OnModuleInit { return this.apImageService.resolveImage(user, img).catch(() => null); })); - const avatarId = avatar ? avatar.id : null; - const bannerId = banner ? banner.id : null; + const avatarId = avatar?.id ?? null; + const bannerId = banner?.id ?? null; const avatarUrl = avatar ? this.driveFileEntityService.getPublicUrl(avatar, 'avatar') : null; const bannerUrl = banner ? this.driveFileEntityService.getPublicUrl(banner) : null; - const avatarBlurhash = avatar ? avatar.blurhash : null; - const bannerBlurhash = banner ? banner.blurhash : null; + const avatarBlurhash = avatar?.blurhash ?? null; + const bannerBlurhash = banner?.blurhash ?? null; await this.usersRepository.update(user.id, { avatarId, From 9801b20040a1285bd8d117d6dfdbf3802d16067c Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 20:25:55 +0900 Subject: [PATCH 69/97] =?UTF-8?q?cleanup(`ApPersonService.ts`):=20?= =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA`as`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/src/core/activitypub/models/ApPersonService.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index e21dd0eac711..8b5d19371dff 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -8,7 +8,6 @@ import { UserNotePining } from '@/models/entities/UserNotePining.js'; import type { LocalUser, RemoteUser } from '@/models/entities/User.js'; import { User } from '@/models/entities/User.js'; import type { Note } from '@/models/entities/Note.js'; -import type { Emoji } from '@/models/entities/Emoji.js'; import { truncate } from '@/misc/truncate.js'; import { StatusError } from '@/misc/status-error.js'; import { toArray } from '@/misc/prelude/array.js'; @@ -374,7 +373,7 @@ export class ApPersonService implements OnModuleInit { //#region カスタム絵文字取得 const emojis = await this.apNoteService.extractEmojis(person.tag ?? [], host).catch(err => { this.logger.info(`extractEmojis: ${err}`); - return [] as Emoji[]; + return []; }); const emojiNames = emojis.map(emoji => emoji.name); @@ -432,8 +431,8 @@ export class ApPersonService implements OnModuleInit { // カスタム絵文字取得 const emojis = await this.apNoteService.extractEmojis(person.tag ?? [], exist.host).catch(e => { this.logger.info(`extractEmojis: ${e}`); - return [] as Emoji[]; - }); + return []; + }); const emojiNames = emojis.map(emoji => emoji.name); From 8e46204d91d56bfbb0e697acaacddc119283a186 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 20:26:43 +0900 Subject: [PATCH 70/97] cleanup(`ApPersonService.ts`) --- .../src/core/activitypub/models/ApPersonService.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 8b5d19371dff..f6c0a6fe1d73 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -401,16 +401,11 @@ export class ApPersonService implements OnModuleInit { if (typeof uri !== 'string') throw new Error('uri is not string'); // URIがこのサーバーを指しているならスキップ - if (uri.startsWith(`${this.config.url}/`)) { - return; - } + if (uri.startsWith(`${this.config.url}/`)) return; //#region このサーバーに既に登録されているか const exist = await this.usersRepository.findOneBy({ uri }) as RemoteUser | null; - - if (exist === null) { - return; - } + if (exist === null) return; //#endregion // eslint-disable-next-line no-param-reassign From 56a66087419ee99cb8d7b74b079436a7b6496907 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 20:29:38 +0900 Subject: [PATCH 71/97] refactor(`ApPersonService.ts`) --- .../src/core/activitypub/models/ApPersonService.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index f6c0a6fe1d73..4d5c3c78a3d9 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -505,11 +505,10 @@ export class ApPersonService implements OnModuleInit { this.hashtagService.updateUsertags(exist, tags); // 該当ユーザーが既にフォロワーになっていた場合はFollowingもアップデートする - await this.followingsRepository.update({ - followerId: exist.id, - }, { - followerSharedInbox: person.sharedInbox ?? (person.endpoints ? person.endpoints.sharedInbox : undefined), - }); + await this.followingsRepository.update( + { followerId: exist.id }, + { followerSharedInbox: person.sharedInbox ?? person.endpoints?.sharedInbox }, + ); await this.updateFeatured(exist.id, resolver).catch(err => this.logger.error(err)); From 37d5c2c79bec9ad5ac5dd4bfb9108fc949ffaa15 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 20:31:12 +0900 Subject: [PATCH 72/97] =?UTF-8?q?refactor(`ApPersonService.ts`):=20?= =?UTF-8?q?=E5=8F=AF=E8=AA=AD=E6=80=A7=E3=81=AE=E4=BD=8E=E3=81=84=E4=B8=89?= =?UTF-8?q?=E9=A0=85=E6=BC=94=E7=AE=97=E5=AD=90=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 元の実装が悪いと判断し`null`かどうかの確認をより厳密に行うようにした。 --- .../core/activitypub/models/ApPersonService.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 4d5c3c78a3d9..45f0d452ebe1 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -460,12 +460,23 @@ export class ApPersonService implements OnModuleInit { isExplorable: !!person.discoverable, } as Partial & Pick; - const moving = + const moving = ((): boolean => { // 移行先がない→ある - (!exist.movedToUri && updates.movedToUri) || + if ( + exist.movedToUri === null && + updates.movedToUri + ) return true; + // 移行先がある→別のもの - (exist.movedToUri !== updates.movedToUri && exist.movedToUri && updates.movedToUri); + if ( + exist.movedToUri !== null && + updates.movedToUri !== null && + exist.movedToUri !== updates.movedToUri + ) return true; + // 移行先がある→ない、ない→ないは無視 + return false; + })(); if (moving) updates.movedAt = new Date(); From a234675eedd76c499128e3a75f3d6bae067954db Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 20:39:39 +0900 Subject: [PATCH 73/97] cleanup(`ApPersonService.ts`) --- packages/backend/src/core/activitypub/models/ApPersonService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 45f0d452ebe1..ae0fd5fe523b 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -503,7 +503,7 @@ export class ApPersonService implements OnModuleInit { } await this.userProfilesRepository.update({ userId: exist.id }, { - url: url, + url, fields, description: person.summary ? this.apMfmService.htmlToMfm(truncate(person.summary, summaryLength), person.tag) : null, birthday: bday ? bday[0] : null, From c2c2efb7fbfa1d28576eb81e5c6bb8303a7cbb20 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 20:39:48 +0900 Subject: [PATCH 74/97] cleanup(`ApPersonService.ts`) --- packages/backend/src/core/activitypub/models/ApPersonService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index ae0fd5fe523b..57298eaee92b 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -506,7 +506,7 @@ export class ApPersonService implements OnModuleInit { url, fields, description: person.summary ? this.apMfmService.htmlToMfm(truncate(person.summary, summaryLength), person.tag) : null, - birthday: bday ? bday[0] : null, + birthday: bday?.[0] ?? null, location: person['vcard:Address'] ?? null, }); From bfa0fcd6f01a6e519ea0c68017358f9980d2ed96 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 20:41:09 +0900 Subject: [PATCH 75/97] =?UTF-8?q?refactor(`ApPersonService.ts`):=20?= =?UTF-8?q?=E8=BF=94=E3=82=8A=E5=80=A4=E3=82=92`void`=E3=81=AB=E7=B5=B1?= =?UTF-8?q?=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit この返り値を参照しているコードは見当たらなかった。 また、普通に意味がない値であるように見受けられた。 --- .../backend/src/core/activitypub/models/ApPersonService.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 57298eaee92b..912477c9feb7 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -397,7 +397,7 @@ export class ApPersonService implements OnModuleInit { * @param movePreventUris ここに指定されたURIがPersonのmovedToに指定されていたり10回より多く回っている場合これ以上アカウント移行を行わない(無限ループ防止) */ @bindThis - public async updatePerson(uri: string, resolver?: Resolver | null, hint?: IObject, movePreventUris: string[] = []): Promise { + public async updatePerson(uri: string, resolver?: Resolver | null, hint?: IObject, movePreventUris: string[] = []): Promise { if (typeof uri !== 'string') throw new Error('uri is not string'); // URIがこのサーバーを指しているならスキップ @@ -536,17 +536,14 @@ export class ApPersonService implements OnModuleInit { exist.movedAt.getTime() + 1000 * 60 * 60 * 24 * 14 < updated.movedAt.getTime() )) { this.logger.info(`Start to process Move of @${updated.username}@${updated.host} (${uri})`); - return this.processRemoteMove(updated, movePreventUris) + await this.processRemoteMove(updated, movePreventUris) .then(result => { this.logger.info(`Processing Move Finished [${result}] @${updated.username}@${updated.host} (${uri})`); - return result; }) .catch(e => { this.logger.info(`Processing Move Failed @${updated.username}@${updated.host} (${uri})`, { stack: e }); }); } - - return 'skip'; } /** From 083cd678abcd64325b9628895366c03b893e42ca Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Mon, 3 Jul 2023 21:01:13 +0900 Subject: [PATCH 76/97] =?UTF-8?q?fixup!=20refactor(`ApPersonService.ts`):?= =?UTF-8?q?=20=E8=BF=94=E3=82=8A=E5=80=A4=E3=82=92`void`=E3=81=AB=E7=B5=B1?= =?UTF-8?q?=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/core/activitypub/ApInboxService.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/core/activitypub/ApInboxService.ts b/packages/backend/src/core/activitypub/ApInboxService.ts index efef777fb07e..3f47b7dc7a4b 100644 --- a/packages/backend/src/core/activitypub/ApInboxService.ts +++ b/packages/backend/src/core/activitypub/ApInboxService.ts @@ -738,11 +738,11 @@ export class ApInboxService { } @bindThis - private async move(actor: RemoteUser, activity: IMove): Promise { + private async move(actor: RemoteUser, activity: IMove): Promise { // fetch the new and old accounts const targetUri = getApHrefNullable(activity.target); - if (!targetUri) return 'skip: invalid activity target'; + if (!targetUri) return; - return await this.apPersonService.updatePerson(actor.uri) ?? 'skip: nothing to do'; + await this.apPersonService.updatePerson(actor.uri); } } From d4ffb25af9dd328d96b1a18b299fb49d660cddf5 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Tue, 4 Jul 2023 05:17:35 +0900 Subject: [PATCH 77/97] refactor(`ApNoteService.ts`) --- packages/backend/src/core/activitypub/models/ApNoteService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index f1b8bf43eac0..cd35e301deee 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -191,7 +191,7 @@ export class ApNoteService { : null; // 引用 - let quote: Note | undefined | null; + let quote: Note | undefined | null = null; if (note._misskey_quote || note.quoteUrl) { const tryResolveNote = async (uri: string): Promise< From 12516b98b08128490aca1e5f3aac6fd59e328ffe Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Tue, 4 Jul 2023 05:18:45 +0900 Subject: [PATCH 78/97] refactor(`ApPersonService.ts`) --- .../core/activitypub/models/ApPersonService.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 912477c9feb7..7fcf9fef60a6 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -268,16 +268,16 @@ export class ApPersonService implements OnModuleInit { createdAt: new Date(), lastFetchedAt: new Date(), name: truncate(person.name, nameLength), - isLocked: !!person.manuallyApprovesFollowers, + isLocked: person.manuallyApprovesFollowers, movedToUri: person.movedTo, movedAt: person.movedTo ? new Date() : null, alsoKnownAs: person.alsoKnownAs, - isExplorable: !!person.discoverable, + isExplorable: person.discoverable, username: person.preferredUsername, usernameLower: person.preferredUsername?.toLowerCase(), host, inbox: person.inbox, - sharedInbox: person.sharedInbox ?? (person.endpoints ? person.endpoints.sharedInbox : undefined), + sharedInbox: person.sharedInbox ?? person.endpoints?.sharedInbox, followersUri: person.followers ? getApId(person.followers) : undefined, featured: person.featured ? getApId(person.featured) : undefined, uri: person.id, @@ -289,9 +289,9 @@ export class ApPersonService implements OnModuleInit { await transactionalEntityManager.save(new UserProfile({ userId: user.id, description: person.summary ? this.apMfmService.htmlToMfm(truncate(person.summary, summaryLength), person.tag) : null, - url: url, + url, fields, - birthday: bday ? bday[0] : null, + birthday: bday?.[0] ?? null, location: person['vcard:Address'] ?? null, userHost: host, })); @@ -446,7 +446,7 @@ export class ApPersonService implements OnModuleInit { const updates = { lastFetchedAt: new Date(), inbox: person.inbox, - sharedInbox: person.sharedInbox ?? (person.endpoints ? person.endpoints.sharedInbox : undefined), + sharedInbox: person.sharedInbox ?? person.endpoints?.sharedInbox, followersUri: person.followers ? getApId(person.followers) : undefined, featured: person.featured, emojis: emojiNames, @@ -454,10 +454,10 @@ export class ApPersonService implements OnModuleInit { tags, isBot: getApType(object) === 'Service', isCat: (person as any).isCat === true, - isLocked: !!person.manuallyApprovesFollowers, + isLocked: person.manuallyApprovesFollowers, movedToUri: person.movedTo ?? null, alsoKnownAs: person.alsoKnownAs ?? null, - isExplorable: !!person.discoverable, + isExplorable: person.discoverable, } as Partial & Pick; const moving = ((): boolean => { From 5bf82ff26597033344bfa187ce0bb1cbae45bf73 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Tue, 4 Jul 2023 05:19:23 +0900 Subject: [PATCH 79/97] cleanup(`ApPersonService.ts`) --- packages/backend/src/core/activitypub/models/ApPersonService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 7fcf9fef60a6..dd75db60df39 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -433,7 +433,7 @@ export class ApPersonService implements OnModuleInit { const fields = this.analyzeAttachments(person.attachment ?? []); - const tags = extractApHashtags(person.tag).map(tag => normalizeForSearch(tag)).splice(0, 32); + const tags = extractApHashtags(person.tag).map(normalizeForSearch).splice(0, 32); const bday = person['vcard:bday']?.match(/^\d{4}-\d{2}-\d{2}/); From ff57dc0b3233272a219067a34cf8f56307b6d06c Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Tue, 4 Jul 2023 05:19:40 +0900 Subject: [PATCH 80/97] cleanup(`ApPersonService.ts`) --- .../src/core/activitypub/models/ApPersonService.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index dd75db60df39..733b5e6bd282 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -308,16 +308,11 @@ export class ApPersonService implements OnModuleInit { // duplicate key error if (isDuplicateKeyValueError(e)) { // /users/@a => /users/:id のように入力がaliasなときにエラーになることがあるのを対応 - const u = await this.usersRepository.findOneBy({ - uri: person.id, - }); + const u = await this.usersRepository.findOneBy({ uri: person.id }); + if (u == null) throw new Error('already registered'); - if (u) { user = u as RemoteUser; } else { - throw new Error('already registered'); - } - } else { this.logger.error(e instanceof Error ? e : new Error(e as string)); throw e; } From 662d2b1758e848a25f5570fa695d8aa32837aaef Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Tue, 4 Jul 2023 05:21:04 +0900 Subject: [PATCH 81/97] =?UTF-8?q?refactor(`ApPersonService.ts`):=20?= =?UTF-8?q?=E8=BF=94=E3=82=8A=E5=80=A4=E3=81=AE`void`=E7=B5=B1=E4=B8=80?= =?UTF-8?q?=E3=81=A8=E6=9D=A1=E4=BB=B6=E5=BC=8F=E3=81=AE=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit この返り値を参照しているコードは見当たらなかった。 また、普通に意味がない値であるように見受けられた。 --- .../activitypub/models/ApPersonService.ts | 54 +++++++++---------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 733b5e6bd282..69f7a25dcd36 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -311,8 +311,8 @@ export class ApPersonService implements OnModuleInit { const u = await this.usersRepository.findOneBy({ uri: person.id }); if (u == null) throw new Error('already registered'); - user = u as RemoteUser; - } else { + user = u as RemoteUser; + } else { this.logger.error(e instanceof Error ? e : new Error(e as string)); throw e; } @@ -625,46 +625,42 @@ export class ApPersonService implements OnModuleInit { * @param movePreventUris ここに列挙されたURIにsrc.movedToUriが含まれる場合、移行処理はしない(無限ループ防止) */ @bindThis - private async processRemoteMove(src: RemoteUser, movePreventUris: string[] = []): Promise { - if (!src.movedToUri) return 'skip: no movedToUri'; - if (src.uri === src.movedToUri) return 'skip: movedTo itself (src)'; // ??? - if (movePreventUris.length > 10) return 'skip: too many moves'; + private async processRemoteMove(src: RemoteUser, movePreventUris: string[] = []): Promise { + if (src.movedToUri === null) return; // skip: no movedToUri + if (src.uri === src.movedToUri) return; // skip: movedTo itself (src) // ??? + if (movePreventUris.length > 10) return; // skip: too many moves // まずサーバー内で検索して様子見 let dst = await this.fetchPerson(src.movedToUri); - if (dst && this.userEntityService.isLocalUser(dst)) { - // targetがローカルユーザーだった場合データベースから引っ張ってくる - dst = await this.usersRepository.findOneByOrFail({ uri: src.movedToUri }) as LocalUser; - } else if (dst) { - if (movePreventUris.includes(src.movedToUri)) return 'skip: circular move'; + if (dst) { + if (this.userEntityService.isLocalUser(dst)) { + // targetがローカルユーザーだった場合データベースから引っ張ってくる + dst = await this.usersRepository.findOneByOrFail({ uri: src.movedToUri }) as LocalUser; + } else { + if (movePreventUris.includes(src.movedToUri)) return; // skip: circular move - // targetを見つけたことがあるならtargetをupdatePersonする - await this.updatePerson(src.movedToUri, undefined, undefined, [...movePreventUris, src.uri]); - dst = await this.fetchPerson(src.movedToUri) ?? dst; - } else { - if (src.movedToUri.startsWith(`${this.config.url}/`)) { - // ローカルユーザーっぽいのにfetchPersonで見つからないということはmovedToUriが間違っている - return 'failed: movedTo is local but not found'; + // targetを見つけたことがあるならtargetをupdatePersonする + await this.updatePerson(src.movedToUri, undefined, undefined, [...movePreventUris, src.uri]); + dst = await this.fetchPerson(src.movedToUri) ?? dst; } + } else { + // ローカルユーザーっぽいのにfetchPersonで見つからないということはmovedToUriが間違っている + // failed: movedTo is local but not found + if (src.movedToUri.startsWith(`${this.config.url}/`)) return; // targetが知らない人だったらresolvePerson // (uriが存在しなかったり応答がなかったりする場合resolvePersonはthrow Errorする) dst = await this.resolvePerson(src.movedToUri); } - if (dst.movedToUri === dst.uri) return 'skip: movedTo itself (dst)'; // ??? - if (src.movedToUri !== dst.uri) return 'skip: missmatch uri'; // ??? - if (dst.movedToUri === src.uri) return 'skip: dst.movedToUri === src.uri'; - if (!dst.alsoKnownAs || dst.alsoKnownAs.length === 0) { - return 'skip: dst.alsoKnownAs is empty'; - } - if (!dst.alsoKnownAs.includes(src.uri)) { - return 'skip: alsoKnownAs does not include from.uri'; - } + if (dst.movedToUri === dst.uri) return; // skip: movedTo itself (dst) // ??? + if (src.movedToUri !== dst.uri) return; // skip: missmatch uri // ??? + if (dst.movedToUri === src.uri) return; // skip: dst.movedToUri === src.uri + if (dst.alsoKnownAs === null) return; // skip: dst.alsoKnownAs is null + if (dst.alsoKnownAs.length === 0) return; // skip: dst.alsoKnownAs is empty + if (!dst.alsoKnownAs.includes(src.uri)) return; // skip: alsoKnownAs does not include src.uri await this.accountMoveService.postMoveProcess(src, dst); - - return 'ok'; } } From 264ae11ac6ec3f5efaafad91852ef4efd335ea68 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Tue, 4 Jul 2023 05:31:45 +0900 Subject: [PATCH 82/97] cleanup(`ApQuestionService.ts`) --- .../backend/src/core/activitypub/models/ApQuestionService.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApQuestionService.ts b/packages/backend/src/core/activitypub/models/ApQuestionService.ts index 6c6481f30d7a..c9480763103f 100644 --- a/packages/backend/src/core/activitypub/models/ApQuestionService.ts +++ b/packages/backend/src/core/activitypub/models/ApQuestionService.ts @@ -35,10 +35,8 @@ export class ApQuestionService { if (resolver == null) resolver = this.apResolverService.createResolver(); const question = await resolver.resolve(source); + if (!isQuestion(question)) throw new Error('invalid type'); - if (!isQuestion(question)) { - throw new Error('invalid type'); - } const multiple = !question.oneOf; const expiresAt = question.endTime ? new Date(question.endTime) : question.closed ? new Date(question.closed) : null; From 42fed0c622b77fbda89b71ee4ccfb36a9c36b056 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Tue, 4 Jul 2023 05:33:18 +0900 Subject: [PATCH 83/97] refactor(`ApQuestionService.ts`) --- .../src/core/activitypub/models/ApQuestionService.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApQuestionService.ts b/packages/backend/src/core/activitypub/models/ApQuestionService.ts index c9480763103f..b7971b9cd4a0 100644 --- a/packages/backend/src/core/activitypub/models/ApQuestionService.ts +++ b/packages/backend/src/core/activitypub/models/ApQuestionService.ts @@ -37,14 +37,11 @@ export class ApQuestionService { const question = await resolver.resolve(source); if (!isQuestion(question)) throw new Error('invalid type'); + const multiple = question.oneOf === undefined; + if (multiple && question.anyOf === undefined) throw new Error('invalid question'); - const multiple = !question.oneOf; const expiresAt = question.endTime ? new Date(question.endTime) : question.closed ? new Date(question.closed) : null; - if (multiple && !question.anyOf) { - throw new Error('invalid question'); - } - const choices = question[multiple ? 'anyOf' : 'oneOf'] ?.map((x) => x.name) .filter((x): x is string => typeof x === 'string') From 58dbf6151c7c5faedb3bbadc9a1cbb01ae198524 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Tue, 4 Jul 2023 05:33:45 +0900 Subject: [PATCH 84/97] refactor(`ApQuestionService.ts`) --- .../src/core/activitypub/models/ApQuestionService.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApQuestionService.ts b/packages/backend/src/core/activitypub/models/ApQuestionService.ts index b7971b9cd4a0..06efa72f3b87 100644 --- a/packages/backend/src/core/activitypub/models/ApQuestionService.ts +++ b/packages/backend/src/core/activitypub/models/ApQuestionService.ts @@ -47,12 +47,7 @@ export class ApQuestionService { .filter((x): x is string => typeof x === 'string') ?? []; - const votes = question[multiple ? 'anyOf' : 'oneOf'] - ?.map((x) => { - if (x.replies) return x.replies.totalItems; - if (x._misskey_votes) return x._misskey_votes; - return 0; - }); + const votes = question[multiple ? 'anyOf' : 'oneOf']?.map((x) => x.replies?.totalItems ?? x._misskey_votes ?? 0); return { choices, votes, multiple, expiresAt }; } From c6897eacb1632c25fa0874c7e086d96208319ff2 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Tue, 4 Jul 2023 05:33:59 +0900 Subject: [PATCH 85/97] refactor(`tag.ts`): function return type --- packages/backend/src/core/activitypub/models/tag.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/tag.ts b/packages/backend/src/core/activitypub/models/tag.ts index 803846a0b081..9aeb843562b7 100644 --- a/packages/backend/src/core/activitypub/models/tag.ts +++ b/packages/backend/src/core/activitypub/models/tag.ts @@ -2,7 +2,7 @@ import { toArray } from '@/misc/prelude/array.js'; import { isHashtag } from '../type.js'; import type { IObject, IApHashtag } from '../type.js'; -export function extractApHashtags(tags: IObject | IObject[] | null | undefined) { +export function extractApHashtags(tags: IObject | IObject[] | null | undefined): string[] { if (tags == null) return []; const hashtags = extractApHashtagObjects(tags); From 6dfbf60f0e4dafbee119d68c03d2b515a497c61a Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Tue, 4 Jul 2023 06:59:05 +0900 Subject: [PATCH 86/97] fixup! enhance: account migration (#10592) --- packages/backend/src/core/activitypub/models/ApPersonService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 69f7a25dcd36..c6bb83c81cc5 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -653,7 +653,7 @@ export class ApPersonService implements OnModuleInit { // (uriが存在しなかったり応答がなかったりする場合resolvePersonはthrow Errorする) dst = await this.resolvePerson(src.movedToUri); } - + if (dst.movedToUri === dst.uri) return; // skip: movedTo itself (dst) // ??? if (src.movedToUri !== dst.uri) return; // skip: missmatch uri // ??? if (dst.movedToUri === src.uri) return; // skip: dst.movedToUri === src.uri From f2bc374ace22c0b57420c7a33720886833b6578f Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Tue, 4 Jul 2023 07:02:12 +0900 Subject: [PATCH 87/97] =?UTF-8?q?fixup!=20WIP(`ApPersonService.ts`):=20?= =?UTF-8?q?=E5=8F=AF=E8=AA=AD=E6=80=A7=E3=81=AE=E4=BD=8E=E3=81=84=E4=B8=89?= =?UTF-8?q?=E9=A0=85=E6=BC=94=E7=AE=97=E5=AD=90=E3=82=92=E5=89=8A=E9=99=A4?= =?UTF-8?q?=E3=81=97=E3=81=A4=E3=81=A4non-null=20assertion=E3=82=92?= =?UTF-8?q?=E5=9B=9E=E9=81=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/core/activitypub/models/ApPersonService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index c6bb83c81cc5..bbc5fd342b5d 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -416,7 +416,7 @@ export class ApPersonService implements OnModuleInit { const [avatar, banner] = await Promise.all([person.icon, person.image].map(img => { if (img == null) return null; return this.apImageService.resolveImage(exist, img).catch(() => null); - })); + })); // カスタム絵文字取得 const emojis = await this.apNoteService.extractEmojis(person.tag ?? [], exist.host).catch(e => { From 6f61e6643beef7766926b3532425b7fed82ee01a Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Tue, 4 Jul 2023 07:02:24 +0900 Subject: [PATCH 88/97] =?UTF-8?q?fixup!=20cleanup(`ApPersonService.ts`):?= =?UTF-8?q?=20=E4=B8=8D=E8=A6=81=E3=81=AA`as`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/core/activitypub/models/ApPersonService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index bbc5fd342b5d..546d6864e698 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -422,7 +422,7 @@ export class ApPersonService implements OnModuleInit { const emojis = await this.apNoteService.extractEmojis(person.tag ?? [], exist.host).catch(e => { this.logger.info(`extractEmojis: ${e}`); return []; - }); + }); const emojiNames = emojis.map(emoji => emoji.name); From 01e6dfb4c9d8687afa4ab0ef9a8220da2bec2997 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Tue, 4 Jul 2023 12:13:09 +0900 Subject: [PATCH 89/97] =?UTF-8?q?refactor:=20=E3=82=A8=E3=83=A9=E3=83=BC?= =?UTF-8?q?=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC=E3=82=B8=E3=82=92=E8=A6=8B?= =?UTF-8?q?=E7=B9=95=E3=81=A3=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/src/core/activitypub/models/ApNoteService.ts | 2 +- .../backend/src/core/activitypub/models/ApPersonService.ts | 6 +++--- .../src/core/activitypub/models/ApQuestionService.ts | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index cd35e301deee..3bc73ec6f3af 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -357,7 +357,7 @@ export class ApNoteService { }); const emoji = await this.emojisRepository.findOneBy({ host, name }); - if (emoji == null) throw new Error(''); // TODO + if (emoji == null) throw new Error('emoji update failed'); return emoji; } diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 546d6864e698..9e55039f6ffb 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -234,7 +234,7 @@ export class ApPersonService implements OnModuleInit { if (resolver == null) resolver = this.apResolverService.createResolver(); const object = await resolver.resolve(uri); - if (object.id == null) throw new Error(''); // TODO + if (object.id == null) throw new Error('invalid object.id: ' + object.id); const person = this.validateActor(object, uri); @@ -318,7 +318,7 @@ export class ApPersonService implements OnModuleInit { } } - if (user == null) throw new Error(''); // TODO + if (user == null) throw new Error('failed to create user: user is null'); // Register host this.federatedInstanceService.fetch(host).then(async i => { @@ -337,7 +337,7 @@ export class ApPersonService implements OnModuleInit { //#region アバターとヘッダー画像をフェッチ const [avatar, banner] = await Promise.all([person.icon, person.image].map(img => { if (img == null) return null; - if (user == null) throw new Error(''); // TODO + if (user == null) throw new Error('failed to create user: user is null'); return this.apImageService.resolveImage(user, img).catch(() => null); })); diff --git a/packages/backend/src/core/activitypub/models/ApQuestionService.ts b/packages/backend/src/core/activitypub/models/ApQuestionService.ts index 06efa72f3b87..e088bf2953eb 100644 --- a/packages/backend/src/core/activitypub/models/ApQuestionService.ts +++ b/packages/backend/src/core/activitypub/models/ApQuestionService.ts @@ -60,7 +60,7 @@ export class ApQuestionService { @bindThis public async updateQuestion(value: string | IObject, resolver?: Resolver): Promise { const uri = typeof value === 'string' ? value : value.id; - if (uri == null) throw new Error(''); // TODO + if (uri == null) throw new Error('uri is null'); // URIがこのサーバーを指しているならスキップ if (uri.startsWith(this.config.url + '/')) throw new Error('uri points local'); @@ -82,14 +82,14 @@ export class ApQuestionService { if (question.type !== 'Question') throw new Error('object is not a Question'); const apChoices = question.oneOf ?? question.anyOf; - if (apChoices == null) throw new Error(''); // TODO + if (apChoices == null) throw new Error('invalid apChoices: ' + apChoices); let changed = false; for (const choice of poll.choices) { const oldCount = poll.votes[poll.choices.indexOf(choice)]; const newCount = apChoices.filter(ap => ap.name === choice).at(0)?.replies?.totalItems; - if (newCount == null) throw new Error(''); // TODO + if (newCount == null) throw new Error('invalid newCount: ' + newCount); if (oldCount !== newCount) { changed = true; From f11c6013b6df8d1dccb642507c31ee89c6250f1a Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Tue, 4 Jul 2023 14:29:51 +0900 Subject: [PATCH 90/97] Revert "cleanup(`ApImageService.ts`): `import`" This reverts commit 1454d04c377eaf46013b0f3c3ce664a4034fd53a. --- .../core/activitypub/models/ApImageService.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApImageService.ts b/packages/backend/src/core/activitypub/models/ApImageService.ts index cd41867e4adf..0da312241f90 100644 --- a/packages/backend/src/core/activitypub/models/ApImageService.ts +++ b/packages/backend/src/core/activitypub/models/ApImageService.ts @@ -1,19 +1,19 @@ import { Inject, Injectable } from '@nestjs/common'; +import { DI } from '@/di-symbols.js'; import type { DriveFilesRepository } from '@/models/index.js'; +import type { Config } from '@/config.js'; import type { RemoteUser } from '@/models/entities/User.js'; import type { DriveFile } from '@/models/entities/DriveFile.js'; +import { MetaService } from '@/core/MetaService.js'; import { truncate } from '@/misc/truncate.js'; -import { checkHttps } from '@/misc/check-https.js'; +import { DB_MAX_IMAGE_COMMENT_LENGTH } from '@/const.js'; +import { DriveService } from '@/core/DriveService.js'; import type Logger from '@/logger.js'; -import { DI } from '@/di-symbols.js'; import { bindThis } from '@/decorators.js'; -import type { MetaService } from '@/core/MetaService.js'; -import type { DriveService } from '@/core/DriveService.js'; -import { DB_MAX_IMAGE_COMMENT_LENGTH } from '@/const.js'; -import type { Config } from '@/config.js'; +import { checkHttps } from '@/misc/check-https.js'; +import { ApResolverService } from '../ApResolverService.js'; +import { ApLoggerService } from '../ApLoggerService.js'; import type { IObject } from '../type.js'; -import type { ApResolverService } from '../ApResolverService.js'; -import type { ApLoggerService } from '../ApLoggerService.js'; @Injectable() export class ApImageService { From abecfc475045fdd147e1a66ea26498b912e3d90a Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Tue, 4 Jul 2023 14:30:20 +0900 Subject: [PATCH 91/97] Revert "cleanup(`ApMentionService.ts`): `import`" This reverts commit 244f6720c134a3434e33c1caf6e3e0c2c87b58f5. --- .../src/core/activitypub/models/ApMentionService.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApMentionService.ts b/packages/backend/src/core/activitypub/models/ApMentionService.ts index 672888849614..62ae3cf93d08 100644 --- a/packages/backend/src/core/activitypub/models/ApMentionService.ts +++ b/packages/backend/src/core/activitypub/models/ApMentionService.ts @@ -1,13 +1,14 @@ -import promiseLimit from 'promise-limit'; import { Inject, Injectable } from '@nestjs/common'; +import promiseLimit from 'promise-limit'; +import { DI } from '@/di-symbols.js'; import type { User } from '@/models/index.js'; +import type { Config } from '@/config.js'; import { toArray, unique } from '@/misc/prelude/array.js'; -import { DI } from '@/di-symbols.js'; import { bindThis } from '@/decorators.js'; -import type { Config } from '@/config.js'; -import { isMention, type IApMention, type IObject } from '../type.js'; -import type { ApPersonService } from './ApPersonService.js'; -import type { ApResolverService, Resolver } from '../ApResolverService.js'; +import { isMention } from '../type.js'; +import { ApResolverService, Resolver } from '../ApResolverService.js'; +import { ApPersonService } from './ApPersonService.js'; +import type { IObject, IApMention } from '../type.js'; @Injectable() export class ApMentionService { From 4522ad1ed26f407177c8ef85952d3b4cf2ab8a16 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Tue, 4 Jul 2023 14:30:48 +0900 Subject: [PATCH 92/97] Revert "cleanup(`ApNoteService.ts`): `import`" This reverts commit d8f0d769733c4cb0629821b04e557a0ae6f5ff5b. --- .../core/activitypub/models/ApNoteService.ts | 48 ++++++++++--------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApNoteService.ts b/packages/backend/src/core/activitypub/models/ApNoteService.ts index 3bc73ec6f3af..35865a819deb 100644 --- a/packages/backend/src/core/activitypub/models/ApNoteService.ts +++ b/packages/backend/src/core/activitypub/models/ApNoteService.ts @@ -1,35 +1,37 @@ -import { In } from 'typeorm'; -import promiseLimit from 'promise-limit'; import { forwardRef, Inject, Injectable } from '@nestjs/common'; +import promiseLimit from 'promise-limit'; +import { In } from 'typeorm'; +import { DI } from '@/di-symbols.js'; import type { PollsRepository, EmojisRepository } from '@/models/index.js'; +import type { Config } from '@/config.js'; import type { RemoteUser } from '@/models/entities/User.js'; import type { Note } from '@/models/entities/Note.js'; +import { toArray, toSingle, unique } from '@/misc/prelude/array.js'; import type { Emoji } from '@/models/entities/Emoji.js'; +import { MetaService } from '@/core/MetaService.js'; +import { AppLockService } from '@/core/AppLockService.js'; import type { DriveFile } from '@/models/entities/DriveFile.js'; -import { StatusError } from '@/misc/status-error.js'; -import { toArray, toSingle, unique } from '@/misc/prelude/array.js'; -import { checkHttps } from '@/misc/check-https.js'; +import { NoteCreateService } from '@/core/NoteCreateService.js'; import type Logger from '@/logger.js'; -import { DI } from '@/di-symbols.js'; +import { IdService } from '@/core/IdService.js'; +import { PollService } from '@/core/PollService.js'; +import { StatusError } from '@/misc/status-error.js'; +import { UtilityService } from '@/core/UtilityService.js'; import { bindThis } from '@/decorators.js'; -import type { UtilityService } from '@/core/UtilityService.js'; -import type { PollService } from '@/core/PollService.js'; -import type { NoteCreateService } from '@/core/NoteCreateService.js'; -import type { MetaService } from '@/core/MetaService.js'; -import type { IdService } from '@/core/IdService.js'; -import type { AppLockService } from '@/core/AppLockService.js'; -import type { Config } from '@/config.js'; -import { getOneApId, getApId, getOneApHrefNullable, validPost, isEmoji, getApType, type IObject, type IPost } from '../type.js'; -import { extractApHashtags } from './tag.js'; +import { checkHttps } from '@/misc/check-https.js'; +import { getOneApId, getApId, getOneApHrefNullable, validPost, isEmoji, getApType } from '../type.js'; +import { ApLoggerService } from '../ApLoggerService.js'; +import { ApMfmService } from '../ApMfmService.js'; +import { ApDbResolverService } from '../ApDbResolverService.js'; +import { ApResolverService } from '../ApResolverService.js'; +import { ApAudienceService } from '../ApAudienceService.js'; import { ApPersonService } from './ApPersonService.js'; -import type { ApQuestionService } from './ApQuestionService.js'; -import type { ApMentionService } from './ApMentionService.js'; -import type { ApImageService } from './ApImageService.js'; -import type { ApResolverService, Resolver } from '../ApResolverService.js'; -import type { ApMfmService } from '../ApMfmService.js'; -import type { ApLoggerService } from '../ApLoggerService.js'; -import type { ApDbResolverService } from '../ApDbResolverService.js'; -import type { ApAudienceService } from '../ApAudienceService.js'; +import { extractApHashtags } from './tag.js'; +import { ApMentionService } from './ApMentionService.js'; +import { ApQuestionService } from './ApQuestionService.js'; +import { ApImageService } from './ApImageService.js'; +import type { Resolver } from '../ApResolverService.js'; +import type { IObject, IPost } from '../type.js'; @Injectable() export class ApNoteService { From 09884375f316a7c128c5e62f4d4f207cd22c47fc Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Tue, 4 Jul 2023 14:32:33 +0900 Subject: [PATCH 93/97] Revert "cleanup(`ApPersonService.ts`): `import`" This reverts commit 5190ef954caf376da46c707f52e02208d53caafd. # Conflicts: # packages/backend/src/core/activitypub/models/ApPersonService.ts --- .../activitypub/models/ApPersonService.ts | 53 ++++++++++--------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 9e55039f6ffb..bda699854b4b 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -1,47 +1,48 @@ +import { Inject, Injectable } from '@nestjs/common'; import promiseLimit from 'promise-limit'; +import { DataSource } from 'typeorm'; import { ModuleRef } from '@nestjs/core'; -import { Inject, Injectable } from '@nestjs/common'; +import { DI } from '@/di-symbols.js'; import type { FollowingsRepository, InstancesRepository, UserProfilesRepository, UserPublickeysRepository, UsersRepository } from '@/models/index.js'; -import { UserPublickey } from '@/models/entities/UserPublickey.js'; -import { UserProfile } from '@/models/entities/UserProfile.js'; -import { UserNotePining } from '@/models/entities/UserNotePining.js'; +import type { Config } from '@/config.js'; import type { LocalUser, RemoteUser } from '@/models/entities/User.js'; import { User } from '@/models/entities/User.js'; -import type { Note } from '@/models/entities/Note.js'; import { truncate } from '@/misc/truncate.js'; -import { StatusError } from '@/misc/status-error.js'; -import { toArray } from '@/misc/prelude/array.js'; +import type { CacheService } from '@/core/CacheService.js'; import { normalizeForSearch } from '@/misc/normalize-for-search.js'; import { isDuplicateKeyValueError } from '@/misc/is-duplicate-key-value-error.js'; -import { checkHttps } from '@/misc/check-https.js'; import type Logger from '@/logger.js'; -import { DI } from '@/di-symbols.js'; -import { bindThis } from '@/decorators.js'; -import type { UserEntityService } from '@/core/entities/UserEntityService.js'; -import type { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js'; -import type UsersChart from '@/core/chart/charts/users.js'; -import type InstanceChart from '@/core/chart/charts/instance.js'; -import type { UtilityService } from '@/core/UtilityService.js'; -import type { MfmService } from '@/core/MfmService.js'; -import type { MetaService } from '@/core/MetaService.js'; +import type { Note } from '@/models/entities/Note.js'; import type { IdService } from '@/core/IdService.js'; -import type { HashtagService } from '@/core/HashtagService.js'; +import type { MfmService } from '@/core/MfmService.js'; +import { toArray } from '@/misc/prelude/array.js'; import type { GlobalEventService } from '@/core/GlobalEventService.js'; -import type { FetchInstanceMetadataService } from '@/core/FetchInstanceMetadataService.js'; import type { FederatedInstanceService } from '@/core/FederatedInstanceService.js'; -import type { CacheService } from '@/core/CacheService.js'; +import type { FetchInstanceMetadataService } from '@/core/FetchInstanceMetadataService.js'; +import { UserProfile } from '@/models/entities/UserProfile.js'; +import { UserPublickey } from '@/models/entities/UserPublickey.js'; +import type UsersChart from '@/core/chart/charts/users.js'; +import type InstanceChart from '@/core/chart/charts/instance.js'; +import type { HashtagService } from '@/core/HashtagService.js'; +import { UserNotePining } from '@/models/entities/UserNotePining.js'; +import { StatusError } from '@/misc/status-error.js'; +import type { UtilityService } from '@/core/UtilityService.js'; +import type { UserEntityService } from '@/core/entities/UserEntityService.js'; +import { bindThis } from '@/decorators.js'; +import { MetaService } from '@/core/MetaService.js'; +import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js'; import type { AccountMoveService } from '@/core/AccountMoveService.js'; -import type { Config } from '@/config.js'; +import { checkHttps } from '@/misc/check-https.js'; import { getApId, getApType, getOneApHrefNullable, isActor, isCollection, isCollectionOrOrderedCollection, isPropertyValue } from '../type.js'; import { extractApHashtags } from './tag.js'; -import type { ApNoteService } from './ApNoteService.js'; -import type { ApImageService } from './ApImageService.js'; import type { OnModuleInit } from '@nestjs/common'; -import type { DataSource } from 'typeorm'; -import type { IActor, IObject } from '../type.js'; -import type { ApResolverService, Resolver } from '../ApResolverService.js'; +import type { ApNoteService } from './ApNoteService.js'; import type { ApMfmService } from '../ApMfmService.js'; +import type { ApResolverService, Resolver } from '../ApResolverService.js'; import type { ApLoggerService } from '../ApLoggerService.js'; +// eslint-disable-next-line @typescript-eslint/consistent-type-imports +import type { ApImageService } from './ApImageService.js'; +import type { IActor, IObject } from '../type.js'; const nameLength = 128; const summaryLength = 2048; From bd2bc1c050c6649b7ba16e66b7244587bfc84ef4 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Tue, 4 Jul 2023 14:33:19 +0900 Subject: [PATCH 94/97] Revert "cleanup(`ApQuestionService.ts`): `import`" This reverts commit 778585e2882477fec5f11fabf398b4b89cf26da2. --- .../src/core/activitypub/models/ApQuestionService.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApQuestionService.ts b/packages/backend/src/core/activitypub/models/ApQuestionService.ts index e088bf2953eb..229a44f90f8e 100644 --- a/packages/backend/src/core/activitypub/models/ApQuestionService.ts +++ b/packages/backend/src/core/activitypub/models/ApQuestionService.ts @@ -1,13 +1,15 @@ import { Inject, Injectable } from '@nestjs/common'; +import { DI } from '@/di-symbols.js'; import type { NotesRepository, PollsRepository } from '@/models/index.js'; +import type { Config } from '@/config.js'; import type { IPoll } from '@/models/entities/Poll.js'; import type Logger from '@/logger.js'; -import { DI } from '@/di-symbols.js'; import { bindThis } from '@/decorators.js'; -import type { Config } from '@/config.js'; -import { isQuestion, type IObject, type IQuestion } from '../type.js'; -import type { ApResolverService, Resolver } from '../ApResolverService.js'; -import type { ApLoggerService } from '../ApLoggerService.js'; +import { isQuestion } from '../type.js'; +import { ApLoggerService } from '../ApLoggerService.js'; +import { ApResolverService } from '../ApResolverService.js'; +import type { Resolver } from '../ApResolverService.js'; +import type { IObject, IQuestion } from '../type.js'; @Injectable() export class ApQuestionService { From 99c8f7ca7dded0dcbd6bef86d71afdca83e4d347 Mon Sep 17 00:00:00 2001 From: tamaina Date: Fri, 7 Jul 2023 07:20:13 +0000 Subject: [PATCH 95/97] =?UTF-8?q?processRemoteMove=E3=81=AF=E3=81=9D?= =?UTF-8?q?=E3=81=AE=E3=81=BE=E3=81=BE=E3=81=AB=E3=81=97=E3=81=A6=E3=81=BB?= =?UTF-8?q?=E3=81=97=E3=81=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activitypub/models/ApPersonService.ts | 52 ++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index bda699854b4b..4647c5914179 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -626,42 +626,46 @@ export class ApPersonService implements OnModuleInit { * @param movePreventUris ここに列挙されたURIにsrc.movedToUriが含まれる場合、移行処理はしない(無限ループ防止) */ @bindThis - private async processRemoteMove(src: RemoteUser, movePreventUris: string[] = []): Promise { - if (src.movedToUri === null) return; // skip: no movedToUri - if (src.uri === src.movedToUri) return; // skip: movedTo itself (src) // ??? - if (movePreventUris.length > 10) return; // skip: too many moves + private async processRemoteMove(src: RemoteUser, movePreventUris: string[] = []): Promise { + if (!src.movedToUri) return 'skip: no movedToUri'; + if (src.uri === src.movedToUri) return 'skip: movedTo itself (src)'; // ??? + if (movePreventUris.length > 10) return 'skip: too many moves'; // まずサーバー内で検索して様子見 let dst = await this.fetchPerson(src.movedToUri); - if (dst) { - if (this.userEntityService.isLocalUser(dst)) { - // targetがローカルユーザーだった場合データベースから引っ張ってくる - dst = await this.usersRepository.findOneByOrFail({ uri: src.movedToUri }) as LocalUser; - } else { - if (movePreventUris.includes(src.movedToUri)) return; // skip: circular move + if (dst && this.userEntityService.isLocalUser(dst)) { + // targetがローカルユーザーだった場合データベースから引っ張ってくる + dst = await this.usersRepository.findOneByOrFail({ uri: src.movedToUri }) as LocalUser; + } else if (dst) { + if (movePreventUris.includes(src.movedToUri)) return 'skip: circular move'; - // targetを見つけたことがあるならtargetをupdatePersonする - await this.updatePerson(src.movedToUri, undefined, undefined, [...movePreventUris, src.uri]); - dst = await this.fetchPerson(src.movedToUri) ?? dst; - } + // targetを見つけたことがあるならtargetをupdatePersonする + await this.updatePerson(src.movedToUri, undefined, undefined, [...movePreventUris, src.uri]); + dst = await this.fetchPerson(src.movedToUri) ?? dst; } else { - // ローカルユーザーっぽいのにfetchPersonで見つからないということはmovedToUriが間違っている - // failed: movedTo is local but not found - if (src.movedToUri.startsWith(`${this.config.url}/`)) return; + if (src.movedToUri.startsWith(`${this.config.url}/`)) { + // ローカルユーザーっぽいのにfetchPersonで見つからないということはmovedToUriが間違っている + return 'failed: movedTo is local but not found'; + } // targetが知らない人だったらresolvePerson // (uriが存在しなかったり応答がなかったりする場合resolvePersonはthrow Errorする) dst = await this.resolvePerson(src.movedToUri); } - - if (dst.movedToUri === dst.uri) return; // skip: movedTo itself (dst) // ??? - if (src.movedToUri !== dst.uri) return; // skip: missmatch uri // ??? - if (dst.movedToUri === src.uri) return; // skip: dst.movedToUri === src.uri - if (dst.alsoKnownAs === null) return; // skip: dst.alsoKnownAs is null - if (dst.alsoKnownAs.length === 0) return; // skip: dst.alsoKnownAs is empty - if (!dst.alsoKnownAs.includes(src.uri)) return; // skip: alsoKnownAs does not include src.uri + + if (dst.movedToUri === dst.uri) return 'skip: movedTo itself (dst)'; // ??? + if (src.movedToUri !== dst.uri) return 'skip: missmatch uri'; // ??? + if (dst.movedToUri === src.uri) return 'skip: dst.movedToUri === src.uri'; + if (!dst.alsoKnownAs || dst.alsoKnownAs.length === 0) { + return 'skip: dst.alsoKnownAs is empty'; + } + if (!dst.alsoKnownAs.includes(src.uri)) { + return 'skip: alsoKnownAs does not include from.uri'; + } await this.accountMoveService.postMoveProcess(src, dst); + + return 'ok'; } } From 081df38f36aee65c0a38b55edb54ea32a86435b6 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sat, 8 Jul 2023 07:46:18 +0900 Subject: [PATCH 96/97] =?UTF-8?q?Revert=20"fixup!=20refactor(`ApPersonServ?= =?UTF-8?q?ice.ts`):=20=E8=BF=94=E3=82=8A=E5=80=A4=E3=82=92`void`=E3=81=AB?= =?UTF-8?q?=E7=B5=B1=E4=B8=80"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 083cd678abcd64325b9628895366c03b893e42ca. --- packages/backend/src/core/activitypub/ApInboxService.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/backend/src/core/activitypub/ApInboxService.ts b/packages/backend/src/core/activitypub/ApInboxService.ts index 3f47b7dc7a4b..efef777fb07e 100644 --- a/packages/backend/src/core/activitypub/ApInboxService.ts +++ b/packages/backend/src/core/activitypub/ApInboxService.ts @@ -738,11 +738,11 @@ export class ApInboxService { } @bindThis - private async move(actor: RemoteUser, activity: IMove): Promise { + private async move(actor: RemoteUser, activity: IMove): Promise { // fetch the new and old accounts const targetUri = getApHrefNullable(activity.target); - if (!targetUri) return; + if (!targetUri) return 'skip: invalid activity target'; - await this.apPersonService.updatePerson(actor.uri); + return await this.apPersonService.updatePerson(actor.uri) ?? 'skip: nothing to do'; } } From 61ba7478551aa79ded6c53fec04e9f62c0655640 Mon Sep 17 00:00:00 2001 From: okayurisotto Date: Sat, 8 Jul 2023 07:46:22 +0900 Subject: [PATCH 97/97] =?UTF-8?q?Revert=20"refactor(`ApPersonService.ts`):?= =?UTF-8?q?=20=E8=BF=94=E3=82=8A=E5=80=A4=E3=82=92`void`=E3=81=AB=E7=B5=B1?= =?UTF-8?q?=E4=B8=80"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit bfa0fcd6f01a6e519ea0c68017358f9980d2ed96. --- .../backend/src/core/activitypub/models/ApPersonService.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/core/activitypub/models/ApPersonService.ts b/packages/backend/src/core/activitypub/models/ApPersonService.ts index 4647c5914179..f72be2abeee7 100644 --- a/packages/backend/src/core/activitypub/models/ApPersonService.ts +++ b/packages/backend/src/core/activitypub/models/ApPersonService.ts @@ -393,7 +393,7 @@ export class ApPersonService implements OnModuleInit { * @param movePreventUris ここに指定されたURIがPersonのmovedToに指定されていたり10回より多く回っている場合これ以上アカウント移行を行わない(無限ループ防止) */ @bindThis - public async updatePerson(uri: string, resolver?: Resolver | null, hint?: IObject, movePreventUris: string[] = []): Promise { + public async updatePerson(uri: string, resolver?: Resolver | null, hint?: IObject, movePreventUris: string[] = []): Promise { if (typeof uri !== 'string') throw new Error('uri is not string'); // URIがこのサーバーを指しているならスキップ @@ -532,14 +532,17 @@ export class ApPersonService implements OnModuleInit { exist.movedAt.getTime() + 1000 * 60 * 60 * 24 * 14 < updated.movedAt.getTime() )) { this.logger.info(`Start to process Move of @${updated.username}@${updated.host} (${uri})`); - await this.processRemoteMove(updated, movePreventUris) + return this.processRemoteMove(updated, movePreventUris) .then(result => { this.logger.info(`Processing Move Finished [${result}] @${updated.username}@${updated.host} (${uri})`); + return result; }) .catch(e => { this.logger.info(`Processing Move Failed @${updated.username}@${updated.host} (${uri})`, { stack: e }); }); } + + return 'skip'; } /**