1
0

refactor link verification.

This commit is contained in:
piuvas
2025-04-19 23:04:48 -03:00
parent f24be3674a
commit 6a77512737
2 changed files with 44 additions and 1 deletions
@@ -0,0 +1,32 @@
/*
* SPDX-FileCopyrightText: piuvas and other Sharkey contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { JSDOM } from 'jsdom';
import { HttpRequestService } from '@/core/HttpRequestService.js';
import { safeForSql } from './safe-for-sql.js';
export async function verifyFieldLink(field_url: string, profile_url: string, httpRequestService: HttpRequestService): Promise<boolean | undefined> {
if (!safeForSql(field_url)) return;
try {
const html = await httpRequestService.getHtml(field_url);
const { window } = new JSDOM(html);
const doc: Document = window.document;
const aEls = Array.from(doc.getElementsByTagName('a'));
const linkEls = Array.from(doc.getElementsByTagName('link'));
const includesProfileLinks = [...aEls, ...linkEls].some(link => link.rel === 'me' && link.href === profile_url);
window.close();
return includesProfileLinks;
} catch (err) {
// なにもしない
return;
}
}