From 5e2a6021ae9161a32cc54173c8e3df6d26855929 Mon Sep 17 00:00:00 2001 From: syuilo <4439005+syuilo@users.noreply.github.com> Date: Sun, 30 Nov 2025 18:45:56 +0900 Subject: perf(backend): use node-html-parser instead of microformats-parser (#16907) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * perf(backend): use node-html-parser instead of microformats-parser microformats-parser は内部的に parse5 に依存していて無駄 * Update OAuth2ProviderService.ts * Add 'id' parameter to parseMicroformats function * Update OAuth2ProviderService.ts * Update OAuth2ProviderService.ts --- .../src/server/oauth/OAuth2ProviderService.ts | 48 +++++++++++++++------- 1 file changed, 34 insertions(+), 14 deletions(-) (limited to 'packages/backend/src/server/oauth/OAuth2ProviderService.ts') diff --git a/packages/backend/src/server/oauth/OAuth2ProviderService.ts b/packages/backend/src/server/oauth/OAuth2ProviderService.ts index 2b0b303b98..1c15f35399 100644 --- a/packages/backend/src/server/oauth/OAuth2ProviderService.ts +++ b/packages/backend/src/server/oauth/OAuth2ProviderService.ts @@ -17,7 +17,6 @@ import pug from 'pug'; import bodyParser from 'body-parser'; import fastifyExpress from '@fastify/express'; import { verifyChallenge } from 'pkce-challenge'; -import { mf2 } from 'microformats-parser'; import { permissions as kinds } from 'misskey-js'; import { secureRndstr } from '@/misc/secure-rndstr.js'; import { HttpRequestService } from '@/core/HttpRequestService.js'; @@ -98,6 +97,32 @@ interface ClientInformation { logo: string | null; } +function parseMicroformats(doc: htmlParser.HTMLElement, baseUrl: string, id: string): { name: string | null; logo: string | null; } { + let name: string | null = null; + let logo: string | null = null; + + const hApp = doc.querySelector('.h-app'); + if (hApp == null) return { name, logo }; + + const nameEl = hApp.querySelector('.p-name'); + if (nameEl != null) { + const href = nameEl.attributes.href || nameEl.attributes.src; + if (href != null && new URL(href, baseUrl).toString() === new URL(id).toString()) { + name = nameEl.textContent.trim(); + } + } + + const logoEl = hApp.querySelector('.u-logo'); + if (logoEl != null) { + const href = logoEl.attributes.href || logoEl.attributes.src; + if (href != null) { + logo = new URL(href, baseUrl).toString(); + } + } + + return { name, logo }; +} + // https://indieauth.spec.indieweb.org/#client-information-discovery // "Authorization servers SHOULD support parsing the [h-app] Microformat from the client_id, // and if there is an [h-app] with a url property matching the client_id URL, @@ -120,24 +145,19 @@ async function discoverClientInformation(logger: Logger, httpRequestService: Htt } const text = await res.text(); - const fragment = htmlParser.parse(`