diff --git a/api/server.js b/api/server.js index a21273b..fbd9687 100644 --- a/api/server.js +++ b/api/server.js @@ -68,6 +68,10 @@ app.get('/file', function(req, res) { return -f.lastModification; }); + files = _.remove(files, function(e){ + return e; + }); + if (files.length > 50) { files = files.slice(0, 50); } @@ -241,6 +245,25 @@ app.post('/file/:key(\\d+)', function(req, res) { }, DELAY); }); +/** + * Delete the file. + * + */ +app.delete('/file/:key(\\d+)', function(req, res) { + var key = decodeURIComponent(req.params.key); + + if (!FILE_DB[key]) { + return res.send(404, 'Sorry, we cannot find that!'); + } + + FILE_DB[key] = false; + + setTimeout(function() { + res.send({}); + }, DELAY); + +}); + app.listen(9090); console.log('Listening on port 9090'); diff --git a/app/assets/app.js b/app/assets/app.js index 2882e5b..10fb1d3 100644 --- a/app/assets/app.js +++ b/app/assets/app.js @@ -41055,7 +41055,7 @@ var JSEncrypt = JSEncryptExports.JSEncrypt; ;angular.module('app.services', ['app.config']). factory('files', function(API_BASE, $resource, $http){ - var res = $resource(API_BASE + '/file/:key'); + var res = $resource(API_BASE + '/file/:key', {key:'@key'}); return { all: function() { return res.query().$promise; @@ -41076,13 +41076,28 @@ var JSEncrypt = JSEncryptExports.JSEncrypt; ;;angular.module('app.homePages', ['app.config', 'app.services', 'ngResource', 'ngAnimate', 'angularSpinkit']). - controller('HomeCtrl', function($scope, files) { + controller('HomeCtrl', function($scope, $window, files) { $scope.files = []; $scope.loading = true; $scope.urlFor = function(file) { + if (!file || $window._.isUndefined(file.key)) { + return; + } + return '/#/file/' + encodeURIComponent(file.key); }; + + $scope.delete = function(file) { + var index; + if ($window.confirm("Are you sure you want to delete " + file.name)) { + index = $scope.files.indexOf(file); + file.$delete().then(function(){ + $scope.files.splice(index, index+1); + }); + } + + }; files.all().then(function(data) { $scope.loading = false; diff --git a/app/scripts/homePages.js b/app/scripts/homePages.js index 10008e4..76d8c89 100644 --- a/app/scripts/homePages.js +++ b/app/scripts/homePages.js @@ -1,12 +1,27 @@ angular.module('app.homePages', ['app.config', 'app.services', 'ngResource', 'ngAnimate', 'angularSpinkit']). - controller('HomeCtrl', function($scope, files) { + controller('HomeCtrl', function($scope, $window, files) { $scope.files = []; $scope.loading = true; $scope.urlFor = function(file) { + if (!file || $window._.isUndefined(file.key)) { + return; + } + return '/#/file/' + encodeURIComponent(file.key); }; + + $scope.delete = function(file) { + var index; + if ($window.confirm("Are you sure you want to delete " + file.name)) { + index = $scope.files.indexOf(file); + file.$delete().then(function(){ + $scope.files.splice(index, index+1); + }); + } + + }; files.all().then(function(data) { $scope.loading = false; diff --git a/app/scripts/services.js b/app/scripts/services.js index 4853133..eeba281 100644 --- a/app/scripts/services.js +++ b/app/scripts/services.js @@ -1,7 +1,7 @@ angular.module('app.services', ['app.config']). factory('files', function(API_BASE, $resource, $http){ - var res = $resource(API_BASE + '/file/:key'); + var res = $resource(API_BASE + '/file/:key', {key:'@key'}); return { all: function() { return res.query().$promise; diff --git a/app/templates/home.html b/app/templates/home.html index 7fa9768..3a45b70 100644 --- a/app/templates/home.html +++ b/app/templates/home.html @@ -25,9 +25,10 @@