mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-01-20 22:52:46 -05:00
very basic support for unpublishing a package
This commit is contained in:
parent
b9cb60da64
commit
7a3255d1ab
4 changed files with 49 additions and 3 deletions
11
lib/index.js
11
lib/index.js
|
@ -178,6 +178,17 @@ module.exports = function(config_hash) {
|
|||
});
|
||||
});
|
||||
|
||||
// unpublishing an entire package
|
||||
app.delete('/:package/-rev/*', can('publish'), function(req, res, next) {
|
||||
storage.remove_package(req.params.package, function(err) {
|
||||
if (err) return next(err);
|
||||
res.status(201);
|
||||
return res.send({
|
||||
ok: 'package removed'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// uploading package tarball
|
||||
app.put('/:package/-/:filename/*', can('publish'), media('application/octet-stream'), function(req, res, next) {
|
||||
var name = req.params.package;
|
||||
|
|
|
@ -160,5 +160,9 @@ Storage.prototype.read_stream = function(name, cb) {
|
|||
return read_stream(this.path + '/' + name, cb);
|
||||
}
|
||||
|
||||
Storage.prototype.unlink = function(name, cb) {
|
||||
fs.unlink(this.path + '/' + name, cb);
|
||||
}
|
||||
|
||||
module.exports = Storage;
|
||||
|
||||
|
|
|
@ -45,6 +45,18 @@ Storage.prototype.add_package = function(name, metadata, callback) {
|
|||
});
|
||||
}
|
||||
|
||||
Storage.prototype.remove_package = function(name, callback) {
|
||||
this.storage.unlink(name + '/' + info_file, function(err) {
|
||||
if (err && err.code === 'ENOENT') {
|
||||
return callback(new UError({
|
||||
status: 404,
|
||||
msg: 'no such package available',
|
||||
}));
|
||||
}
|
||||
callback();
|
||||
});
|
||||
}
|
||||
|
||||
Storage.prototype._read_create_package = function(name, callback) {
|
||||
var self = this;
|
||||
self.storage.read_json(name + '/' + info_file, function(err, data) {
|
||||
|
|
|
@ -131,6 +131,24 @@ Storage.prototype.add_version = function(name, version, metadata, tag, callback)
|
|||
});
|
||||
}
|
||||
|
||||
//
|
||||
// Remove a package from a system
|
||||
//
|
||||
// Function removes a package from local storage and all uplinks with
|
||||
// write access.
|
||||
//
|
||||
// TODO: currently it works only locally
|
||||
//
|
||||
// TODO: if a package is uploaded to uplink1, but upload to uplink2 fails,
|
||||
// we report failure, but package is not removed from uplink1. This might
|
||||
// require manual intervention.
|
||||
//
|
||||
// Used storages: local (write) && uplinks (proxy_publish, write)
|
||||
//
|
||||
Storage.prototype.remove_package = function(name, callback) {
|
||||
return this.local.remove_package(name, callback);
|
||||
}
|
||||
|
||||
//
|
||||
// Upload a tarball for {name} package
|
||||
//
|
||||
|
@ -147,8 +165,9 @@ Storage.prototype.add_tarball = function(name, filename) {
|
|||
|
||||
var self = this;
|
||||
var upstreams = [];
|
||||
|
||||
upstreams.push(self.local.add_tarball(name, filename));
|
||||
var localstream = self.local.add_tarball(name, filename);
|
||||
|
||||
upstreams.push(localstream);
|
||||
for (var i in self.uplinks) {
|
||||
if (self.config.proxy_publish(name, i)) {
|
||||
upstreams.push(self.uplinks[i].add_tarball(name, filename));
|
||||
|
@ -170,7 +189,7 @@ Storage.prototype.add_tarball = function(name, filename) {
|
|||
status: 409,
|
||||
msg: 'this tarball is already present'
|
||||
}));
|
||||
} else if (!stream.status && upstream != self.local) {
|
||||
} else if (!stream.status && upstream !== localstream) {
|
||||
stream.emit('error', new UError({
|
||||
status: 503,
|
||||
msg: 'one or more uplinks are unreachable'
|
||||
|
|
Loading…
Add table
Reference in a new issue