From e3484644d1db65885090f2c4ca07f5064151ece7 Mon Sep 17 00:00:00 2001 From: chopster44 Date: Thu, 30 Oct 2025 22:56:11 +0000 Subject: [PATCH] forgot to build --- dist/index.cjs.js | 53 ++++++++++++++++++++++++++++++++++++++++++----- dist/index.d.ts | 5 ++++- dist/index.es.js | 53 ++++++++++++++++++++++++++++++++++++++++++----- dist/types.d.ts | 2 +- 4 files changed, 101 insertions(+), 12 deletions(-) diff --git a/dist/index.cjs.js b/dist/index.cjs.js index 41d5ded..255e35a 100644 --- a/dist/index.cjs.js +++ b/dist/index.cjs.js @@ -5,18 +5,19 @@ var parseXml = require('@rgrove/parse-xml'); class Updater { archiveURL; feedType; - constructor(archiveURL = "/", feedType = "rss") { + constructor(archiveURL = "/", feedType = "atom") { this.archiveURL = archiveURL; this.feedType = feedType; } async getRawArchive() { - const res = await fetch(`${this.archiveURL}.${this.feedType}`, { + const res = await fetch(`https://cors.emaker.limited/?url=${this.archiveURL}.${this.feedType}`, { "mode": "cors" }); const text = await res.text(); return text; } - getVersionDetails(entry) { + // atom feeds + atomGetVersionDetails(entry) { let outEntry = { title: "", date: new Date, link: "", html: "" }; entry.children.forEach((elm) => { let element = elm; @@ -35,7 +36,7 @@ class Updater { }); return outEntry; } - async getArchive() { + async atomGetArchive() { const rawArchive = await this.getRawArchive(); const releaseNotes = parseXml.parseXml(rawArchive); const output = []; @@ -44,12 +45,54 @@ class Updater { if (elm.type == "element") { const element = elm; if (element.name == "entry") { - output.push(this.getVersionDetails(element)); + output.push(this.atomGetVersionDetails(element)); } } }); return output; } + // rss feeds + rssGetVersionDetails(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 == "pubDate") { + outEntry.date = element.children[0].text; + } + else if (element.name == "link") { + outEntry.link = element.children[0].text; + } + else if (element.name == "content") { + outEntry.html = element.children[0].text; + } + }); + return outEntry; + } + async rssGetArchive() { + const rawArchive = await this.getRawArchive(); + const releaseNotes = parseXml.parseXml(rawArchive); + const output = []; + releaseNotes.children[0].children[1].children.forEach((elm) => { + if (elm.type == "element") { + const element = elm; + if (element.name == "item") { + output.push(this.atomGetVersionDetails(element)); + } + } + }); + return output; + } + async getArchive() { + if (this.feedType == "atom") { + return this.atomGetArchive(); + } + else if (this.feedType == "rss") { + return this.rssGetArchive(); + } + } } module.exports = Updater; diff --git a/dist/index.d.ts b/dist/index.d.ts index bed6749..fb199e9 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -4,6 +4,9 @@ export default class Updater { feedType: string; constructor(archiveURL?: string, feedType?: string); private getRawArchive; - private getVersionDetails; + private atomGetVersionDetails; + private atomGetArchive; + private rssGetVersionDetails; + private rssGetArchive; getArchive(): Promise; } diff --git a/dist/index.es.js b/dist/index.es.js index 1b032e9..83cae78 100644 --- a/dist/index.es.js +++ b/dist/index.es.js @@ -3,18 +3,19 @@ import { parseXml } from '@rgrove/parse-xml'; class Updater { archiveURL; feedType; - constructor(archiveURL = "/", feedType = "rss") { + constructor(archiveURL = "/", feedType = "atom") { this.archiveURL = archiveURL; this.feedType = feedType; } async getRawArchive() { - const res = await fetch(`${this.archiveURL}.${this.feedType}`, { + const res = await fetch(`https://cors.emaker.limited/?url=${this.archiveURL}.${this.feedType}`, { "mode": "cors" }); const text = await res.text(); return text; } - getVersionDetails(entry) { + // atom feeds + atomGetVersionDetails(entry) { let outEntry = { title: "", date: new Date, link: "", html: "" }; entry.children.forEach((elm) => { let element = elm; @@ -33,7 +34,7 @@ class Updater { }); return outEntry; } - async getArchive() { + async atomGetArchive() { const rawArchive = await this.getRawArchive(); const releaseNotes = parseXml(rawArchive); const output = []; @@ -42,12 +43,54 @@ class Updater { if (elm.type == "element") { const element = elm; if (element.name == "entry") { - output.push(this.getVersionDetails(element)); + output.push(this.atomGetVersionDetails(element)); } } }); return output; } + // rss feeds + rssGetVersionDetails(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 == "pubDate") { + outEntry.date = element.children[0].text; + } + else if (element.name == "link") { + outEntry.link = element.children[0].text; + } + else if (element.name == "content") { + outEntry.html = element.children[0].text; + } + }); + return outEntry; + } + async rssGetArchive() { + const rawArchive = await this.getRawArchive(); + const releaseNotes = parseXml(rawArchive); + const output = []; + releaseNotes.children[0].children[1].children.forEach((elm) => { + if (elm.type == "element") { + const element = elm; + if (element.name == "item") { + output.push(this.atomGetVersionDetails(element)); + } + } + }); + return output; + } + async getArchive() { + if (this.feedType == "atom") { + return this.atomGetArchive(); + } + else if (this.feedType == "rss") { + return this.rssGetArchive(); + } + } } export { Updater as default }; diff --git a/dist/types.d.ts b/dist/types.d.ts index e554c94..a871e56 100644 --- a/dist/types.d.ts +++ b/dist/types.d.ts @@ -1,6 +1,6 @@ export type versionNotes = { title: string; - date: Date; + date: Date | string; link: string; html: string; };