summaryrefslogtreecommitdiffstats
path: root/extra/download-apprise.mjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel@debian.org>2024-11-26 09:28:28 +0100
committerDaniel Baumann <daniel@debian.org>2024-11-26 12:25:58 +0100
commita1882b67c41fe9901a0cd8059b5cc78a5beadec0 (patch)
tree2a24507c67aa99a15416707b2f7e645142230ed8 /extra/download-apprise.mjs
parentInitial commit. (diff)
downloaduptime-kuma-a1882b67c41fe9901a0cd8059b5cc78a5beadec0.tar.xz
uptime-kuma-a1882b67c41fe9901a0cd8059b5cc78a5beadec0.zip
Adding upstream version 2.0.0~beta.0+dfsg.upstream/2.0.0_beta.0+dfsgupstream
Signed-off-by: Daniel Baumann <daniel@debian.org>
Diffstat (limited to 'extra/download-apprise.mjs')
-rw-r--r--extra/download-apprise.mjs57
1 files changed, 57 insertions, 0 deletions
diff --git a/extra/download-apprise.mjs b/extra/download-apprise.mjs
new file mode 100644
index 0000000..3d31f7c
--- /dev/null
+++ b/extra/download-apprise.mjs
@@ -0,0 +1,57 @@
+// Go to http://ftp.debian.org/debian/pool/main/a/apprise/ using fetch api, where it is a apache directory listing page
+// Use cheerio to parse the html and get the latest version of Apprise
+// call curl to download the latest version of Apprise
+// Target file: the latest version of Apprise, which the format is apprise_{VERSION}_all.deb
+
+import * as cheerio from "cheerio";
+import semver from "semver";
+import * as childProcess from "child_process";
+
+const baseURL = "http://ftp.debian.org/debian/pool/main/a/apprise/";
+const response = await fetch(baseURL);
+
+if (!response.ok) {
+ throw new Error("Failed to fetch page of Apprise Debian repository.");
+}
+
+const html = await response.text();
+
+const $ = cheerio.load(html);
+
+// Get all the links in the page
+const linkElements = $("a");
+
+// Filter the links which match apprise_{VERSION}_all.deb
+const links = [];
+const pattern = /apprise_(.*?)_all.deb/;
+
+for (let i = 0; i < linkElements.length; i++) {
+ const link = linkElements[i];
+ if (link.attribs.href.match(pattern) && !link.attribs.href.includes("~")) {
+ links.push({
+ filename: link.attribs.href,
+ version: link.attribs.href.match(pattern)[1],
+ });
+ }
+}
+
+console.log(links);
+
+// semver compare and download
+let latestLink = {
+ filename: "",
+ version: "0.0.0",
+};
+
+for (const link of links) {
+ if (semver.gt(link.version, latestLink.version)) {
+ latestLink = link;
+ }
+}
+
+const downloadURL = baseURL + latestLink.filename;
+console.log(`Downloading ${downloadURL}...`);
+let result = childProcess.spawnSync("curl", [ downloadURL, "--output", "apprise.deb" ]);
+console.log(result.stdout?.toString());
+console.error(result.stderr?.toString());
+process.exit(result.status !== null ? result.status : 1);