# HG changeset patch # User Guido Berhoerster # Date 1544650725 -3600 # Node ID 48cabd01ef64bf0c5a70b016341962ec98961c28 # Parent a59d322e5826fd89ec274a57662ee4e97e7ba67b Add support for enclosures in Atom feeds diff -r a59d322e5826 -r 48cabd01ef64 js/feed-parser.js --- a/js/feed-parser.js Wed Dec 12 10:56:37 2018 +0100 +++ b/js/feed-parser.js Wed Dec 12 22:38:45 2018 +0100 @@ -475,11 +475,33 @@ return this.parseAtomTextConstruct(contentElement, false); } + parseAtomEntryFile(enclosureElement) { + let type; + let size; + let url = parseURL(enclosureElement.getAttribute('href'), this.url); + if (url === null) { + throw new TypeError('invalid URL in enclosure href attribute'); + } + + let typeAttribute = enclosureElement.getAttribute('type'); + if (typeAttribute !== null) { + type = typeAttribute; + } + + let length = parseInt(enclosureElement.getAttribute('length'), 10); + if (!isNaN(length)) { + size = length; + } + + return new FeedEntryFile(url, {type, size}); + } + parseAtomEntry(entryElement) { let title; let link; let date; let content; + let files = []; let titleElement = feedQueryXPath(this.document, entryElement, './atom:title'); if (titleElement !== null) { @@ -511,7 +533,19 @@ } } - return new FeedEntry({title, link, date, content}); + for (let enclosureElement of feedQueryXPathAll(this.document, + entryElement, './atom:link[@href][@rel="enclosure"]')) { + try { + let entryFile = this.parseAtomEntryFile(enclosureElement); + files.push(entryFile); + } catch (e) { + if (!(e instanceof TypeError)) { + throw e; + } + } + } + + return new FeedEntry({title, link, date, content, files}); } parseAtomFeed() {