Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
Support .AppImage format
Browse files Browse the repository at this point in the history
From GitbookIO#158

(also fixed previous commit's oopsie woopsie)
  • Loading branch information
rastiqdev committed Jun 22, 2023
1 parent 8ce609d commit 29ad229
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 12 deletions.
37 changes: 37 additions & 0 deletions __tests__/platforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
)
Expand Down
1 change: 1 addition & 0 deletions __tests__/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 7 additions & 8 deletions docs/assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/nuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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, {
Expand Down Expand Up @@ -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 () {
Expand Down
9 changes: 8 additions & 1 deletion lib/utils/platforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -122,6 +128,7 @@ function resolveForVersion(version, platformID, opts) {
filePreference: [
".exe",
".dmg",
".AppImage",
".deb",
".rpm",
".tgz",
Expand Down

0 comments on commit 29ad229

Please sign in to comment.