diff --git a/__tests__/platforms.js b/__tests__/platforms.js index 103e17c7..a66a9b92 100644 --- a/__tests__/platforms.js +++ b/__tests__/platforms.js @@ -52,6 +52,18 @@ describe("Platforms", function () { ) }) + test("should detect AppImage_32", function () { + expect(platforms.detect("appimaged-i686.AppImage")).toEqual( + platforms.LINUX_APPIMAGE_32, + ) + }) + + test("should detect AppImage_64", function () { + expect(platforms.detect("appimaged-x86_64.AppImage")).toEqual( + platforms.LINUX_APPIMAGE_64, + ) + }) + test("should detect debian_32", function () { expect(platforms.detect("atom-ia32.deb")).toEqual(platforms.LINUX_DEB_32) }) @@ -121,6 +133,24 @@ describe("Platforms", function () { "https://api.github.com/repos/atom/atom/releases/assets/825658", download_count: 2494, }, + { + type: "linux_AppImage_32", + filename: "appimaged-i686.AppImage", + size: 244728, + content_type: "application/octet-stream", + download_url: + "https://api.github.com/repos/AppImage/AppImageKit/releases/assets/5295931", + download_count: 55, + }, + { + type: "linux_AppImage_64", + filename: "appimaged-x86_64.AppImage", + size: 244728, + content_type: "application/octet-stream", + download_url: + "https://api.github.com/repos/AppImage/AppImageKit/releases/assets/5295938", + download_count: 55, + }, { type: "linux_rpm_32", filename: "atom-ia32.rpm", @@ -194,6 +224,13 @@ describe("Platforms", function () { expect(platforms.resolve(version, "linux_rpm_32").filename).toEqual( "atom-ia32.rpm", ) + expect( + platforms.resolve(version, "linux_AppImage_32").filename, + ).toEqual("appimaged-i686.AppImage") + + expect( + platforms.resolve(version, "linux_AppImage_64").filename, + ).toEqual("appimaged-x86_64.AppImage") expect(platforms.resolve(version, "linux_rpm_64").filename).toEqual( "atom-amd64.rpm", ) diff --git a/__tests__/update.js b/__tests__/update.js index 9b11b358..05782ec0 100644 --- a/__tests__/update.js +++ b/__tests__/update.js @@ -17,6 +17,7 @@ describe("Update", function () { .get("/update/osx/0.9.0") .expect("Content-Type", /json/) .expect(function (res) { + console.log(res) expect(res.body.name).toBe("1.0.0") expect(res.body.url).toBeTruthy() expect(res.body.pub_date).toBeTruthy() diff --git a/docs/assets.md b/docs/assets.md index dd8eca74..0da9fa3a 100644 --- a/docs/assets.md +++ b/docs/assets.md @@ -4,7 +4,7 @@ Nuts uses GitHub Releases and assets to serve the right file to the right user. See GitHub guides: [About Releases](https://help.github.com/articles/about-releases/) & [Creating Releases](https://help.github.com/articles/creating-releases/). -### Naming +## Naming Nuts uses some filename/extension conventions to serve the correct asset to a specific request: @@ -18,18 +18,17 @@ By default releases are tagged as 32-bits (except for OSX), but 64-bits will als Filetype and usage will be detected from the extension: -| Platform | Extensions (sorted by priority) | -| -------- | ---------- | -| Windows | `.exe`, `.nupkg`, `.zip` | -| OS X | `.dmg`, `.zip` | -| Linux | `.deb`, `.rpm`, `.zip` | - +| Platform | Extensions (sorted by priority) | +| -------- | ----------------------------------- | +| Windows | `.exe`, `.nupkg`, `.zip` | +| OS X | `.dmg`, `.zip` | +| Linux | `.AppImage`, `.deb`, `.rpm`, `.zip` | ### Example Here is a list of files in one of the latest release of our [GitBook Editor](https://www.gitbook.com/editor): -``` +```sh gitbook-editor-5.0.0-beta.10-linux-ia32.deb gitbook-editor-5.0.0-beta.10-linux-x64.deb gitbook-editor-5.0.0-beta.10-osx-x64.dmg diff --git a/lib/nuts.js b/lib/nuts.js index 1f2823ec..e6fc1c0e 100644 --- a/lib/nuts.js +++ b/lib/nuts.js @@ -302,7 +302,7 @@ Nuts.prototype.onUpdate = function (req, res, next) { if (!latest || latest.tag == tag) return res.status(204).send("No updates") - if (!(await that.checkAuth(req, version))) return res.sendStatus(403) + if (!(await that.checkAuth(req, latest))) return res.sendStatus(403) // Extract release notes from all versions in range var notesSlice = @@ -358,7 +358,7 @@ Nuts.prototype.onUpdateWin = function (req, res, next) { var latest = _.first(versions) if (!latest) throw new Error("Version not found") - if (!(await that.checkAuth(req, version))) return res.sendStatus(403) + if (!(await that.checkAuth(req, latest))) return res.sendStatus(403) // File exists var asset = _.find(latest.platforms, { @@ -413,7 +413,7 @@ Nuts.prototype.onServeNotes = function (req, res, next) { if (!latest) throw new Error("No versions matching") - if (!(await that.checkAuth(req, version))) return res.sendStatus(403) + if (!(await that.checkAuth(req, latest))) return res.sendStatus(403) res.format({ "application/json": function () { diff --git a/lib/utils/platforms.js b/lib/utils/platforms.js index 95333c1c..ff3d5f0d 100644 --- a/lib/utils/platforms.js +++ b/lib/utils/platforms.js @@ -5,6 +5,9 @@ var platforms = { LINUX: "linux", LINUX_32: "linux_32", LINUX_64: "linux_64", + LINUX_APPIMAGE: "linux_AppImage", + LINUX_APPIMAGE_32: "linux_AppImage_32", + LINUX_APPIMAGE_64: "linux_AppImage_64", LINUX_RPM: "linux_rpm", LINUX_RPM_32: "linux_rpm_32", LINUX_RPM_64: "linux_rpm_64", @@ -45,11 +48,14 @@ function detectPlatform(platform) { _.includes(name, "linux") || _.includes(name, "ubuntu") || hasSuffix(name, ".deb") || + hasSuffix(name, ".appimage") || hasSuffix(name, ".rpm") || hasSuffix(name, ".tgz") || hasSuffix(name, ".tar.gz") ) { - if (_.includes(name, "linux_deb") || hasSuffix(name, ".deb")) { + if (_.includes(name, "linux_appimage") || hasSuffix(name, ".appimage")) { + prefix = platforms.LINUX_APPIMAGE + } else if (_.includes(name, "linux_deb") || hasSuffix(name, ".deb")) { prefix = platforms.LINUX_DEB } else if (_.includes(name, "linux_rpm") || hasSuffix(name, ".rpm")) { prefix = platforms.LINUX_RPM @@ -122,6 +128,7 @@ function resolveForVersion(version, platformID, opts) { filePreference: [ ".exe", ".dmg", + ".AppImage", ".deb", ".rpm", ".tgz",