fix(backend): happy-domで外部HTMLをパースする際に関連リソースが読み込まれる問題を修正 (#14521)

cherry picked from commit be0906a6c73726ed02a358bcbe904fa3d99713ea

Co-authored-by: かっこかり <67428053+kakkokari-gtyih@users.noreply.github.com>
This commit is contained in:
かっこかり 2024-09-15 12:30:27 +09:00 committed by あわわわとーにゅ
parent 9e998cc10b
commit c441c4728f
No known key found for this signature in database
GPG key ID: 6AFBBF529601C1DB

View file

@ -206,14 +206,18 @@ export class ApRequestService {
if ((contentType ?? '').split(';')[0].trimEnd().toLowerCase() === 'text/html' && _followAlternate) { if ((contentType ?? '').split(';')[0].trimEnd().toLowerCase() === 'text/html' && _followAlternate) {
const html = await res.text(); const html = await res.text();
const fragment = JSDOM.fragment(html); try {
const fragment = JSDOM.fragment(html);
const alternate = fragment.querySelector('head > link[rel="alternate"][type="application/activity+json"]'); const alternate = fragment.querySelector('head > link[rel="alternate"][type="application/activity+json"]');
if (alternate) { if (alternate) {
const href = alternate.getAttribute('href'); const href = alternate.getAttribute('href');
if (href) { if (href) {
return await this.signedGet(href, user, false); return await this.signedGet(href, user, false);
}
} }
} catch (e) {
// something went wrong parsing the HTML, ignore the whole thing
} }
} }
//#endregion //#endregion