aboutsummaryrefslogtreecommitdiff
path: root/hooks/update.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-02-12 10:33:06 +0100
committerMinteck <contact@minteck.org>2022-02-12 10:33:06 +0100
commit01160246e4a0c0052181c72a53737e356ea7d02d (patch)
treec6f8ea675f9147d4c06ef503697fb35d58493991 /hooks/update.js
parentaf898a152a14e31bdbcbbedb952ad333697553ef (diff)
downloadtwilight-01160246e4a0c0052181c72a53737e356ea7d02d.tar.gz
twilight-01160246e4a0c0052181c72a53737e356ea7d02d.tar.bz2
twilight-01160246e4a0c0052181c72a53737e356ea7d02d.zip
First commit
Diffstat (limited to 'hooks/update.js')
-rw-r--r--hooks/update.js69
1 files changed, 69 insertions, 0 deletions
diff --git a/hooks/update.js b/hooks/update.js
new file mode 100644
index 0000000..f871889
--- /dev/null
+++ b/hooks/update.js
@@ -0,0 +1,69 @@
+module.exports = async () => {
+ const spinner = ora("Fetching package lists...").start();
+ let list = (await axios.get("https://twipkg.cdn.minteck.org/packages.json")).data;
+
+ if (fs.existsSync(home + "/repository")) {
+ fs.rmSync(home + "/repository", { recursive: true });
+ }
+ fs.mkdirSync(home + "/repository");
+
+ fs.writeFileSync(home + "/repository/list.json", JSON.stringify(list));
+
+ let index = 0;
+ for (let pkg of list) {
+ spinner.text = "Fetching package lists... " + Math.round((index / list.length) * 100) + "%";
+ let dir = pkg.substring(0, 1).replace(/[^a-zA-Z0-9]/gm, "#");
+ let pack = (await axios.get("https://twipkg.cdn.minteck.org/" + dir + "/" + pkg + ".json")).data;
+
+ let verdata = (await axios.get(pack.version)).data;
+ pack.verdata = {
+ latest: verdata.commit.short_id,
+ publisher: {
+ name: verdata.commit.author_name,
+ email: verdata.commit.author_email
+ },
+ date: verdata.commit.created_at
+ }
+
+ let signRaw = { error: "404 Not Found" };
+ try {
+ signRaw = (await axios.get(pack.signature.replace("{version}", verdata.commit.id))).data;
+ } catch (e) {}
+ pack.sign = {
+ signed: false,
+ verified: false,
+ key: null,
+ signer: {
+ name: null,
+ email: null
+ }
+ }
+ if (signRaw.error !== "404 Not Found") {
+ pack.sign.signed = true;
+ if (signRaw.verification_status === "verified") {
+ pack.sign.verified = true;
+ } else {
+ pack.sign.verified = false;
+ }
+ if (signRaw.gpg_key_user_name) {
+ pack.sign.signer.name = signRaw.gpg_key_user_name;
+ }
+ if (signRaw.gpg_key_user_email) {
+ pack.sign.signer.email = signRaw.gpg_key_user_email;
+ }
+ if (signRaw.gpg_key_primary_keyid) {
+ pack.sign.key = signRaw.gpg_key_primary_keyid;
+ }
+ }
+
+ if (!fs.existsSync(home + "/repository/" + dir)) {
+ fs.mkdirSync(home + "/repository/" + dir);
+ }
+ fs.writeFileSync(home + "/repository/" + dir + "/" + pkg + ".json", JSON.stringify(pack));
+
+ index++;
+ }
+
+ spinner.succeed("Fetching package lists... done");
+ //process.exit();
+} \ No newline at end of file