From 319ff4d3840fa3c40580d2ec7406ba81365de1a8 Mon Sep 17 00:00:00 2001 From: Yannick Galatol Date: Fri, 12 Dec 2014 17:19:23 +0100 Subject: [PATCH 1/4] Create a list method for the wep app to return all the packages --- lib/index-web.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/index-web.js b/lib/index-web.js index 2038d1c6..52065f36 100644 --- a/lib/index-web.js +++ b/lib/index-web.js @@ -129,6 +129,19 @@ module.exports = function(config, auth, storage) { next( renderReadme(info.readme || 'ERROR: No README data found!') ) }) }) + + app.get('/-/list', function(req, res, next) { + + storage.get_local(function(err, packages) { + if (err) throw err // that function shouldn't produce any + next(packages) + }) + + function allow(package) { + return config.allow_access(package.name, req.remote_user) + } + }) + return app } From 2c796e95eb2c926cc5a053a96382834d9655c556 Mon Sep 17 00:00:00 2001 From: Yannick Galatol Date: Fri, 12 Dec 2014 17:58:37 +0100 Subject: [PATCH 2/4] Move the list method from WEB to API --- lib/index-api.js | 8 ++++++++ lib/index-web.js | 12 ------------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/index-api.js b/lib/index-api.js index 65f5b8a1..21ed12b3 100644 --- a/lib/index-api.js +++ b/lib/index-api.js @@ -94,6 +94,14 @@ module.exports = function(config, auth, storage) { }) }) + app.get('/-/list', function(req, res, next) { + + storage.get_local(function(err, packages) { + if (err) throw err // that function shouldn't produce any + next(packages) + }) + }) + //app.get('/*', function(req, res) { // proxy.request(req, res) //}) diff --git a/lib/index-web.js b/lib/index-web.js index 52065f36..adcd51ca 100644 --- a/lib/index-web.js +++ b/lib/index-web.js @@ -130,18 +130,6 @@ module.exports = function(config, auth, storage) { }) }) - app.get('/-/list', function(req, res, next) { - - storage.get_local(function(err, packages) { - if (err) throw err // that function shouldn't produce any - next(packages) - }) - - function allow(package) { - return config.allow_access(package.name, req.remote_user) - } - }) - return app } From 77a13cf7e702f7cbcec60714ceed651c35a246f9 Mon Sep 17 00:00:00 2001 From: Yannick Galatol Date: Fri, 12 Dec 2014 17:59:28 +0100 Subject: [PATCH 3/4] Move the list method from WEB to API --- lib/index-web.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/index-web.js b/lib/index-web.js index adcd51ca..2038d1c6 100644 --- a/lib/index-web.js +++ b/lib/index-web.js @@ -129,7 +129,6 @@ module.exports = function(config, auth, storage) { next( renderReadme(info.readme || 'ERROR: No README data found!') ) }) }) - return app } From 658e624c868b6df5b7b3e63fba97264a9ccf998d Mon Sep 17 00:00:00 2001 From: Yannick Galatol Date: Fri, 12 Dec 2014 18:54:55 +0100 Subject: [PATCH 4/4] Add a query parameter "local" to the search method of storage to allow listing only local packages --- lib/index-api.js | 8 -------- lib/storage.js | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/lib/index-api.js b/lib/index-api.js index 21ed12b3..65f5b8a1 100644 --- a/lib/index-api.js +++ b/lib/index-api.js @@ -94,14 +94,6 @@ module.exports = function(config, auth, storage) { }) }) - app.get('/-/list', function(req, res, next) { - - storage.get_local(function(err, packages) { - if (err) throw err // that function shouldn't produce any - next(packages) - }) - }) - //app.get('/*', function(req, res) { // proxy.request(req, res) //}) diff --git a/lib/storage.js b/lib/storage.js index fcf4414f..1193a1b7 100644 --- a/lib/storage.js +++ b/lib/storage.js @@ -382,7 +382,7 @@ Storage.prototype.search = function(startkey, options, callback) { function remote_search() { var uplink = self.uplinks[uplinks[i]] - if (!uplink) { + if (options.req.query.local !== undefined || !uplink) { return merge_with_local_packages(null, null, {}) } self.uplinks[uplinks[i]].request({