Repository navigation
Expand file tree
/
Copy pathdatautil.js
More file actions
76 lines (66 loc) · 1.78 KB
/
Copy pathdatautil.js
File metadata and controls
76 lines (66 loc) · 1.78 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
<
8A46
div data-line-number="29" class="react-line-number react-code-text" style="padding-right:16px">2930
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
64
65
66
67
68
69
70
71
72
73
74
75
76
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.info(
'Device database does not have an entry for "%s" (model "%s"/"%s"). ' +
'This is not an error, it only means that we don\'t have data for it yet.'
, 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
}
// Only owner can see this information
datautil.applyOwnerOnlyInfo = function(device, user) {
if (device.owner && device.owner.email === user.email) {
// No-op
}
else {
device.remoteConnect = false
device.remoteConnectUrl = null
}
}
datautil.normalize = function(device, user) {
datautil.applyData(device)
datautil.applyBrowsers(device)
datautil.applyOwner(device, user)
datautil.applyOwnerOnlyInfo(device, user)
if (!device.present) {
device.owner = null
}
}