package main import ( "archive/zip" "bytes" "io" "net/http" "os" "os/exec" "path/filepath" "strings" "github.com/gin-gonic/gin" ) func check(err error) { if err != nil { panic(err) } } func index(c *gin.Context) { index_page, err := indexHTML.ReadFile("html/index.html") check(err) c.Data(http.StatusOK, "text/html", index_page) } func update(c *gin.Context) { cmd := exec.Command("awdaawdawd") var out bytes.Buffer cmd.Stdout = &out err := cmd.Run() if err != nil { c.String(http.StatusBadRequest, err.Error()) } else { c.String(http.StatusOK, out.String()) } } func RecursiveZip(pathToZip, destinationPath string) error { os.MkdirAll("data", 0755) destinationFile, err := os.Create(destinationPath) if err != nil { return err } myZip := zip.NewWriter(destinationFile) err = filepath.Walk(pathToZip, func(filePath string, info os.FileInfo, err error) error { if info.IsDir() { return nil } if err != nil { return err } relPath := strings.TrimPrefix(filePath, filepath.Dir(pathToZip)) zipFile, err := myZip.Create(relPath) if err != nil { return err } fsFile, err := os.Open(filePath) if err != nil { return err } _, err = io.Copy(zipFile, fsFile) if err != nil { return err } return nil }) if err != nil { return err } err = myZip.Close() if err != nil { return err } return nil } func backup(c *gin.Context) { err := RecursiveZip("/root/.wine/drive_c/users/root/AppData/LocalLow/Stunlock Studios/VRisingServer/Saves", "data/backup.zip") check(err) backup, err := os.ReadFile("data/backup.zip") check(err) c.Data(http.StatusOK, "application/zip", backup) }