validate versions file
This commit is contained in:
+12
-6
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user