2014-12-01 15:52:09 +00:00
|
|
|
url = require('url')
|
2014-11-28 19:36:03 +00:00
|
|
|
_ = require('lodash')
|
|
|
|
resin = require('../resin')
|
|
|
|
|
2014-11-20 17:53:10 +00:00
|
|
|
exports.formatLongString = (string, n) ->
|
|
|
|
return string if not n?
|
|
|
|
splitRegexp = new RegExp(".{1,#{n}}", 'g')
|
|
|
|
splittedString = string.match(splitRegexp)
|
|
|
|
return splittedString.join('\n')
|
2014-11-28 19:36:03 +00:00
|
|
|
|
|
|
|
exports.isDeviceUUIDValid = (uuid, callback) ->
|
|
|
|
resin.models.device.getAll (error, devices) ->
|
|
|
|
return callback?(error) if error?
|
|
|
|
uuidExists = _.findWhere(devices, { uuid })?
|
|
|
|
return callback(null, uuidExists)
|
2014-12-01 15:52:09 +00:00
|
|
|
|
|
|
|
exports.constructRemoteUrl = (base, path, query) ->
|
|
|
|
if not _.isEmpty(query)
|
|
|
|
formattedQuery = url.format({ query })
|
|
|
|
path = url.resolve(path, formattedQuery)
|
|
|
|
|
|
|
|
return url.resolve(base, path)
|