diff --git a/package-lock.json b/package-lock.json index 4d093e5ac..ed0dae943 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@aws-sdk/client-s3": "^3.974.0", "@aws-sdk/lib-storage": "^3.974.0", "@cloudron/connect-lastmile": "^2.3.0", - "@cloudron/manifest-format": "^5.31.0", + "@cloudron/manifest-format": "^5.32.1", "@cloudron/pipework": "^1.2.0", "@cloudron/superagent": "^1.0.1", "@google-cloud/dns": "^5.3.1", @@ -1291,9 +1291,9 @@ "license": "MIT" }, "node_modules/@cloudron/manifest-format": { - "version": "5.31.0", - "resolved": "https://registry.npmjs.org/@cloudron/manifest-format/-/manifest-format-5.31.0.tgz", - "integrity": "sha512-WzmUzKWyvtv3iR4dw2fyCbltgMk0dSTol7pAER47XZ4HTsJuQ4dpbR5/tFJ11P4DZudUJErOTf0nBkz50foQCA==", + "version": "5.32.1", + "resolved": "https://registry.npmjs.org/@cloudron/manifest-format/-/manifest-format-5.32.1.tgz", + "integrity": "sha512-dq54lx/YMO1TOoFfdZTArgU3UH+WOz57z8Tcafc09d82iKB40grZSVsT1AWuY+yw5aXbo8V0r5P9nDx/qzMejw==", "license": "MIT", "dependencies": { "ajv": "^8.17.1", diff --git a/package.json b/package.json index 18592de72..0f5614d5f 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "@aws-sdk/client-s3": "^3.974.0", "@aws-sdk/lib-storage": "^3.974.0", "@cloudron/connect-lastmile": "^2.3.0", - "@cloudron/manifest-format": "^5.31.0", + "@cloudron/manifest-format": "^5.32.1", "@cloudron/pipework": "^1.2.0", "@cloudron/superagent": "^1.0.1", "@google-cloud/dns": "^5.3.1", diff --git a/src/community.js b/src/community.js index fab1deab0..96875f552 100644 --- a/src/community.js +++ b/src/community.js @@ -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);