diff --git a/admin/api/file.go b/admin/api/file.go index b73058f1..a70dd9ba 100644 --- a/admin/api/file.go +++ b/admin/api/file.go @@ -15,6 +15,8 @@ func init() { router.GET("/api/files/:fileid", apiHandler(fileHandler(showFile))) router.PUT("/api/files/:fileid", apiHandler(fileHandler(updateFile))) router.DELETE("/api/files/:fileid", apiHandler(fileHandler(deleteFile))) + + router.POST("/api/files/:fileid/check", apiHandler(fileHandler(checkFile))) } func listFiles(_ httprouter.Params, body []byte) (interface{}, error) { @@ -48,3 +50,7 @@ func updateFile(file fic.EFile, body []byte) (interface{}, error) { func deleteFile(file fic.EFile, _ []byte) (interface{}, error) { return file.Delete() } + +func checkFile(file fic.EFile, _ []byte) (interface{}, error) { + return true, file.CheckFileOnDisk() +} diff --git a/admin/static/js/app.js b/admin/static/js/app.js index 14021e07..ec640c9b 100644 --- a/admin/static/js/app.js +++ b/admin/static/js/app.js @@ -695,6 +695,7 @@ angular.module("FICApp") .controller("FilesListController", function($scope, File, $location, $http, $rootScope) { $scope.files = File.query(); + $scope.errfnd = 0; $scope.fields = ["id", "path", "name", "checksum", "size"]; $scope.clearFiles = function(id) { @@ -704,17 +705,18 @@ angular.module("FICApp") }; $scope.checksum = function(f) { $http({ - url: "/api/files/" + f.id + "/checksum", - method: "GET" + url: "/api/files/" + f.id + "/check", + method: "POST" }).then(function(response) { - if (response.data) - $rootScope.newBox('danger', response.data); + f.err = true; }, function(response) { $scope.inSync = false; - $rootScope.newBox('danger', 'An error occurs when checking files:', response.data); + $scope.errfnd += 1; + f.err = response.data.errmsg; }) }; $scope.checksumAll = function() { + $scope.errfnd = 0; angular.forEach($scope.files, function(file) { $scope.checksum(file); }); diff --git a/admin/static/views/file-list.html b/admin/static/views/file-list.html index cbfdc4de..92f6eb95 100644 --- a/admin/static/views/file-list.html +++ b/admin/static/views/file-list.html @@ -1,5 +1,6 @@