admin: Implement button to delete the entire FILES dir
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
68dad00930
commit
a14c151b04
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@ -143,12 +144,27 @@ func listFiles(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func clearFiles(c *gin.Context) {
|
func clearFiles(c *gin.Context) {
|
||||||
_, err := fic.ClearFiles()
|
err := os.RemoveAll(fic.FilesDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Println("Unable to remove files:", err.Error())
|
||||||
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = os.MkdirAll(fic.FilesDir, 0751)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Unable to create FILES:", err.Error())
|
||||||
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = fic.ClearFiles()
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Unable to clean DB files:", err.Error())
|
||||||
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Les fichiers ont bien été effacés. Mais il n'a pas été possible d'effacer la base de données. Refaites une synchronisation maintenant. " + err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, true)
|
c.JSON(http.StatusOK, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1358,6 +1358,7 @@ angular.module("FICApp")
|
|||||||
$scope.files = File.query();
|
$scope.files = File.query();
|
||||||
$scope.errfnd = null;
|
$scope.errfnd = null;
|
||||||
$scope.errzip = null;
|
$scope.errzip = null;
|
||||||
|
$scope.clearFilesWIP = false;
|
||||||
$scope.fields = ["id", "path", "name", "size"];
|
$scope.fields = ["id", "path", "name", "size"];
|
||||||
|
|
||||||
$scope.clearFiles = function (id) {
|
$scope.clearFiles = function (id) {
|
||||||
@ -1366,6 +1367,21 @@ angular.module("FICApp")
|
|||||||
$scope.files = [];
|
$scope.files = [];
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
$scope.clearFilesDir = function () {
|
||||||
|
$scope.addToast('warning', 'Êtes-vous sûr de vouloir continuer ?', "Ceci va supprimer tout le contenu du dossier FILES. Il s'agit des fichiers ci-dessous, il faudra refaire une synchronisation ensuite.",
|
||||||
|
function () {
|
||||||
|
$scope.clearFilesWIP = true;
|
||||||
|
$http({
|
||||||
|
url: "api/files",
|
||||||
|
method: "DELETE"
|
||||||
|
}).then(function (response) {
|
||||||
|
$scope.clearFilesWIP = false;
|
||||||
|
}, function (response) {
|
||||||
|
$scope.clearFilesWIP = false;
|
||||||
|
$scope.addToast('danger', 'An error occurs when trying to clear files:', response.data.errmsg);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
$scope.gunzipFile = function (f) {
|
$scope.gunzipFile = function (f) {
|
||||||
f.gunzipWIP = true;
|
f.gunzipWIP = true;
|
||||||
$http({
|
$http({
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
<small class="text-muted" ng-if="errzip > 0"><span class="glyphicon glyphicon-exclamation-sign"></span> <ng-pluralize count="errzip" when="{'one': '{} décompression problématique', 'other': '{} décompressions problématiques'}"></ng-pluralize></small>
|
<small class="text-muted" ng-if="errzip > 0"><span class="glyphicon glyphicon-exclamation-sign"></span> <ng-pluralize count="errzip" when="{'one': '{} décompression problématique', 'other': '{} décompressions problématiques'}"></ng-pluralize></small>
|
||||||
<button type="button" ng-click="checksumAll()" class="float-right btn btn-sm" ng-class="{'btn-secondary': errfnd === null, 'btn-success': errfnd === 0, 'btn-danger': errfnd > 0}"><span class="glyphicon glyphicon-flash" aria-hidden="true"></span> Vérifier les fichiers</button>
|
<button type="button" ng-click="checksumAll()" class="float-right btn btn-sm" ng-class="{'btn-secondary': errfnd === null, 'btn-success': errfnd === 0, 'btn-danger': errfnd > 0}"><span class="glyphicon glyphicon-flash" aria-hidden="true"></span> Vérifier les fichiers</button>
|
||||||
<button type="button" ng-click="gunzipFiles()" class="float-right btn btn-sm mx-1" ng-class="{'btn-secondary': errzip === null, 'btn-success': errzip === 0, 'btn-danger': errzip > 0}" title="Décompresse tous les fichiers compressés afin d'afficher la bonne taille au moment du téléchargement"><span class="glyphicon glyphicon-compressed" aria-hidden="true"></span> Gunzip</button>
|
<button type="button" ng-click="gunzipFiles()" class="float-right btn btn-sm mx-1" ng-class="{'btn-secondary': errzip === null, 'btn-success': errzip === 0, 'btn-danger': errzip > 0}" title="Décompresse tous les fichiers compressés afin d'afficher la bonne taille au moment du téléchargement"><span class="glyphicon glyphicon-compressed" aria-hidden="true"></span> Gunzip</button>
|
||||||
|
<button type="button" ng-click="clearFilesDir()" class="float-right btn btn-danger btn-sm mx-1" title="Supprime l'arborescence des fichiers"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Nuke files</button>
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<p><input type="search" class="form-control" placeholder="Search" ng-model="query" autofocus></p>
|
<p><input type="search" class="form-control" placeholder="Search" ng-model="query" autofocus></p>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user