mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 08:03:30 +02:00
Fixed most of the dependencies by unit testing.
Refactored TransactionService and StorageService.
This commit is contained in:
48
res/app/components/stf/storage/storage-service.js
Normal file
48
res/app/components/stf/storage/storage-service.js
Normal file
@@ -0,0 +1,48 @@
|
||||
var Promise = require('bluebird')
|
||||
|
||||
module.exports = function StorageServiceFactory($http, $upload) {
|
||||
var service = {}
|
||||
|
||||
service.storeUrl = function(type, url) {
|
||||
return $http({
|
||||
url: '/api/v1/s/' + type + '/download'
|
||||
, method: 'POST'
|
||||
, data: {
|
||||
url: url
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
service.storeFile = function(type, files, options) {
|
||||
var resolver = Promise.defer()
|
||||
var input = options.filter ? files.filter(options.filter) : files
|
||||
|
||||
if (input.length) {
|
||||
$upload.upload({
|
||||
url: '/api/v1/s/' + type
|
||||
, method: 'POST'
|
||||
, file: input
|
||||
})
|
||||
.then(
|
||||
function(value) {
|
||||
resolver.resolve(value)
|
||||
}
|
||||
, function(err) {
|
||||
resolver.reject(err)
|
||||
}
|
||||
, function(progressEvent) {
|
||||
resolver.progress(progressEvent)
|
||||
}
|
||||
)
|
||||
}
|
||||
else {
|
||||
var err = new Error('No input files')
|
||||
err.code = 'no_input_files'
|
||||
resolver.reject(err)
|
||||
}
|
||||
|
||||
return resolver.promise
|
||||
}
|
||||
|
||||
return service
|
||||
}
|
||||
Reference in New Issue
Block a user