From 0e6b704af1432dc509a6e080ded915ffc02376c3 Mon Sep 17 00:00:00 2001 From: Rory& Date: Sat, 14 Mar 2026 03:39:14 +0100 Subject: [PATCH] Remove unused autoupdater code --- .../SecurityConfiguration.cs | 3 - .../config/types/SecurityConfiguration.ts | 1 - src/util/util/AutoUpdate.ts | 90 ------------------- 3 files changed, 94 deletions(-) delete mode 100644 src/util/util/AutoUpdate.ts diff --git a/extra/admin-api/Models/Spacebar.Models.Config/SecurityConfiguration.cs b/extra/admin-api/Models/Spacebar.Models.Config/SecurityConfiguration.cs index e1592c8d4..88681d2df 100644 --- a/extra/admin-api/Models/Spacebar.Models.Config/SecurityConfiguration.cs +++ b/extra/admin-api/Models/Spacebar.Models.Config/SecurityConfiguration.cs @@ -9,9 +9,6 @@ public class SecurityConfiguration { [JsonPropertyName("twoFactor")] public TwoFactorConfiguration TwoFactor { get; set; } = new(); - [JsonPropertyName("autoUpdate")] - public bool AutoUpdate { get; set; } = true; - [JsonPropertyName("requestSignature")] public string RequestSignature; // {get;set;}=crypto.randomBytes(32).toString("base64"); [JsonPropertyName("jwtSecret")] diff --git a/src/util/config/types/SecurityConfiguration.ts b/src/util/config/types/SecurityConfiguration.ts index 7a15f8986..10900c58d 100644 --- a/src/util/config/types/SecurityConfiguration.ts +++ b/src/util/config/types/SecurityConfiguration.ts @@ -22,7 +22,6 @@ import { CaptchaConfiguration, TwoFactorConfiguration } from "."; export class SecurityConfiguration { captcha: CaptchaConfiguration = new CaptchaConfiguration(); twoFactor: TwoFactorConfiguration = new TwoFactorConfiguration(); - autoUpdate: boolean | number = true; requestSignature: string = crypto.randomBytes(32).toString("base64"); jwtSecret: string | null = null; // header to get the real user ip address diff --git a/src/util/util/AutoUpdate.ts b/src/util/util/AutoUpdate.ts deleted file mode 100644 index d9fe93a3d..000000000 --- a/src/util/util/AutoUpdate.ts +++ /dev/null @@ -1,90 +0,0 @@ -/* - Spacebar: A FOSS re-implementation and extension of the Discord.com backend. - Copyright (C) 2023 Spacebar and Spacebar Contributors - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published - by the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -import readline from "readline"; -import fs from "fs/promises"; -import path from "path"; - -const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout, -}); - -export function enableAutoUpdate(opts: { checkInterval: number | boolean; packageJsonLink: string; path: string; downloadUrl: string; downloadType?: "zip" }) { - if (!opts.checkInterval) return; - const interval = 1000 * 60 * 60 * 24; - if (typeof opts.checkInterval === "number") opts.checkInterval = 1000 * interval; - - const i = setInterval(async () => { - const currentVersion = await getCurrentVersion(opts.path); - const latestVersion = await getLatestVersion(opts.packageJsonLink); - if (currentVersion !== latestVersion) { - clearInterval(i); - console.log(`[Auto Update] Current version (${currentVersion}) is out of date, updating ...`); - await download(opts.downloadUrl, opts.path); - } - }, interval); - setImmediate(async () => { - const currentVersion = await getCurrentVersion(opts.path); - const latestVersion = await getLatestVersion(opts.packageJsonLink); - if (currentVersion !== latestVersion) { - rl.question(`[Auto Update] Current version (${currentVersion}) is out of date, would you like to update? (Y/n)`, (answer) => { - if (answer === "" || answer.toLowerCase() === "y") { - console.log(`[Auto update] updating ...`); - download(opts.downloadUrl, opts.path); - } else { - console.log(`[Auto update] aborted`); - } - }); - } - }); -} - -async function download(url: string, dir: string) { - try { - // TODO: use file stream instead of buffer (to prevent crash because of high memory usage for big files) - // TODO check file hash - const response = await fetch(url); - const buffer = await response.bytes(); - const tempDir = await fs.mkdtemp("spacebar"); - await fs.writeFile(path.join(tempDir, "Spacebar.zip"), buffer); - } catch (error) { - console.error(`[Auto Update] download failed`, error); - } -} - -async function getCurrentVersion(dir: string) { - try { - const content = await fs.readFile(path.join(dir, "package.json"), { - encoding: "utf8", - }); - return JSON.parse(content).version; - } catch (error) { - throw new Error("[Auto update] couldn't get current version in " + dir); - } -} - -async function getLatestVersion(url: string) { - try { - const response = await fetch(url); - const content = (await response.json()) as { version: string }; - return content.version; - } catch (error) { - throw new Error("[Auto update] check failed for " + url); - } -}