1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-04 02:09:32 +02:00

Integrate device database.

This commit is contained in:
Simo Kinnunen 2014-03-17 14:58:45 +09:00
parent 7a2cdaf071
commit d1b724ada0
4 changed files with 66 additions and 3 deletions

54
lib/util/datautil.js Normal file
View file

@ -0,0 +1,54 @@
var deviceData = require('stf-devices-db')
var express = require('express')
var pathutil = require('./pathutil')
var logger = require('./logger')
var log = logger.createLogger('util:datautil')
var aliases = {
'KYY22': 'L02'
}
module.exports.applyData = function(device) {
var model = device.model
var match
match = deviceData[model]
if (!match) {
if (aliases[model]) {
match = deviceData[aliases[model]]
}
else {
if (!match) {
model = model.replace(/ /g, '_')
match = deviceData[model]
if (!match) {
model = model.replace(/_/g, '')
match = deviceData[model]
}
}
}
}
if (match) {
device.name = match.name.id
device.releasedAt = match.date
device.image = match.image.s.replace(/^small\//, '')
}
else {
log.warn(
'Device database does not have a match for device "%s" (model "%s")'
, device.serial
, device.model
)
}
return device
}
module.exports.middleware = function() {
return express.static(pathutil.root('node_modules/stf-devices-db/data/small'))
}