functional initial version

This commit is contained in:
2025-10-30 16:19:38 +00:00
parent 0bcba44b1d
commit 7893dce549
10 changed files with 155 additions and 12 deletions

View File

@@ -1,3 +1,6 @@
import * as types from "@/types";
import { parseXml, XmlDocument, XmlElement, XmlText } from "@rgrove/parse-xml";
export default class Updater {
public archiveURL: string;
public feedType: string;
@@ -6,11 +9,49 @@ export default class Updater {
this.feedType = feedType;
}
async getArchive(): Promise<Response> {
private async getRawArchive(): Promise<string> {
const res = await fetch(`${this.archiveURL}.${this.feedType}`, {
"mode": "cors"
});
return res;
const text = await res.text();
return text;
}
private getVersionDetails(entry: XmlElement): types.versionNotes {
let outEntry: types.versionNotes = {title: "", date: new Date, link: "", html: ""};
entry.children.forEach((elm) => {
let element = elm as XmlElement;
if (element.name == "title") {
outEntry.title = (element.children[0] as XmlText).text;
}
else if (element.name == "date") {
outEntry.date = new Date((element.children[0] as XmlText).text);
}
else if (element.name == "link") {
outEntry.link = element.attributes["href"];
} else if (element.name == "content") {
outEntry.html = (element.children[0] as XmlText).text;
}
})
return outEntry;
}
public async getArchive(): Promise<types.versionNotes[]> {
const rawArchive: string = await this.getRawArchive();
const releaseNotes: XmlDocument = parseXml(rawArchive);
const output: types.versionNotes[] = [];
// console.dir(releaseNotes)
(releaseNotes.children[0] as XmlElement).children.forEach((elm) => {
if (elm.type == "element") {
const element = elm as XmlElement;
if (element.name == "entry") {
output.push(this.getVersionDetails(element))
}
}
});
return output;
}
}