fix(update): verify and apply the actual latest version

This commit is contained in:
Sucukdeluxe
2026-08-21 07:39:37 +02:00
parent 4cebc6fefd
commit 6efdca6885
10 changed files with 154 additions and 41 deletions
+16 -4
View File
@@ -4,7 +4,8 @@ import crypto from "node:crypto";
import os from "node:os";
import { spawnSync } from "node:child_process";
import { fileURLToPath } from "node:url";
import { parse } from "yaml";
import { parse } from "yaml";
import { extractFile } from "@electron/asar";
const EXPECTED_PUBLISH = Object.freeze({
provider: "github",
@@ -112,7 +113,7 @@ function requireNonEmptyFile(filePath, label) {
return stat;
}
function sha256NormalizedText(filePath) {
function sha256NormalizedText(filePath) {
const normalized = fs.readFileSync(filePath, "utf8").replace(/\r\n/g, "\n").replace(/\r/g, "\n");
return crypto.createHash("sha256").update(normalized, "utf8").digest("hex");
}
@@ -140,6 +141,14 @@ function hasExtraResource(extraResources, expected) {
));
}
function readPackagedMainVersion(asarPath) {
requireNonEmptyFile(asarPath, "packaged app.asar");
const packagePayload = JSON.parse(extractFile(asarPath, "package.json").toString("utf8"));
const mainBundle = extractFile(asarPath, path.win32.join("build", "main", "main", "main.js")).toString("utf8");
const bundled = /name:\s*["']multi-debrid-downloader["']\s*,\s*version:\s*["']([^"']+)["']/.exec(mainBundle)?.[1] || "";
return { packageVersion: String(packagePayload?.version || ""), bundledVersion: bundled };
}
function sha256File(filePath) {
return crypto.createHash("sha256").update(fs.readFileSync(filePath)).digest("hex");
}
@@ -321,10 +330,13 @@ export function verifyPublicRelease(rootDir = process.cwd()) {
assertEqual(appUpdateFields.owner, EXPECTED_PUBLISH.owner, "app-update.yml owner");
assertEqual(appUpdateFields.repo, EXPECTED_PUBLISH.repo, "app-update.yml repo");
const expectedSetup = `${EXPECTED_PRODUCT_NAME}-Setup-${version}.exe`;
const expectedSetup = `${EXPECTED_PRODUCT_NAME}-Setup-${version}.exe`;
const expectedPortable = `${EXPECTED_PRODUCT_NAME}-${version}-portable.exe`;
const expectedBlockmap = `${expectedSetup}.blockmap`;
assertEqual(latestFields.path, expectedSetup, "latest.yml path");
assertEqual(latestFields.path, expectedSetup, "latest.yml path");
const packagedVersions = readPackagedMainVersion(path.join(releaseDir, "win-unpacked", "resources", "app.asar"));
assertEqual(packagedVersions.packageVersion, version, "packaged package version");
assertEqual(packagedVersions.bundledVersion, version, "packaged main bundle version");
const requiredArtifacts = [expectedSetup, expectedPortable, expectedBlockmap];
const missingArtifacts = requiredArtifacts.filter((fileName) => !fs.existsSync(path.join(releaseDir, fileName)));