mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-16 21:56:25 -05:00
adding support for new npm behaviour, closes #31
This commit is contained in:
parent
8c05cfe6a2
commit
54535893ab
1 changed files with 63 additions and 6 deletions
69
lib/index.js
69
lib/index.js
|
@ -235,21 +235,78 @@ module.exports = function(config_hash) {
|
|||
|
||||
if (req.params._rev) {
|
||||
storage.change_package(name, metadata, req.params.revision, function(err) {
|
||||
if (err) return next(err)
|
||||
res.status(201)
|
||||
return res.send({
|
||||
ok: 'package changed'
|
||||
})
|
||||
after_change(err, 'package changed')
|
||||
})
|
||||
} else {
|
||||
storage.add_package(name, metadata, function(err) {
|
||||
after_change(err, 'created new package')
|
||||
})
|
||||
}
|
||||
|
||||
function after_change(err, ok_message) {
|
||||
if (metadata._attachments == null && metadata.versions == null) {
|
||||
if (err) return next(err)
|
||||
res.status(201)
|
||||
return res.send({
|
||||
ok: 'created new package'
|
||||
ok: ok_message
|
||||
})
|
||||
}
|
||||
|
||||
// npm-registry-client 0.3+ embeds tarball into the json upload
|
||||
// https://github.com/isaacs/npm-registry-client/commit/e9fbeb8b67f249394f735c74ef11fe4720d46ca0
|
||||
// issue #31, dealing with it here:
|
||||
|
||||
if (typeof(metadata._attachments) != 'object'
|
||||
|| Object.keys(metadata._attachments).length != 1
|
||||
|| typeof(metadata.versions) != 'object'
|
||||
|| Object.keys(metadata.versions).length != 1) {
|
||||
|
||||
// npm is doing something strange again
|
||||
// if this happens in normal circumstances, report it as a bug
|
||||
return next(new UError({
|
||||
status: 400,
|
||||
msg: 'unsupported registry call',
|
||||
}))
|
||||
}
|
||||
|
||||
if (err && err.status != 409) return next(err)
|
||||
|
||||
// at this point document is either created or existed before
|
||||
var t1 = Object.keys(metadata._attachments)[0]
|
||||
create_tarball(t1, metadata._attachments[t1], function(err) {
|
||||
if (err) return err
|
||||
|
||||
var t2 = Object.keys(metadata.versions)[0]
|
||||
create_version(t2, metadata.versions[t2], function(err) {
|
||||
if (err) return err
|
||||
|
||||
res.status(201)
|
||||
return res.send({
|
||||
ok: ok_message
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function create_tarball(filename, data, cb) {
|
||||
var stream = storage.add_tarball(name, filename)
|
||||
stream.on('error', function(err) {
|
||||
cb(err)
|
||||
})
|
||||
stream.on('success', function() {
|
||||
cb()
|
||||
})
|
||||
|
||||
// this is dumb and memory-consuming, but what choices do we have?
|
||||
stream.end(new Buffer(data.data, 'base64'))
|
||||
stream.done()
|
||||
}
|
||||
|
||||
function create_version(version, data, cb) {
|
||||
// assume latest tag, it's ignored anyway
|
||||
// if you want tags, tag packages explicitly
|
||||
storage.add_version(name, version, data, 'latest', cb)
|
||||
}
|
||||
})
|
||||
|
||||
// unpublishing an entire package
|
||||
|
|
Loading…
Reference in a new issue