From 322aeebd4572630f09d1274dddfd7376b008d6c3 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Sat, 20 Jul 2024 22:33:14 -0400 Subject: [PATCH] feat(update): migrate vuetorrent update script to typescript --- apps/update/src/app.ts | 15 ++++++++++----- apps/update/src/misc.ts | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/apps/update/src/app.ts b/apps/update/src/app.ts index 179d1f51..074e76f2 100644 --- a/apps/update/src/app.ts +++ b/apps/update/src/app.ts @@ -1,19 +1,24 @@ import { parseArgs } from './lib.ts'; import { updateFirefoxAddons } from '././firefox.ts'; -import { updateDocker } from './misc.ts'; +import { updateDocker, updateVuetorrent } from './misc.ts'; const args = parseArgs(); -if (args['f'] || args['firefox']) { - console.log(updateFirefoxAddons()); -} - if (args['d'] || args['docker']) { console.log(updateDocker()); } +if (args['f'] || args['firefox']) { + console.log(updateFirefoxAddons()); +} + +if (args['v'] || args['vuetorrent']) { + console.log(updateVuetorrent()); +} + if (args['a'] || args['all']) { + console.log(updateVuetorrent()); console.log(updateFirefoxAddons()); console.log(updateDocker()); } diff --git a/apps/update/src/misc.ts b/apps/update/src/misc.ts index 0771447a..b00afd62 100644 --- a/apps/update/src/misc.ts +++ b/apps/update/src/misc.ts @@ -1,6 +1,8 @@ -import { readdirSync } from 'node:fs'; +import { readdirSync, writeFileSync } from 'node:fs'; import { spawnSync } from 'node:child_process'; +import { parseFetchurl } from './lib.ts'; + /* Constants */ const FLAKE = process.env.FLAKE; @@ -19,3 +21,33 @@ export const updateDocker = () => { return updates; }; + +const genVueText = (version: string, hash: string, url: string) => + `# This file was autogenerated. DO NOT EDIT! +{ + version = "${version}"; + url = "${url}"; + hash = "${hash}"; +} +`; + +export const updateVuetorrent = () => { + const FILE = `${FLAKE}/devices/nos/modules/qbittorrent/vuetorrent.nix`; + + const OLD_VERSION = JSON.parse(spawnSync('nix', + ['eval', '-f', FILE, '--json'], + { shell: true }).stdout.toString()).version; + + const VERSION = JSON.parse(spawnSync('curl', + ['-s', 'https://api.github.com/repos/VueTorrent/VueTorrent/releases/latest'], + { shell: true }).stdout.toString()).tag_name.replace('v', ''); + + const URL = `https://github.com/VueTorrent/VueTorrent/releases/download/v${VERSION}/vuetorrent.zip`; + const HASH = parseFetchurl(URL); + + const fileText = genVueText(VERSION, HASH, URL); + + writeFileSync(FILE, fileText); + + return OLD_VERSION !== VERSION ? `Vuetorrent: ${OLD_VERSION} -> ${VERSION}}` : ''; +};