mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 16:23:28 +02:00
fix review comments
This commit is contained in:
@@ -34,32 +34,27 @@ module.exports = function(options) {
|
||||
app.use(bodyParser.json())
|
||||
app.use(validator())
|
||||
|
||||
function putObject(plugin, uriorpath, name) {
|
||||
function putObject(plugin, file) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var id = uuid.v4()
|
||||
var key = id
|
||||
var filename = name? name: path.basename(uriorpath)
|
||||
var rs = fs.createReadStream(uriorpath)
|
||||
var rs = fs.createReadStream(file.path)
|
||||
|
||||
s3.putObject({
|
||||
Key: key
|
||||
Key: id
|
||||
, Body: rs
|
||||
, Bucket: options.bucket
|
||||
, Metadata: {
|
||||
plugin: plugin
|
||||
, name: filename
|
||||
, name: file.name
|
||||
}
|
||||
}, function(err, data) {
|
||||
if (err) {
|
||||
log.error('failed to store "%s" bucket:"%s"', key, options.bucket)
|
||||
log.error('failed to store "%s" bucket:"%s"', id, options.bucket)
|
||||
log.error(err);
|
||||
reject(err);
|
||||
} else {
|
||||
log.info('Stored "%s" to %s/%s', name, options.bucket, key)
|
||||
resolve({
|
||||
id: id
|
||||
, name: filename
|
||||
})
|
||||
log.info('Stored "%s" to %s/%s', file.name, options.bucket, id)
|
||||
resolve(id)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -82,12 +77,12 @@ module.exports = function(options) {
|
||||
var requests = Object.keys(files).map(function(field) {
|
||||
var file = files[field]
|
||||
log.info('Uploaded "%s" to "%s"', file.name, file.path)
|
||||
return putObject(plugin, file.path, file.name)
|
||||
.then(function (obj) {
|
||||
return putObject(plugin, file)
|
||||
.then(function (id) {
|
||||
return {
|
||||
field: field
|
||||
, id: obj.id
|
||||
, name: obj.name
|
||||
, id: id
|
||||
, name: file.name
|
||||
, temppath: file.path
|
||||
}
|
||||
})
|
||||
@@ -116,7 +111,6 @@ module.exports = function(options) {
|
||||
})
|
||||
.then(function (storedFiles){
|
||||
storedFiles.forEach(function (file){
|
||||
log.debug('cleaned up: %s', file.temppath)
|
||||
fs.unlink(file.temppath)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user