Bug fix in API
This commit is contained in:
1 parent
813bd836f5
commit
76758f35b3
1 file changed
+14
-4
+14
-4
@@ -9,6 +9,7 @@ Timestamp = require('mongodb').Timestamp
|
|||||||
# regular expression objects
|
# regular expression objects
|
||||||
TASKS_REGEX = /^\/devices\/([a-zA-Z0-9\-\_]+)\/tasks\/?$/
|
TASKS_REGEX = /^\/devices\/([a-zA-Z0-9\-\_]+)\/tasks\/?$/
|
||||||
TAGS_REGEX = /^\/devices\/([a-zA-Z0-9\-\_]+)\/tags\/([a-zA-Z0-9\-\_]+)\/?$/
|
TAGS_REGEX = /^\/devices\/([a-zA-Z0-9\-\_]+)\/tags\/([a-zA-Z0-9\-\_]+)\/?$/
|
||||||
|
PROFILES_REGEX = /^\/profiles\/([a-zA-Z0-9\-\_]+)\/?$/
|
||||||
|
|
||||||
connectionRequest = (deviceId, callback) ->
|
connectionRequest = (deviceId, callback) ->
|
||||||
devicesCollection.findOne({_id : deviceId}, {'InternetGatewayDevice.ManagementServer.ConnectionRequestURL._value' : 1}, (err, device)->
|
devicesCollection.findOne({_id : deviceId}, {'InternetGatewayDevice.ManagementServer.ConnectionRequestURL._value' : 1}, (err, device)->
|
||||||
@@ -103,8 +104,17 @@ else
|
|||||||
return body.toString(encoding || 'utf8', 0, body.byteLength)
|
return body.toString(encoding || 'utf8', 0, body.byteLength)
|
||||||
|
|
||||||
request.addListener 'end', () ->
|
request.addListener 'end', () ->
|
||||||
|
body = request.getBody()
|
||||||
urlParts = url.parse(request.url, true)
|
urlParts = url.parse(request.url, true)
|
||||||
if TAGS_REGEX.test(urlParts.pathname)
|
if PROFILES_REGEX.test(urlParts.pathname)
|
||||||
|
if request.method == 'PUT'
|
||||||
|
# TODO save profile
|
||||||
|
else if request.method == 'DELETE'
|
||||||
|
# TODO delete profile
|
||||||
|
else
|
||||||
|
response.writeHead 405, {'Allow': 'PUT, DELETE'}
|
||||||
|
response.end('405 Method Not Allowed')
|
||||||
|
else if TAGS_REGEX.test(urlParts.pathname)
|
||||||
r = TAGS_REGEX.exec(urlParts.pathname)
|
r = TAGS_REGEX.exec(urlParts.pathname)
|
||||||
deviceId = r[1]
|
deviceId = r[1]
|
||||||
tag = r[2]
|
tag = r[2]
|
||||||
@@ -127,14 +137,14 @@ else
|
|||||||
response.end()
|
response.end()
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
response.writeHead 405, {'Allow': 'GET'}
|
response.writeHead 405, {'Allow': 'POST, DELETE'}
|
||||||
response.end('405 Method Not Allowed')
|
response.end('405 Method Not Allowed')
|
||||||
else if TASKS_REGEX.test(urlParts.pathname)
|
else if TASKS_REGEX.test(urlParts.pathname)
|
||||||
if request.method == 'POST'
|
if request.method == 'POST'
|
||||||
deviceId = TASKS_REGEX.exec(urlParts.pathname)[1]
|
deviceId = TASKS_REGEX.exec(urlParts.pathname)[1]
|
||||||
if request.content
|
if body
|
||||||
# queue given task
|
# queue given task
|
||||||
task = JSON.parse(request.content)
|
task = JSON.parse(body)
|
||||||
task.device = deviceId
|
task.device = deviceId
|
||||||
task.timestamp = Timestamp()
|
task.timestamp = Timestamp()
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user