mirror of
https://github.com/schollz/cowyo.git
synced 2023-08-10 21:13:00 +03:00
Added restoration routes
Former-commit-id: 822e9b62b8c72965c0733f8d2b035291ab4d8613 [formerly cf916cceb9a12def41c854a0b1430ffbf25ef4ca] [formerly f2bf6102389e65d58b6cb6b7c57516d794bb5658 [formerly 796e92eed1
]]
Former-commit-id: 94e2f000d63311cc44d8300f0c931edc01b5ed43 [formerly 71b130845411a9462beee94bcae12ff890d3be96]
Former-commit-id: f99a1f31fa2153a8d0e2c09e8a96562bce107544
This commit is contained in:
parent
f23613399f
commit
c89f019084
32
main.go
32
main.go
@ -1,11 +1,14 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/boltdb/bolt"
|
"github.com/boltdb/bolt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@ -32,6 +35,8 @@ var RuntimeArgs struct {
|
|||||||
AdminKey string
|
AdminKey string
|
||||||
Socket string
|
Socket string
|
||||||
ForceWss bool
|
ForceWss bool
|
||||||
|
DumpDataset string
|
||||||
|
RestoreDataset string
|
||||||
}
|
}
|
||||||
var VersionNum string
|
var VersionNum string
|
||||||
|
|
||||||
@ -51,7 +56,8 @@ func main() {
|
|||||||
flag.StringVar(&RuntimeArgs.ServerKey, "key", "", "location of SSL key")
|
flag.StringVar(&RuntimeArgs.ServerKey, "key", "", "location of SSL key")
|
||||||
flag.StringVar(&RuntimeArgs.WikiName, "w", "cowyo", "custom name for wiki")
|
flag.StringVar(&RuntimeArgs.WikiName, "w", "cowyo", "custom name for wiki")
|
||||||
flag.BoolVar(&RuntimeArgs.ForceWss, "e", false, "force encrypted sockets (use if using Caddy auto HTTPS)")
|
flag.BoolVar(&RuntimeArgs.ForceWss, "e", false, "force encrypted sockets (use if using Caddy auto HTTPS)")
|
||||||
dumpDataset := flag.Bool("dump", false, "flag to dump all data to 'dump' directory")
|
flag.StringVar(&RuntimeArgs.DumpDataset, "dump", "", "directory to dump all data to")
|
||||||
|
flag.StringVar(&RuntimeArgs.RestoreDataset, "restore", "", "directory to restore all data from")
|
||||||
flag.CommandLine.Usage = func() {
|
flag.CommandLine.Usage = func() {
|
||||||
fmt.Println(`cowyo (version ` + VersionNum + `)
|
fmt.Println(`cowyo (version ` + VersionNum + `)
|
||||||
|
|
||||||
@ -70,9 +76,9 @@ Options:`)
|
|||||||
}
|
}
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *dumpDataset {
|
if len(RuntimeArgs.DumpDataset) > 0 {
|
||||||
fmt.Println("Dumping data to 'dump' folder...")
|
fmt.Println("Dumping data to '" + RuntimeArgs.DumpDataset + "' folder...")
|
||||||
dumpEverything()
|
dumpEverything(RuntimeArgs.DumpDataset)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,6 +111,11 @@ Options:`)
|
|||||||
p := WikiData{"help", "", []string{}, []string{}, false, "zzz"}
|
p := WikiData{"help", "", []string{}, []string{}, false, "zzz"}
|
||||||
p.save(string(aboutFile))
|
p.save(string(aboutFile))
|
||||||
|
|
||||||
|
if len(RuntimeArgs.RestoreDataset) > 0 {
|
||||||
|
fmt.Println("Restoring data from '" + RuntimeArgs.RestoreDataset + "' folder...")
|
||||||
|
filepath.Walk(RuntimeArgs.RestoreDataset, restoreFile)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
// var q WikiData
|
// var q WikiData
|
||||||
// q.load("about")
|
// q.load("about")
|
||||||
// fmt.Println(getImportantVersions(q))
|
// fmt.Println(getImportantVersions(q))
|
||||||
@ -139,3 +150,16 @@ Options:`)
|
|||||||
r.Run(RuntimeArgs.Port)
|
r.Run(RuntimeArgs.Port)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func restoreFile(path string, f os.FileInfo, err error) error {
|
||||||
|
fName := filepath.Base(path)
|
||||||
|
buf := bytes.NewBuffer(nil)
|
||||||
|
fOpen, _ := os.Open(path) // Error handling elided for brevity.
|
||||||
|
io.Copy(buf, fOpen) // Error handling elided for brevity.
|
||||||
|
fOpen.Close()
|
||||||
|
s := string(buf.Bytes())
|
||||||
|
fmt.Println(fName)
|
||||||
|
p := WikiData{fName, "", []string{}, []string{}, false, ""}
|
||||||
|
p.save(s)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -578,10 +578,10 @@ func listEverything() string {
|
|||||||
return everything
|
return everything
|
||||||
}
|
}
|
||||||
|
|
||||||
func dumpEverything() {
|
func dumpEverything(folderpath string) {
|
||||||
Open(RuntimeArgs.DatabaseLocation)
|
Open(RuntimeArgs.DatabaseLocation)
|
||||||
defer Close()
|
defer Close()
|
||||||
err := os.MkdirAll("dump", 0777)
|
err := os.MkdirAll(folderpath, 0777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Already exists")
|
fmt.Println("Already exists")
|
||||||
}
|
}
|
||||||
@ -593,7 +593,7 @@ func dumpEverything() {
|
|||||||
var p WikiData
|
var p WikiData
|
||||||
p.load(string(k))
|
p.load(string(k))
|
||||||
fmt.Println(string(k), len(p.CurrentText))
|
fmt.Println(string(k), len(p.CurrentText))
|
||||||
ioutil.WriteFile(path.Join("dump", string(k)+".md"), []byte(p.CurrentText), 0644)
|
ioutil.WriteFile(path.Join(folderpath, string(k)), []byte(p.CurrentText), 0644)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user