functional initial version
This commit is contained in:
45
src/index.ts
45
src/index.ts
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user