admin: Can delete a repository directory if needed

This commit is contained in:
nemunaire 2025-01-13 17:20:28 +01:00
parent 7692f92aa4
commit c1924c0e92
5 changed files with 48 additions and 4 deletions

View File

@ -41,5 +41,27 @@ func declareRepositoriesRoutes(router *gin.RouterGroup) {
} }
c.JSON(http.StatusOK, mod) c.JSON(http.StatusOK, mod)
}) })
router.DELETE("/repositories/*repopath", func(c *gin.Context) {
di, ok := sync.GlobalImporter.(sync.DeletableImporter)
if !ok {
c.AbortWithStatusJSON(http.StatusNotImplemented, gin.H{"errmsg": "Not implemented"})
return
}
if strings.Contains(c.Param("repopath"), "..") {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": "Repopath contains invalid characters"})
return
}
repopath := strings.TrimPrefix(c.Param("repopath"), "/")
err := di.DeleteDir(repopath)
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": err.Error()})
return
}
c.JSON(http.StatusOK, true)
})
} }
} }

View File

@ -755,6 +755,12 @@ angular.module("FICApp")
$http.get("api/repositories").then(function (response) { $http.get("api/repositories").then(function (response) {
$scope.repositories = response.data.repositories; $scope.repositories = response.data.repositories;
}); });
$scope.deleteRepository = function(repo) {
$http.delete("api/repositories/" + repo.path).then(function (response) {
$scope.repositories[$scope.repositories.indexOf(repo)].hash = "- DELETED -";
});
};
}) })
.component('repositoryUptodate', { .component('repositoryUptodate', {
bindings: { bindings: {

View File

@ -9,16 +9,20 @@
<tr> <tr>
<th>Chemin</th> <th>Chemin</th>
<th>Branche</th> <th>Branche</th>
<th>Commit</th> <th>Commit <span class="text-muted">Plus récent</span></th>
<th>Plus récent</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr ng-repeat="repository in repositories"> <tr ng-repeat="repository in repositories">
<td>{{ repository.path }}</td> <td>{{ repository.path }}</td>
<td>{{ repository.branch }}</td> <td>{{ repository.branch }}</td>
<td>{{ repository.hash }}</td> <td>
<td><repository-uptodate repository="repository" /></td> {{ repository.hash }}<br>
<repository-uptodate repository="repository" />
</td>
<td>
<button type="button" ng-click="deleteRepository(repository)" class="btn btn-sm btn-danger"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>
</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -57,6 +57,10 @@ func (i GitImporter) Kind() string {
return "git originated from " + i.Remote + " on " + i.li.Kind() return "git originated from " + i.Remote + " on " + i.li.Kind()
} }
func (i GitImporter) DeleteDir(filename string) error {
return i.li.DeleteDir(filename)
}
func getForgeBaseLink(remote string) (u *url.URL, err error) { func getForgeBaseLink(remote string) (u *url.URL, err error) {
res := gitRemoteRe.FindStringSubmatch(remote) res := gitRemoteRe.FindStringSubmatch(remote)
u, err = url.Parse(res[2]) u, err = url.Parse(res[2])

View File

@ -113,3 +113,11 @@ func (i LocalImporter) ListDir(filename string) ([]string, error) {
func (i LocalImporter) Stat(filename string) (os.FileInfo, error) { func (i LocalImporter) Stat(filename string) (os.FileInfo, error) {
return os.Stat(path.Join(i.Base, filename)) return os.Stat(path.Join(i.Base, filename))
} }
type DeletableImporter interface {
DeleteDir(filename string) error
}
func (i LocalImporter) DeleteDir(filename string) error {
return os.RemoveAll(path.Join(i.Base, filename))
}