feat: Implement update management refactor with new dialog and settings handling

This commit is contained in:
2026-05-24 22:31:18 +02:00
parent 54ab1fcb9f
commit c8e2edc0c0
6 changed files with 368 additions and 121 deletions
+34
View File
@@ -0,0 +1,34 @@
import fs from "node:fs";
import path from "node:path";
import { Readable } from "node:stream";
import { ReleaseUpdate, sanitizeFileName } from "./update-utils";
type UpdateDownloadConfig = {
tempDirectory: string;
};
export async function downloadInstaller(update: ReleaseUpdate, config: UpdateDownloadConfig): Promise<string> {
const safeFileName = sanitizeFileName(update.installer.name);
const downloadDirectory = path.join(config.tempDirectory, "scoreko-updates");
const targetPath = path.join(downloadDirectory, safeFileName);
fs.mkdirSync(downloadDirectory, { recursive: true });
const response = await fetch(update.installer.downloadUrl);
if (!response.ok || !response.body) {
throw new Error(`Could not download update installer. HTTP ${response.status}.`);
}
await new Promise<void>((resolve, reject) => {
const fileStream = fs.createWriteStream(targetPath);
const responseStream = Readable.fromWeb(response.body as Parameters<typeof Readable.fromWeb>[0]);
responseStream.on("error", reject);
fileStream.on("error", reject);
fileStream.on("finish", resolve);
responseStream.pipe(fileStream);
});
return targetPath;
}