mirror of
https://github.com/openstf/stf
synced 2025-10-06 03:50:04 +02:00
Add browser list to device identity.
This commit is contained in:
parent
2bf8f2352b
commit
e17f306d30
11 changed files with 144 additions and 9 deletions
51
lib/roles/device/plugins/browsers.js
Normal file
51
lib/roles/device/plugins/browsers.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
var util = require('util')
|
||||
|
||||
var syrup = require('syrup')
|
||||
|
||||
var logger = require('../../../util/logger')
|
||||
|
||||
module.exports = syrup()
|
||||
.dependency(require('../support/http'))
|
||||
.dependency(require('./input'))
|
||||
.define(function(options, http, input) {
|
||||
var log = logger.createLogger('device:plugins:browsers')
|
||||
|
||||
log.info('Fetching browser list')
|
||||
return input.getBrowsers()
|
||||
.then(function(browsers) {
|
||||
var icons = Object.create(null)
|
||||
|
||||
browsers.apps.forEach(function(app) {
|
||||
icons[app.component] = app.icon.toBuffer()
|
||||
app.icon = util.format(
|
||||
'%s/api/v1/browsers/%s/icon'
|
||||
, http.get('public url')
|
||||
, app.component
|
||||
)
|
||||
})
|
||||
|
||||
http.get(
|
||||
'/api/v1/browsers/:package/:activity/icon'
|
||||
, function(req, res) {
|
||||
var component = util.format(
|
||||
'%s/%s'
|
||||
, req.params.package
|
||||
, req.params.activity
|
||||
)
|
||||
|
||||
var icon = icons[component]
|
||||
|
||||
if (icon) {
|
||||
res.set('Content-Type', 'image/png')
|
||||
res.set('Content-Length', icon.length)
|
||||
res.send(200, icon)
|
||||
}
|
||||
else {
|
||||
res.send(404)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
return browsers
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue