Repository navigation
Expand file tree
/
Copy pathdatautil.js
More file actions
63 lines (54 loc) · 1.41 KB
/
Copy pathdatautil.js
File metadata and controls
63 lines (54 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var deviceData = require('stf-device-db')
var browserData = require('stf-browser-db')
var logger = require('./logger')
var log = logger.createLogger('util:datautil')
var datautil = module.exports = Object.create(null)
datautil.applyData = function(device) {
var match = deviceData.find({
model: device.model
, name: device.product
})
if (match) {
device.name = match.name.id
device.releasedAt = match.date
device.image = match.image
device.cpu = match.cpu
device.memory = match.memory
if (match.display && match.display.s) {
device.display = device.display || {}
device.display.inches = match.display.s
}
}
else {
log.warn(
'Device database does not have a match for device "%s" (model "%s"/"%s")'
, device.serial
, device.model
, device.product
)
}
return device
}
datautil.applyBrowsers = function(device) {
if (device.browser) {
device.browser.apps.forEach(function(app) {
var data = browserData[app.type]
if (data) {
app.developer = data.developer
}
})
}
return device
}
datautil.applyOwner = function(device, user) {
device.using = !!device.owner && device.owner.email === user.email
return device
}
datautil.normalize = function(device, user) {
datautil.applyData(device)
datautil.applyBrowsers(device)
datautil.applyOwner(device, user)
if (!device.present) {
device.owner = null
}
}