mirror of
https://github.com/verdaccio/verdaccio.git
synced 2024-12-30 22:34:10 -05:00
calculating sha1sum of uploaded tarballs
This commit is contained in:
parent
5622b2283d
commit
4c2c4b87c2
1 changed files with 27 additions and 14 deletions
|
@ -160,20 +160,23 @@ Storage.prototype.add_version = function(name, version, metadata, tag, callback)
|
|||
}
|
||||
|
||||
Storage.prototype.add_tarball = function(name, filename) {
|
||||
var stream = new mystreams.UploadTarballStream();
|
||||
var _transform = stream._transform;
|
||||
var length = 0;
|
||||
stream._transform = function(data) {
|
||||
length += data.length;
|
||||
_transform.apply(stream, arguments);
|
||||
};
|
||||
var stream = new mystreams.UploadTarballStream()
|
||||
, _transform = stream._transform
|
||||
, length = 0
|
||||
, shasum = crypto.createHash('sha1')
|
||||
|
||||
var self = this;
|
||||
stream._transform = function(data) {
|
||||
shasum.update(data)
|
||||
length += data.length
|
||||
_transform.apply(stream, arguments)
|
||||
}
|
||||
|
||||
var self = this
|
||||
if (name === info_file || name === '__proto__') {
|
||||
stream.emit('error', new UError({
|
||||
status: 403,
|
||||
msg: 'can\'t use this filename'
|
||||
}));
|
||||
}))
|
||||
}
|
||||
|
||||
var wstream = this.storage.write_stream(name + '/' + filename);
|
||||
|
@ -201,14 +204,24 @@ Storage.prototype.add_tarball = function(name, filename) {
|
|||
wstream.on('open', function() {
|
||||
// re-emitting open because it's handled in storage.js
|
||||
stream.emit('open');
|
||||
});
|
||||
})
|
||||
wstream.on('success', function() {
|
||||
// re-emitting open because it's handled in index.js
|
||||
stream.emit('success');
|
||||
});
|
||||
self.update_package(name, function updater(data, cb) {
|
||||
data._attachments[filename] = {
|
||||
shasum: shasum.digest('hex'),
|
||||
}
|
||||
cb()
|
||||
}, function(err) {
|
||||
if (err) {
|
||||
stream.emit('error', err)
|
||||
} else {
|
||||
stream.emit('success')
|
||||
}
|
||||
})
|
||||
})
|
||||
stream.abort = function() {
|
||||
wstream.abort();
|
||||
};
|
||||
wstream.abort()
|
||||
}
|
||||
stream.done = function() {
|
||||
if (!length) {
|
||||
stream.emit('error', new UError({
|
||||
|
|
Loading…
Reference in a new issue