admin: Can delete a repository directory if needed
This commit is contained in:
parent
7692f92aa4
commit
c1924c0e92
5 changed files with 48 additions and 4 deletions
|
@ -41,5 +41,27 @@ func declareRepositoriesRoutes(router *gin.RouterGroup) {
|
|||
}
|
||||
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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue