mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 08:03:30 +02:00
Implement APK uploads using the new storage system. Installation from URL still does not work, and dropping the file on the screen may not work either.
This commit is contained in:
54
lib/roles/storage/plugins/apk/index.js
Normal file
54
lib/roles/storage/plugins/apk/index.js
Normal file
@@ -0,0 +1,54 @@
|
||||
var http = require('http')
|
||||
var url = require('url')
|
||||
|
||||
var express = require('express')
|
||||
var httpProxy = require('http-proxy')
|
||||
|
||||
var logger = require('../../../../util/logger')
|
||||
var download = require('../../../../util/download')
|
||||
var manifest = require('./task/manifest')
|
||||
|
||||
module.exports = function(options) {
|
||||
var log = logger.createLogger('storage:plugins:apk')
|
||||
, app = express()
|
||||
, server = http.createServer(app)
|
||||
, proxy = httpProxy.createProxyServer()
|
||||
|
||||
proxy.on('error', function(err) {
|
||||
log.error('Proxy had an error', err.stack)
|
||||
})
|
||||
|
||||
app.set('strict routing', true)
|
||||
app.set('case sensitive routing', true)
|
||||
app.set('trust proxy', true)
|
||||
|
||||
app.get('/api/v1/s/apk/:id/*/manifest', function(req, res) {
|
||||
download(url.resolve(options.storageUrl, req.url), {
|
||||
dir: options.cacheDir
|
||||
})
|
||||
.then(manifest)
|
||||
.then(function(data) {
|
||||
res.status(200)
|
||||
.json({
|
||||
success: true
|
||||
, manifest: data
|
||||
})
|
||||
})
|
||||
.catch(function(err) {
|
||||
log.error('Unable to read manifest of "%s"', req.params.id, err.stack)
|
||||
res.status(500)
|
||||
.json({
|
||||
success: false
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
app.get('/api/v1/s/apk/:id/*', function(req, res) {
|
||||
proxy.web(req, res, {
|
||||
target: options.storageUrl
|
||||
})
|
||||
})
|
||||
|
||||
server.listen(options.port)
|
||||
log.info('Listening on port %d', options.port)
|
||||
}
|
||||
19
lib/roles/storage/plugins/apk/task/manifest.js
Normal file
19
lib/roles/storage/plugins/apk/task/manifest.js
Normal file
@@ -0,0 +1,19 @@
|
||||
var Promise = require('bluebird')
|
||||
var ApkReader = require('adbkit-apkreader')
|
||||
|
||||
module.exports = function(file) {
|
||||
var resolver = Promise.defer()
|
||||
|
||||
process.nextTick(function() {
|
||||
try {
|
||||
var reader = ApkReader.readFile(file.path)
|
||||
var manifest = reader.readManifestSync()
|
||||
resolver.resolve(manifest)
|
||||
}
|
||||
catch (err) {
|
||||
resolver.reject(err)
|
||||
}
|
||||
})
|
||||
|
||||
return resolver.promise
|
||||
}
|
||||
Reference in New Issue
Block a user