From 39054abcbcaffb5f3c627370c86a751703dbcd94 Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Sat, 15 Jun 2024 20:20:11 +0900 Subject: [PATCH 1/6] =?UTF-8?q?fix(backend):=20=E3=83=95=E3=82=A3=E3=83=BC?= =?UTF-8?q?=E3=83=89=E3=81=AE=E3=83=8E=E3=83=BC=E3=83=88=E3=81=AEMFM?= =?UTF-8?q?=E3=81=AFHTML=E3=81=AB=E3=83=AC=E3=83=B3=E3=83=80=E3=83=BC?= =?UTF-8?q?=E3=81=97=E3=81=A6=E3=81=8B=E3=82=89=E8=BF=94=E3=81=99=20(test?= =?UTF-8?q?=20wip)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/src/server/web/FeedService.ts | 6 +++++- packages/backend/test/e2e/fetch-resource.ts | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/server/web/FeedService.ts b/packages/backend/src/server/web/FeedService.ts index 10e3ed26820c..37111eef8815 100644 --- a/packages/backend/src/server/web/FeedService.ts +++ b/packages/backend/src/server/web/FeedService.ts @@ -14,6 +14,8 @@ import { UserEntityService } from '@/core/entities/UserEntityService.js'; import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js'; import { bindThis } from '@/decorators.js'; import { IdService } from '@/core/IdService.js'; +import {MfmService} from "@/core/MfmService.js"; +import { parse as mfmParse } from 'mfm-js'; @Injectable() export class FeedService { @@ -33,6 +35,7 @@ export class FeedService { private userEntityService: UserEntityService, private driveFileEntityService: DriveFileEntityService, private idService: IdService, + private mfmService: MfmService, ) { } @@ -76,13 +79,14 @@ export class FeedService { id: In(note.fileIds), }) : []; const file = files.find(file => file.type.startsWith('image/')); + const text = note.text; feed.addItem({ title: `New note by ${author.name}`, link: `${this.config.url}/notes/${note.id}`, date: this.idService.parse(note.id).date, description: note.cw ?? undefined, - content: note.text ?? undefined, + content: text ? this.mfmService.toHtml(mfmParse(text), JSON.parse(note.mentionedRemoteUsers)) ?? undefined : undefined, image: file ? this.driveFileEntityService.getPublicUrl(file) : undefined, }); } diff --git a/packages/backend/test/e2e/fetch-resource.ts b/packages/backend/test/e2e/fetch-resource.ts index 4851ed14be6a..fd37c12fa203 100644 --- a/packages/backend/test/e2e/fetch-resource.ts +++ b/packages/backend/test/e2e/fetch-resource.ts @@ -153,6 +153,16 @@ describe('Webリソース', () => { path: path('nonexisting'), status: 404, })); + + before(() => {}); + test('のエントリはMFMを含まない。', async () => { + const content = await simpleGet(path(alice.username), "application/json"); + const a: string = content.body; + + if (a.includes("**a**")) { + throw new Error("MFM shouldn't be included"); + } + }); }); describe.each([{ path: '/api/foo' }])('$path', ({ path }) => { From 6a9ca1a2e79b05cb0cc3542752c3b70f18d39a04 Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Sat, 15 Jun 2024 20:37:58 +0900 Subject: [PATCH 2/6] =?UTF-8?q?chore:=20beforeEach=E3=82=92=E4=BD=BF?= =?UTF-8?q?=E3=81=86=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/test/e2e/fetch-resource.ts | 23 +++++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/backend/test/e2e/fetch-resource.ts b/packages/backend/test/e2e/fetch-resource.ts index fd37c12fa203..fd2bd985a7d0 100644 --- a/packages/backend/test/e2e/fetch-resource.ts +++ b/packages/backend/test/e2e/fetch-resource.ts @@ -154,15 +154,20 @@ describe('Webリソース', () => { status: 404, })); - before(() => {}); - test('のエントリはMFMを含まない。', async () => { - const content = await simpleGet(path(alice.username), "application/json"); - const a: string = content.body; - - if (a.includes("**a**")) { - throw new Error("MFM shouldn't be included"); - } - }); + describe(' has entry such ', () => { + beforeEach(() => { + post(alice, { text: "**a**" }) + }); + + test('MFMを含まない。', async () => { + const content = await simpleGet(path(alice.username), "application/json"); + const a: string = content.body; + + if (a.includes("**a**")) { + throw new Error("MFM shouldn't be included"); + } + }); + }) }); describe.each([{ path: '/api/foo' }])('$path', ({ path }) => { From cf50be480a737c5ad5f67d7036132a92ca70b185 Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Sat, 15 Jun 2024 20:58:36 +0900 Subject: [PATCH 3/6] =?UTF-8?q?fix:=20=E3=83=97=E3=83=AC=E3=83=BC=E3=83=B3?= =?UTF-8?q?=E3=83=86=E3=82=AD=E3=82=B9=E3=83=88=E3=81=AB=E3=83=95=E3=82=A9?= =?UTF-8?q?=E3=83=BC=E3=83=AB=E3=83=90=E3=83=83=E3=82=AF=E3=81=97=E3=81=A6?= =?UTF-8?q?MFM=E3=81=8C=E5=90=AB=E3=81=BE=E3=82=8C=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=81=AA=E3=81=84=E3=81=8B=E8=AA=BF=E3=81=B9=E3=82=8B=E6=96=B9?= =?UTF-8?q?=E9=87=9D=E3=82=92=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/test/e2e/fetch-resource.ts | 2 +- packages/backend/test/utils.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/backend/test/e2e/fetch-resource.ts b/packages/backend/test/e2e/fetch-resource.ts index fd2bd985a7d0..243241bc95df 100644 --- a/packages/backend/test/e2e/fetch-resource.ts +++ b/packages/backend/test/e2e/fetch-resource.ts @@ -160,7 +160,7 @@ describe('Webリソース', () => { }); test('MFMを含まない。', async () => { - const content = await simpleGet(path(alice.username), "application/json"); + const content = await simpleGet(path(alice.username), "*/*", undefined, res => res.text()); const a: string = content.body; if (a.includes("**a**")) { diff --git a/packages/backend/test/utils.ts b/packages/backend/test/utils.ts index 86814fffe0e4..aad4ab37c93c 100644 --- a/packages/backend/test/utils.ts +++ b/packages/backend/test/utils.ts @@ -17,6 +17,7 @@ import { validateContentTypeSetAsActivityPub } from '@/core/activitypub/misc/val import { entities } from '../src/postgres.js'; import { loadConfig } from '../src/config.js'; import type * as misskey from 'misskey-js'; +import { type Response } from 'node-fetch'; export { server as startServer, jobQueue as startJobQueue } from '@/boot/common.js'; @@ -454,7 +455,7 @@ export type SimpleGetResponse = { type: string | null, location: string | null }; -export const simpleGet = async (path: string, accept = '*/*', cookie: any = undefined): Promise => { +export const simpleGet = async (path: string, accept = '*/*', cookie: any = undefined, bodyExtractor: (res: Response) => Promise = _ => Promise.resolve(null)): Promise => { const res = await relativeFetch(path, { headers: { Accept: accept, @@ -482,7 +483,7 @@ export const simpleGet = async (path: string, accept = '*/*', cookie: any = unde const body = jsonTypes.includes(res.headers.get('content-type') ?? '') ? await res.json() : htmlTypes.includes(res.headers.get('content-type') ?? '') ? new JSDOM(await res.text()) : - null; + await bodyExtractor(res); return { status: res.status, From 4833680efa2ebe36bdc81296bbaf14b277e9b349 Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Sat, 15 Jun 2024 21:18:23 +0900 Subject: [PATCH 4/6] =?UTF-8?q?fix:=20application/json=E3=81=A0=E3=81=A8?= =?UTF-8?q?=E3=83=91=E3=83=BC=E3=82=B9=E3=81=95=E3=82=8C=E3=82=8B=E3=81=AE?= =?UTF-8?q?=E3=81=A7=E3=81=9D=E3=81=AE=E4=BD=9C=E7=94=A8=E3=82=92=E3=82=AD?= =?UTF-8?q?=E3=83=A3=E3=83=B3=E3=82=BB=E3=83=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/backend/test/e2e/fetch-resource.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/backend/test/e2e/fetch-resource.ts b/packages/backend/test/e2e/fetch-resource.ts index 243241bc95df..7efd688ec279 100644 --- a/packages/backend/test/e2e/fetch-resource.ts +++ b/packages/backend/test/e2e/fetch-resource.ts @@ -161,9 +161,11 @@ describe('Webリソース', () => { test('MFMを含まない。', async () => { const content = await simpleGet(path(alice.username), "*/*", undefined, res => res.text()); - const a: string = content.body; + const _body: unknown = content.body; + // JSONフィードのときは改めて文字列化する + const body: string = typeof (_body) === "object" ? JSON.stringify(_body) : _body as string; - if (a.includes("**a**")) { + if (body.includes("**a**")) { throw new Error("MFM shouldn't be included"); } }); From 5ca3b53b64e8ef6fcbe5f3dcd33cff56faf1f2fb Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Sat, 15 Jun 2024 21:19:02 +0900 Subject: [PATCH 5/6] build: fix lint error --- packages/backend/src/server/web/FeedService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/backend/src/server/web/FeedService.ts b/packages/backend/src/server/web/FeedService.ts index 37111eef8815..9d810ddc846b 100644 --- a/packages/backend/src/server/web/FeedService.ts +++ b/packages/backend/src/server/web/FeedService.ts @@ -14,7 +14,7 @@ import { UserEntityService } from '@/core/entities/UserEntityService.js'; import { DriveFileEntityService } from '@/core/entities/DriveFileEntityService.js'; import { bindThis } from '@/decorators.js'; import { IdService } from '@/core/IdService.js'; -import {MfmService} from "@/core/MfmService.js"; +import { MfmService } from "@/core/MfmService.js"; import { parse as mfmParse } from 'mfm-js'; @Injectable() From 9b32b08ab3c7aba659280ce3f3f1d9bf26ed42b6 Mon Sep 17 00:00:00 2001 From: Kisaragi Marine Date: Sat, 15 Jun 2024 21:34:53 +0900 Subject: [PATCH 6/6] docs: update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76fed76b5651..aeb87a214483 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ ### Server - チャート生成時にinstance.suspentionStateに置き換えられたinstance.isSuspendedが参照されてしまう問題を修正 - Feat: レートリミット制限に引っかかったときに`Retry-After`ヘッダーを返すように (#13949) +- Fix: ユーザーのフィードページのMFMをHTMLに展開するように (#14006) ## 2024.5.0