functional initial version
This commit is contained in:
41
dist/index.cjs.js
vendored
41
dist/index.cjs.js
vendored
@@ -1,5 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
var parseXml = require('@rgrove/parse-xml');
|
||||
|
||||
class Updater {
|
||||
archiveURL;
|
||||
feedType;
|
||||
@@ -7,11 +9,46 @@ class Updater {
|
||||
this.archiveURL = archiveURL;
|
||||
this.feedType = feedType;
|
||||
}
|
||||
async getArchive() {
|
||||
async getRawArchive() {
|
||||
const res = await fetch(`${this.archiveURL}.${this.feedType}`, {
|
||||
"mode": "cors"
|
||||
});
|
||||
return res;
|
||||
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.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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user