Files
UpdaterWebLibrary/dist/index.es.js

54 lines
1.7 KiB
JavaScript

import { parseXml } from '@rgrove/parse-xml';
class Updater {
archiveURL;
feedType;
constructor(archiveURL = "/", feedType = "rss") {
this.archiveURL = archiveURL;
this.feedType = feedType;
}
async getRawArchive() {
const res = await fetch(`${this.archiveURL}.${this.feedType}`, {
"mode": "cors"
});
const text = await res.text();
return text;
}
getVersionDetails(entry) {
let outEntry = { title: "", date: new Date, link: "", html: "" };
entry.children.forEach((elm) => {
let element = elm;
if (element.name == "title") {
outEntry.title = element.children[0].text;
}
else if (element.name == "date") {
outEntry.date = new Date(element.children[0].text);
}
else if (element.name == "link") {
outEntry.link = element.attributes["href"];
}
else if (element.name == "content") {
outEntry.html = element.children[0].text;
}
});
return outEntry;
}
async getArchive() {
const rawArchive = await this.getRawArchive();
const releaseNotes = parseXml(rawArchive);
const output = [];
// console.dir(releaseNotes)
releaseNotes.children[0].children.forEach((elm) => {
if (elm.type == "element") {
const element = elm;
if (element.name == "entry") {
output.push(this.getVersionDetails(element));
}
}
});
return output;
}
}
export { Updater as default };