From f987f795817bafd4e6a302fc66daa53e23d41fd6 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Sun, 15 Jan 2012 17:14:18 +0100 Subject: [PATCH] Add a controller for the removal of draggables --- plemp.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plemp.js b/plemp.js index 6e75e22..5155ab2 100644 --- a/plemp.js +++ b/plemp.js @@ -142,6 +142,24 @@ app.post('/draggables/:id', function(req, res) { new_pos.left = req.body.left; }); +// Draggable removal controller: removes the specific draggable from the +// database. +app.del('/draggables/:id', function(req, res) { + var file_id = req.params.id; + console.log("Hello?"); + fs.unlink("public/upload/" + file_id, function(err) { + if (err) { + console.log("Something went wrong while deleting " + + file_id + ": " + err); + res.send(err); + throw err; + } + delete draggables[file_id]; + console.log("Deleted draggable " + file_id); + res.send(true); + }); +}); + // Signal handling. process.on('SIGINT', function() { db.save(draggables); process.exit(0); }); process.on('SIGTERM', function() { db.save(draggables); process.exit(0); });