From e0c82dd121247350a873946a13bdd9d73b62e3e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Thu, 17 Mar 2016 10:59:31 +0100 Subject: [PATCH] Add RSS feeds --- lib/backends/github.js | 2 +- lib/nuts.js | 43 ++++++++++++++++++- package.json | 94 +++++++++++++++++++++--------------------- 3 files changed, 89 insertions(+), 50 deletions(-) diff --git a/lib/backends/github.js b/lib/backends/github.js index c476f107..dbcbe9fe 100644 --- a/lib/backends/github.js +++ b/lib/backends/github.js @@ -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'); } diff --git a/lib/nuts.js b/lib/nuts.js index 17f54d4b..5ddec9d4 100644 --- a/lib/nuts.js +++ b/lib/nuts.js @@ -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'); @@ -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); @@ -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() @@ -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; }) @@ -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', { diff --git a/package.json b/package.json index f2f67d27..c331023a 100644 --- a/package.json +++ b/package.json @@ -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": "samypesse@gmail.com" - } - ], - "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": "samypesse@gmail.com" } + ], + "repository": { + "type": "git", + "url": "https://github.com/GitbookIO/nuts.git" + }, + "scripts": { + "start": "node bin/web.js", + "test": "mocha --reporter list" + } }