Support generating a compressed archive for a server via the API

This commit is contained in:
Dane Everitt
2020-07-11 13:13:49 -07:00
parent 79928aff76
commit c1e591c99b
6 changed files with 155 additions and 7 deletions

View File

@@ -83,6 +83,7 @@ func Configure() *gin.Engine {
files.POST("/write", postServerWriteFile)
files.POST("/create-directory", postServerCreateDirectory)
files.POST("/delete", postServerDeleteFile)
files.POST("/compress", postServerCompressFiles)
}
backup := server.Group("/backup")

View File

@@ -3,6 +3,7 @@ package router
import (
"bufio"
"github.com/gin-gonic/gin"
"github.com/pterodactyl/wings/server"
"net/http"
"net/url"
"os"
@@ -188,3 +189,27 @@ func postServerCreateDirectory(c *gin.Context) {
c.Status(http.StatusNoContent)
}
func postServerCompressFiles(c *gin.Context) {
s := GetServer(c.Param("server"))
var data struct {
RootPath string `json:"root"`
Paths []string `json:"paths"`
}
if err := c.BindJSON(&data); err != nil {
return
}
f, err := s.Filesystem.CompressFiles(data.RootPath, data.Paths)
if err != nil {
TrackedServerError(err, s).AbortWithServerError(c)
return
}
c.JSON(http.StatusOK, &server.Stat{
Info: f,
Mimetype: "application/tar+gzip",
})
}