18 lines
825 B
JavaScript
18 lines
825 B
JavaScript
import { decodeXmlEntities } from '#import-recipes/odt/decodeXmlEntities.js'
|
|
|
|
// Namespace prefixes vary between servers (d:href, D:href, href).
|
|
const HREF_PATTERN = /<(?:[a-zA-Z0-9]+:)?href>([^<]*)<\/(?:[a-zA-Z0-9]+:)?href>/g
|
|
|
|
// The .odt entries of a PROPFIND answer, as the paths the server gave them -
|
|
// still percent-encoded, because that is what we send back on the GET. Read by
|
|
// regular expression on purpose: this is a one-shot download helper, Node has no
|
|
// DOMParser, and Nextcloud's PROPFIND answer is stable.
|
|
export function listOdtHrefs(xmlText) {
|
|
if (typeof xmlText !== 'string') return []
|
|
const hrefs = []
|
|
for (const [, rawHref] of xmlText.matchAll(HREF_PATTERN)) {
|
|
const href = decodeXmlEntities(rawHref).trim()
|
|
if (href.toLowerCase().endsWith('.odt')) hrefs.push(href)
|
|
}
|
|
return hrefs
|
|
}
|