diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2025-05-21 19:17:51 -0400 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2025-06-12 21:11:16 -0400 |
| commit | 1a964cb6c037efe8e71c6e91e5c2ce032d22e107 (patch) | |
| tree | c3332902f6666a256b62b791b5a6df7ed0598b5f /packages/backend/src/core/WebfingerService.ts | |
| parent | merge: Emit log messages with correct level (!1097) (diff) | |
| download | sharkey-1a964cb6c037efe8e71c6e91e5c2ce032d22e107.tar.gz sharkey-1a964cb6c037efe8e71c6e91e5c2ce032d22e107.tar.bz2 sharkey-1a964cb6c037efe8e71c6e91e5c2ce032d22e107.zip | |
pcleanup dependencies:
* Consolidate multiple different HTML/XML/RSS libraries to use the Cheerio stack
* Remove unused deps
* Move dev dependencies to correct section
* Pin versions where missing
Diffstat (limited to 'packages/backend/src/core/WebfingerService.ts')
| -rw-r--r-- | packages/backend/src/core/WebfingerService.ts | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/packages/backend/src/core/WebfingerService.ts b/packages/backend/src/core/WebfingerService.ts index 664963f3a3..bb9f0be4c6 100644 --- a/packages/backend/src/core/WebfingerService.ts +++ b/packages/backend/src/core/WebfingerService.ts @@ -5,7 +5,7 @@ import { URL } from 'node:url'; import { Injectable } from '@nestjs/common'; -import { XMLParser } from 'fast-xml-parser'; +import { load as cheerio } from 'cheerio/slim'; import { HttpRequestService } from '@/core/HttpRequestService.js'; import { bindThis } from '@/decorators.js'; import type Logger from '@/logger.js'; @@ -101,14 +101,12 @@ export class WebfingerService { private async fetchWebFingerTemplateFromHostMeta(url: string): Promise<string | null> { try { const res = await this.httpRequestService.getHtml(url, 'application/xrd+xml'); - const options = { - ignoreAttributes: false, - isArray: (_name: string, jpath: string) => jpath === 'XRD.Link', - }; - const parser = new XMLParser(options); - const hostMeta = parser.parse(res); - const template = (hostMeta['XRD']['Link'] as Array<any>).filter(p => p['@_rel'] === 'lrdd')[0]['@_template']; - return template.indexOf('{uri}') < 0 ? null : template; + const hostMeta = cheerio(res, { + xml: true, + }); + + const template = hostMeta('XRD > Link[rel="lrdd"][template*="{uri}"]').attr('template'); + return template ?? null; } catch (err) { this.logger.error(`error while request host-meta for ${url}: ${renderInlineError(err)}`); return null; |