Add support for deleting a backup

This commit is contained in:
Dane Everitt 2020-04-09 22:07:48 -07:00
parent 33875105b6
commit 1c235025b7
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
2 changed files with 25 additions and 1 deletions

View File

@ -49,7 +49,6 @@ func Configure() *gin.Engine {
server.POST("/commands", postServerCommands) server.POST("/commands", postServerCommands)
server.POST("/install", postServerInstall) server.POST("/install", postServerInstall)
server.POST("/reinstall", postServerReinstall) server.POST("/reinstall", postServerReinstall)
server.POST("/backup", postServerBackup)
// This archive request causes the archive to start being created // This archive request causes the archive to start being created
// this should only be triggered by the panel. // this should only be triggered by the panel.
@ -65,6 +64,12 @@ func Configure() *gin.Engine {
files.POST("/create-directory", postServerCreateDirectory) files.POST("/create-directory", postServerCreateDirectory)
files.POST("/delete", postServerDeleteFile) files.POST("/delete", postServerDeleteFile)
} }
backup := server.Group("/backup")
{
backup.POST("", postServerBackup)
backup.DELETE("/:backup", deleteServerBackup)
}
} }
return router return router

View File

@ -5,6 +5,7 @@ import (
"github.com/pterodactyl/wings/server" "github.com/pterodactyl/wings/server"
"go.uber.org/zap" "go.uber.org/zap"
"net/http" "net/http"
"os"
) )
// Backs up a server. // Backs up a server.
@ -25,3 +26,21 @@ func postServerBackup(c *gin.Context) {
c.Status(http.StatusAccepted) c.Status(http.StatusAccepted)
} }
// Deletes a local backup of a server.
func deleteServerBackup(c *gin.Context) {
s := GetServer(c.Param("server"))
p, _, err := s.LocateBackup(c.Param("backup"))
if err != nil {
TrackedServerError(err, s).AbortWithServerError(c)
return
}
if err := os.Remove(p); err != nil {
TrackedServerError(err, s).AbortWithServerError(c)
return
}
c.Status(http.StatusNoContent)
}