diff --git a/main.go b/main.go
index 6ea6c37..8f15b50 100644
--- a/main.go
+++ b/main.go
@@ -9,6 +9,7 @@ import (
"flag"
"fmt"
"html/template"
+ "io"
"io/fs"
"io/ioutil"
"log"
@@ -972,7 +973,70 @@ func (web *Web) createBackup(backupPath string) error {
// backupTest (/backup/test) tests the selected backup file
func (web *Web) backupTest(c *gin.Context) {
+ importID, err := strconv.Atoi(c.Param("id"))
+ if err != nil {
+ c.AbortWithError(http.StatusBadRequest, err)
+ return
+ }
+ if importID < 0 {
+ c.Redirect(http.StatusSeeOther, "/backup/view")
+ return
+ }
+ if !viper.IsSet("database.backup") {
+ c.HTML(http.StatusOK, "backupTest", gin.H{"Error": "database.backup not set"})
+ return
+ }
+ if !viper.IsSet("database.backup.schedule") {
+ c.HTML(http.StatusOK, "backupTest", gin.H{"Error": "database.backup.schedule not set"})
+ return
+ }
+ if !viper.IsSet("database.backup.path") {
+ c.HTML(http.StatusOK, "backupTest", gin.H{"Error": "database.backup.path not set"})
+ return
+ }
+ backupPath := viper.GetString("database.backup.path")
+
+ backupDir, err := filepath.Abs(filepath.Dir(backupPath))
+ if err != nil {
+ c.HTML(http.StatusOK, "backupTest", gin.H{"Error": err})
+ return
+ }
+
+ filesInBackupDir, err := ioutil.ReadDir(backupDir)
+ if err != nil {
+ c.HTML(http.StatusOK, "backupTest", gin.H{"Error": err})
+ return
+ }
+ if importID >= len(filesInBackupDir) {
+ c.Redirect(http.StatusSeeOther, "/backup/view")
+ return
+ }
+
+ backupFileName := filesInBackupDir[importID]
+ backupFullPath := filepath.Join(backupDir, backupFileName.Name())
+ backupFile, err := os.Open(backupFullPath)
+ if err != nil {
+ c.HTML(http.StatusOK, "backupTest", gin.H{"Error": err})
+ return
+ }
+ defer backupFile.Close()
+
+ backupReader, err := gzip.NewReader(backupFile)
+ if err != nil {
+ c.HTML(http.StatusOK, "backupTest", gin.H{"Error": err})
+ return
+ }
+ defer backupReader.Close()
+ rawBytes, err := io.ReadAll(backupReader)
+
+ var backup Backup
+ json.Unmarshal(rawBytes, &backup)
+
+ c.HTML(http.StatusOK, "backupTest", gin.H{
+ "Backup": backup,
+ "BackupPath": backupFullPath,
+ })
}
// exportWatch (/watch/export/:id) creates a json export of the current watch
diff --git a/templates/backup/test.html b/templates/backup/test.html
index 728b63a..639564c 100644
--- a/templates/backup/test.html
+++ b/templates/backup/test.html
@@ -4,40 +4,66 @@ GoWatch Backups
{{define "content"}}
-
- Backups
+
+ Backup Test: {{ .BackupPath }}
{{ if .Error }}
-
+
{{ .Error }}
{{ end }}
-
+
+ Watches
- File |
- Test |
- Restore |
+ ID |
+ Name |
- {{ range $i, $backup := .Backups }}
+ {{ range $watch := .Backup.Watches }}
- {{ $backup }} |
-
-
- Test
-
- |
-
-
- Restore
-
- |
+ {{ $watch.ID }} |
+ {{ $watch.Name }} |
{{ end }}
+
+ Stored Values: {{ len .Backup.Values }}
+
+
+ Filters
+
+
+ ID |
+ WatchID |
+ Name |
+ Type |
+ Var1 |
+ Var2 |
+ Var3 |
+ X/Y |
+
+
+
+ {{ range $filter := .Backup.Filters }}
+
+ {{ $filter.ID }} |
+ {{ $filter.WatchID }} |
+ {{ $filter.Name }} |
+ {{ $filter.Type }} |
+ {{ $filter.Var1 }} |
+ {{ $filter.Var2 }} |
+ {{ $filter.Var3 }} |
+ {{ $filter.X }}/{{ $filter.Y }} |
+
+ {{ end }}
+
+
+
+ FilterConnections: {{ len .Backup.Connections }}
+
{{end}}
\ No newline at end of file
diff --git a/templates/backup/view.html b/templates/backup/view.html
index 9de6937..00d4ac3 100644
--- a/templates/backup/view.html
+++ b/templates/backup/view.html
@@ -26,7 +26,7 @@ GoWatch Backups
{{ $backup }} |
-
+
Test
|
diff --git a/todo.md b/todo.md
index c3430f9..231b603 100644
--- a/todo.md
+++ b/todo.md
@@ -6,7 +6,7 @@
- edit.ts
- diagram.ts
- ~~scheduled backup~~
- - test
+ - ~~test~~
- restore
- delete
- download