Added Backup Update

This commit is contained in:
2022-05-24 15:07:31 -05:00
parent eab7a20533
commit 880b858d01
5 changed files with 80 additions and 7 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
data
vrisingd

View File

@@ -1,2 +1,6 @@
# VRisingD (V Rising Daemon) # VRisingD (V Rising Daemon)
This tool allows for the simple configuration, backup, and starting of a V Rising Server to better assist for Docker deployments using a web page This tool allows for the simple configuration, backup, and starting of a V Rising Server to better assist for Docker deployments using a web page
- [x] Backup Saves
- [x] Update
- [] Upload Config Files

View File

@@ -1,18 +1,27 @@
package main package main
import ( import (
"archive/zip"
"bytes" "bytes"
"io"
"net/http" "net/http"
"os"
"os/exec" "os/exec"
"path/filepath"
"strings"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func index(c *gin.Context) { func check(err error) {
index_page, err := indexHTML.ReadFile("html/index.html")
if err != nil { if err != nil {
panic(err) 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) c.Data(http.StatusOK, "text/html", index_page)
} }
@@ -30,3 +39,55 @@ func update(c *gin.Context) {
c.String(http.StatusOK, out.String()) 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)
}

View File

@@ -1,19 +1,24 @@
<!DOCTYPE html> <!DOCTYPE html>
<header> <header>
<title>Rod Biren</title> <title>Rod</title>
</header> </header>
<body> <body>
<p id="console"> Why Hello There</p> <p id="console"> Why Hello There</p>
<button id="update" type="button" onclick="update()">Update</button> <button id="update" type="button">Update</button>
<form method="get" action="backup.zip">
<button type="submit">Download!</button>
</form>
</body> </body>
<script> <script>
let update_button = document.getElementById("update") let update_button = document.getElementById("update")
let start_button = document.getElementById("start")
let console = document.getElementById("console") let console = document.getElementById("console")
update_button.addEventListener("click",update) update_button.addEventListener("click", update)
async function update() { async function update() {
update_button.disabled = true update_button.disabled = true
console.innerText = "Updating" console.innerText = "Updating"

View File

@@ -19,6 +19,7 @@ func main() {
r.GET("/", index) r.GET("/", index)
r.GET("/api/update", update) r.GET("/api/update", update)
r.GET("/backup.zip", backup)
srv := &http.Server{ srv := &http.Server{
Addr: ":2169", Addr: ":2169",
Handler: r, Handler: r,