validate versions file

This commit is contained in:
Girish Ramakrishnan
2026-02-06 16:58:46 +01:00
parent 49d5d10d77
commit 4461e7225f
3 changed files with 17 additions and 11 deletions
+12 -6
View File
@@ -24,8 +24,10 @@ async function getAppVersion(url, version) {
if (response.status === 404) throw new BoxError(BoxError.NOT_FOUND, 'CloudronVersions.json not found');
if (response.status !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, `Fetch failed: ${response.status}`);
const versions = response.body;
if (!versions || typeof versions !== 'object') throw new BoxError(BoxError.EXTERNAL_ERROR, 'Invalid CloudronVersions.json format');
// if the content-type is incorrect, we will get a buffer
const versions = Buffer.isBuffer(response.body) ? safe.JSON.parse(response.body) : response.body;
const versionsError = manifestFormat.parseVersions(versions);
if (versionsError) throw new BoxError(BoxError.EXTERNAL_ERROR, `Invalid CloudronVersions.json: ${versionsError.message}`);
const sortedVersions = Object.keys(versions).sort(manifestFormat.packageVersionCompare);
const versionData = version === 'latest' ? versions[sortedVersions.at(-1)] : versions[version];
@@ -60,8 +62,10 @@ async function downloadManifest(versionsUrl) {
if (response.status === 404) throw new BoxError(BoxError.NOT_FOUND, 'CloudronVersions.json not found');
if (response.status !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, `Fetch failed: ${response.status}`);
const versions = response.body;
if (!versions || typeof versions !== 'object') throw new BoxError(BoxError.EXTERNAL_ERROR, 'Invalid CloudronVersions.json format');
// if the content-type is incorrect, we will get a buffer
const versions = Buffer.isBuffer(response.body) ? safe.JSON.parse(response.body) : response.body;
const versionsError = manifestFormat.parseVersions(versions);
if (versionsError) throw new BoxError(BoxError.EXTERNAL_ERROR, `Invalid CloudronVersions.json: ${versionsError.message}`);
const sortedVersions = Object.keys(versions).sort(manifestFormat.packageVersionCompare);
const versionData = version === 'latest' ? versions[sortedVersions.at(-1)] : versions[version];
@@ -81,8 +85,10 @@ async function getAppUpdate(app, options) {
if (response.status === 404) throw new BoxError(BoxError.NOT_FOUND, 'CloudronVersions.json not found');
if (response.status !== 200) throw new BoxError(BoxError.EXTERNAL_ERROR, `Fetch failed: ${response.status}`);
const versions = response.body;
if (!versions || typeof versions !== 'object') throw new BoxError(BoxError.EXTERNAL_ERROR, 'Invalid CloudronVersions.json format');
// if the content-type is incorrect, we will get a buffer
const versions = Buffer.isBuffer(response.body) ? safe.JSON.parse(response.body) : response.body;
const versionsError = manifestFormat.parseVersions(versions);
if (versionsError) throw new BoxError(BoxError.EXTERNAL_ERROR, `Invalid CloudronVersions.json: ${versionsError.message}`);
const sortedVersions = Object.keys(versions).sort(manifestFormat.packageVersionCompare);
const idx = sortedVersions.findIndex(v => v === app.manifest.version);