Skip to content

Commit

Permalink
Merge pull request GitbookIO#51 from GitbookIO/feature/atomfeed
Browse files Browse the repository at this point in the history
Fix GitbookIO#44: Atom/RSS feed
  • Loading branch information
SamyPesse committed Mar 17, 2016
2 parents 9af3fd2 + f73a377 commit c47bbb7
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 51 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ It uses GitHub as a backend to store assets, and it can easily be deployed to He
- :sparkles: Release notes endpoint
- `/notes/:version`
- :sparkles: Up-to-date releases (GitHub webhooks)
- :sparkles: Atom/RSS feeds for versions/channels

#### Deploy it / Start it

Expand Down
4 changes: 4 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ By default releases are tagged as 32-bits (except for OSX), but 64-bits will als
### How should I tag my releases?

Nuts requires applications to follow [SemVer](http://semver.org). And even if you're not using Nuts, you should follow it!

### Does nuts provide an Atom feed of versions?

Yes, [See Feed URLS](./urls.md).
8 changes: 7 additions & 1 deletion docs/urls.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Download urls
# Download Urls

Nuts provides urls to access releases assets. These assets are cached on the disk.

Expand All @@ -9,3 +9,9 @@ Nuts provides urls to access releases assets. These assets are cached on the dis
* Specific channel: `http://download.myapp.com/download/channel/beta`
* Specific channel for specific platform: `http://download.myapp.com/download/channel/beta/osx`

# Atom Feed Urls

Nuts provides different Atom feeds:

* All versions: `http://download.myapp.com/feed/channel/all.atom`
* Versions in specific channel: `http://download.myapp.com/feed/channel/:channel.atom`
2 changes: 1 addition & 1 deletion lib/backends/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function GitHubBackend() {
proxyAssets: true
});

if (!this.opts.username || (!this.opts.password && !this.opts.token)) {
if ((!this.opts.username || !this.opts.password) && (!this.opts.token)) {
throw new Error('GitHub backend require "username" and "token" options');
}

Expand Down
43 changes: 41 additions & 2 deletions lib/nuts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var _ = require('lodash');
var Q = require('q');
var Feed = require('feed');
var urljoin = require('urljoin.js');
var Understudy = require('understudy');
var express = require('express');
Expand Down Expand Up @@ -56,6 +57,8 @@ function Nuts(opts) {
this.router.get('/download/:tag/:filename', this.onDownload);
this.router.get('/download/:platform?', this.onDownload);

this.router.get('/feed/channel/:channel.atom', this.onServeVersionsFeed);

this.router.get('/update', this.onUpdateRedirect);
this.router.get('/update/:platform/:version', this.onUpdate);
this.router.get('/update/:platform/:version/RELEASES', this.onUpdateWin);
Expand Down Expand Up @@ -230,7 +233,7 @@ Nuts.prototype.onUpdate = function(req, res, next) {
var releaseNotes = notes.merge(versions.slice(0, -1), { includeTag: false });

res.status(200).send({
"url": urljoin(fullUrl, "/../../../", "/download/version/"+latest.tag+"/"+platform+"?filetype="+filetype),
"url": urljoin(fullUrl, '/../../../', '/download/version/'+latest.tag+'/'+platform+'?filetype='+filetype),
"name": latest.tag,
"notes": releaseNotes,
"pub_date": latest.published_at.toISOString()
Expand Down Expand Up @@ -278,7 +281,7 @@ Nuts.prototype.onUpdateWin = function(req, res, next) {

// Change filename to use download proxy
.map(function(entry) {
entry.filename = urljoin(fullUrl, "/../../../../", '/download/'+entry.semver+'/'+entry.filename);
entry.filename = urljoin(fullUrl, '/../../../../', '/download/'+entry.semver+'/'+entry.filename);

return entry;
})
Expand Down Expand Up @@ -330,6 +333,42 @@ Nuts.prototype.onServeNotes = function(req, res, next) {
.fail(next);
};

// Serve versions list as RSS
Nuts.prototype.onServeVersionsFeed = function(req, res, next) {
var that = this;
var channel = req.params.channel || 'all';
var channelId = channel === 'all'? '*' : channel;
var fullUrl = getFullUrl(req);

var feed = new Feed({
id: 'versions/channels/'+channel,
title: 'Versions (' + channel + ')',
link: fullUrl
});

Q()
.then(function() {
return that.versions.filter({
channel: channelId
});
})
.then(function(versions) {
_.each(versions, function(version) {
feed.addItem({
title: version.tag,
link: urljoin(fullUrl, '/../../../', '/download/version/'+version.tag),
description: version.notes,
date: version.published_at,
author: []
});
});

res.set('Content-Type', 'application/atom+xml; charset=utf-8');
res.send(feed.render('atom-1.0'));
})
.fail(next);
};

// Control access to the API
Nuts.prototype.onAPIAccessControl = function(req, res, next) {
this.performQ('api', {
Expand Down
94 changes: 47 additions & 47 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
{
"name": "nuts-serve",
"version": "3.0.0-pre.6",
"description": "Server to make GitHub releases (private) available to download with Squirrel support",
"main": "./lib/index.js",
"homepage": "https://github.com/GitbookIO/nuts",
"license": "Apache-2.0",
"main": "./lib/index.js",
"dependencies": {
"express": "^4.13.3",
"lodash": "3.7.0",
"q": "1.2.0",
"body-parser": "1.12.3",
"octocat": "0.10.2",
"semver": "5.0.1",
"request": "2.60.0",
"basic-auth": "1.0.3",
"express-useragent": "0.1.9",
"lru-diskcache": "1.1.1",
"stream-res": "1.0.1",
"urljoin.js": "0.1.0",
"analytics-node": "1.2.2",
"uuid": "2.0.1",
"github-webhook-handler": "0.5.0",
"strip-bom": "2.0.0",
"destroy": "1.0.3",
"understudy": "4.1.0"
},
"devDependencies": {
"mocha": "1.18.2",
"should": "7.0.4"
},
"bugs": {
"url": "https://github.com/GitbookIO/nuts/issues"
},
"authors": [
{
"name": "Samy Pesse",
"email": "[email protected]"
}
],
"repository": {
"type" : "git",
"url" : "https://github.com/GitbookIO/nuts.git"
},
"scripts": {
"start": "node bin/web.js",
"test": "mocha --reporter list"
"name": "nuts-serve",
"version": "3.0.0-pre.6",
"description": "Server to make GitHub releases (private) available to download with Squirrel support",
"main": "./lib/index.js",
"homepage": "https://github.com/GitbookIO/nuts",
"license": "Apache-2.0",
"dependencies": {
"analytics-node": "1.2.2",
"basic-auth": "1.0.3",
"body-parser": "1.12.3",
"destroy": "1.0.3",
"express": "^4.13.3",
"express-useragent": "0.1.9",
"feed": "^0.3.0",
"github-webhook-handler": "0.5.0",
"lodash": "3.7.0",
"lru-diskcache": "1.1.1",
"octocat": "0.10.2",
"q": "1.2.0",
"request": "2.60.0",
"semver": "5.0.1",
"stream-res": "1.0.1",
"strip-bom": "2.0.0",
"understudy": "4.1.0",
"urljoin.js": "0.1.0",
"uuid": "2.0.1"
},
"devDependencies": {
"mocha": "1.18.2",
"should": "7.0.4"
},
"bugs": {
"url": "https://github.com/GitbookIO/nuts/issues"
},
"authors": [
{
"name": "Samy Pesse",
"email": "[email protected]"
}
],
"repository": {
"type": "git",
"url": "https://github.com/GitbookIO/nuts.git"
},
"scripts": {
"start": "node bin/web.js",
"test": "mocha --reporter list"
}
}

0 comments on commit c47bbb7

Please sign in to comment.