Permalink
Browse files

File deletion works

  • Loading branch information...
1 parent d40cedd commit 598139649485fa129c3a5c259617d09f44aec160 @Pita Pita committed Feb 3, 2012
Showing with 32 additions and 2 deletions.
  1. +13 −0 node/handler/FileHandler.js
  2. +16 −0 node/handler/PadMessageHandler.js
  3. +3 −2 static/js/files.js
@@ -96,3 +96,16 @@ exports.listFiles = function(padid, callback){
callback(err, files);
});
}
+
+exports.deleteFile = function(padid, fileName, callback){
+ fs.unlink("../var/files/" + padid + "/" + fileName, function(err){
+ //mute file does not exist error
+ if(err && err.code == 'ENOENT'){
+ err = null;
+ }
+
+ if(ERR(err, callback)) return;
+
+ padMessageHandler.updateClientsWithNewFileList(padid,callback);
+ });
+}
@@ -191,6 +191,11 @@ exports.handleMessage = function(client, message)
{
handleSuggestUserName(client, message);
}
+ else if(message.type == "COLLABROOM" &&
+ message.data.type == "DELETE_FILE")
+ {
+ handleFileDelete(client, message);
+ }
//if the message type is unknown, throw an exception
else
{
@@ -956,3 +961,14 @@ function handleClientReady(client, message)
ERR(err);
});
}
+
+function handleFileDelete(client, message){
+ if(typeof message.data.file !== "string"){
+ messageLogger.warn("Dropped message, DELETE_FILE Message has bad file attribute!");
+ return;
+ }
+
+ var padId = session2pad[client.id];
+
+ fileHandler.deleteFile(padId, message.data.file, ERR);
+}
View
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+
exports.init = function(){
//set the upload iframe url
$("#files iframe").attr("src",document.location.pathname + "/upload?" + clientVars.padId);
@@ -69,5 +69,6 @@ exports.listFiles = function(){
}
exports.deleteFile = function(fileName){
- alert(fileName)
+ var pad = require('/pad2').pad;
+ pad.collabClient.sendMessage({type:"DELETE_FILE", file:fileName});
}

0 comments on commit 5981396

Please sign in to comment.