Changed path for delete, retry actions on tasks

This commit is contained in:
Zaid Abdulla committed 2013-03-01 18:07:33 +03:00
1 parent dcfd102f9c
commit 488afa53bb
1 file changed
+8 -9
+8 -9
View File
@@ -7,8 +7,8 @@ mongodb = require 'mongodb'
querystring = require 'querystring' querystring = require 'querystring'
# regular expression objects # regular expression objects
TASKS_REGEX = /^\/devices\/([a-zA-Z0-9\-\_\%]+)\/tasks\/?$/ DEVICE_TASKS_REGEX = /^\/devices\/([a-zA-Z0-9\-\_\%]+)\/tasks\/?$/
TASK_REGEX = /^\/devices\/([a-zA-Z0-9\-\_\%]+)\/tasks\/([a-zA-Z0-9\-\_\%]+)(\/[a-zA-Z_]*)?$/ TASKS_REGEX = /^\/tasks\/([a-zA-Z0-9\-\_\%]+)(\/[a-zA-Z_]*)?$/
TAGS_REGEX = /^\/devices\/([a-zA-Z0-9\-\_\%]+)\/tags\/([a-zA-Z0-9\-\_\%]+)\/?$/ TAGS_REGEX = /^\/devices\/([a-zA-Z0-9\-\_\%]+)\/tags\/([a-zA-Z0-9\-\_\%]+)\/?$/
PRESETS_REGEX = /^\/presets\/([a-zA-Z0-9\-\_\%]+)\/?$/ PRESETS_REGEX = /^\/presets\/([a-zA-Z0-9\-\_\%]+)\/?$/
FILES_REGEX = /^\/files\/([a-zA-Z0-9\-\_\%\ \.\/\(\)]+)\/?$/ FILES_REGEX = /^\/files\/([a-zA-Z0-9\-\_\%\ \.\/\(\)]+)\/?$/
@@ -159,9 +159,9 @@ else
else else
response.writeHead 405, {'Allow': 'POST, DELETE'} 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 DEVICE_TASKS_REGEX.test(urlParts.pathname)
if request.method == 'POST' if request.method == 'POST'
deviceId = querystring.unescape(TASKS_REGEX.exec(urlParts.pathname)[1]) deviceId = querystring.unescape(DEVICE_TASKS_REGEX.exec(urlParts.pathname)[1])
if body if body
# queue given task # queue given task
task = sanitizeTask(deviceId, JSON.parse(body)) task = sanitizeTask(deviceId, JSON.parse(body))
@@ -214,11 +214,10 @@ else
else else
response.writeHead 405, {'Allow': 'POST'} response.writeHead 405, {'Allow': 'POST'}
response.end('405 Method Not Allowed') response.end('405 Method Not Allowed')
else if TASK_REGEX.test(urlParts.pathname) else if TASKS_REGEX.test(urlParts.pathname)
r = TASK_REGEX.exec(urlParts.pathname) r = TASKS_REGEX.exec(urlParts.pathname)
deviceId = querystring.unescape(r[1]) taskId = mongodb.ObjectID(querystring.unescape(r[1]))
taskId = mongodb.ObjectID(querystring.unescape(r[2])) action = try querystring.unescape(r[2])
action = try querystring.unescape(r[3])
if not action? or action is '/' if not action? or action is '/'
if request.method == 'DELETE' if request.method == 'DELETE'
db.tasksCollection.remove({'_id' : taskId}, (err, removedCount) -> db.tasksCollection.remove({'_id' : taskId}, (err, removedCount) ->