admin: Implement button to delete the entire FILES dir
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
nemunaire 2025-01-14 15:53:12 +01:00
parent 68dad00930
commit a14c151b04
3 changed files with 34 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt"
"log"
"net/http"
"os"
"path/filepath"
"strconv"
@ -143,12 +144,27 @@ func listFiles(c *gin.Context) {
}
func clearFiles(c *gin.Context) {
_, err := fic.ClearFiles()
err := os.RemoveAll(fic.FilesDir)
if err != nil {
log.Println("Unable to remove files:", err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
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)
}

View File

@ -1358,6 +1358,7 @@ angular.module("FICApp")
$scope.files = File.query();
$scope.errfnd = null;
$scope.errzip = null;
$scope.clearFilesWIP = false;
$scope.fields = ["id", "path", "name", "size"];
$scope.clearFiles = function (id) {
@ -1366,6 +1367,21 @@ angular.module("FICApp")
$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) {
f.gunzipWIP = true;
$http({

View File

@ -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>
<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="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>
<p><input type="search" class="form-control" placeholder="Search" ng-model="query" autofocus></p>