Skip to content

Commit

Permalink
Merge pull request #1 from rlidwka/master
Browse files Browse the repository at this point in the history
Merge latest Upstream Master
  • Loading branch information
valdemon authored Mar 7, 2018
2 parents 17e0ffe + 3f55fb4 commit 09d7aec
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 141 deletions.
11 changes: 10 additions & 1 deletion lib/index-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ module.exports = function(config, auth, storage) {
app.use(expressJson5({ strict: false, limit: config.max_body_size || '10mb' }))
app.use(Middleware.anti_loop(config))

// encode / in a scoped package name to be matched as a single parameter in routes
app.use(function(req, res, next) {
if (req.url.indexOf('@') != -1) {
// e.g.: /@org/pkg/1.2.3 -> /@org%2Fpkg/1.2.3, /@org%2Fpkg/1.2.3 -> /@org%2Fpkg/1.2.3
req.url = req.url.replace(/^(\/@[^\/%]+)\/(?!$)/, '$1%2F')
}
next()
})

// for "npm whoami"
app.get('/whoami', function(req, res, next) {
if (req.headers.referer === 'whoami') {
Expand Down Expand Up @@ -90,7 +99,7 @@ module.exports = function(config, auth, storage) {
res.status(200)
res.write('{"_updated":' + Date.now());

var stream = storage.search(req.param.startkey || 0, { req: req })
var stream = storage.search(req.query.startkey || 0, { req: req })

stream.on('data', function each(pkg) {
processing_pkgs++
Expand Down
9 changes: 9 additions & 0 deletions lib/index-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ module.exports = function(config, auth, storage) {
})
})
}, function(packages) {
packages.sort(function(p1, p2) {
if (p1.name < p2.name) {
return -1;
}
else {
return 1;
}
});

next(template({
name: config.web && config.web.title ? config.web.title : 'Sinopia',
packages: packages,
Expand Down
5 changes: 4 additions & 1 deletion lib/up-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ var parse_interval = require('./config').parse_interval
var Logger = require('./logger')
var MyStreams = require('./streams')
var Utils = require('./utils')
var encode = encodeURIComponent
var encode = function(thing) {
return encodeURIComponent(thing).replace(/^%40/, '@');
};

module.exports = Storage

Expand Down Expand Up @@ -101,6 +103,7 @@ Storage.prototype.request = function(options, cb) {
if (typeof(cb) === 'function') cb(Error('uplink is offline'))
req.emit('error', Error('uplink is offline'))
})
req._read = function(){}
// preventing 'Uncaught, unspecified "error" event'
req.on('error', function(){})
return req
Expand Down
Loading

0 comments on commit 09d7aec

Please sign in to comment.