work in progress

This commit is contained in:
ston1th 2018-09-04 23:15:47 +02:00
commit 07ff5ccffb
23 changed files with 228 additions and 240 deletions

View file

@ -6,15 +6,17 @@ import (
"encoding/json"
"fmt"
"os"
"git.giftfish.de/ston1th/gowiki/pkg/core"
)
type Dump struct {
Articles []DumpArticle `json:"articles"`
Snippets []Snippet `json:"snippets"`
Users []User `json:"users"`
type DBDump struct {
Pages []DumpPage `json:"pages"`
Snippets []Snippet `json:"snippets"`
Users []User `json:"users"`
}
type DumpArticle struct {
type DumpPage struct {
Title string `json:"title"`
LinkTitle string `json:"link_title"`
MD string `json:"md"`
@ -29,38 +31,26 @@ func verboseLog(prefix, title string, v bool) {
}
}
func dump(path string, v bool) (err error) {
i, err := NewDumpIndex(path)
if err != nil {
return
}
defer i.Close()
func Dump(path string, v bool) (err error) {
bs, err := NewBoltStore()
if err != nil {
return
}
art, err := i.Get(false, indexName)
if err != nil {
return
}
var dump Dump
titles, err := i.Dump()
if err != nil {
return
}
for _, title := range titles {
art, err = i.Get(false, title)
var dump DBDump
//TODO bs.GetAllPages
var pages []*core.Page
for _, p := range pages {
if err != nil {
return
}
verboseLog("dump:", art.Title, v)
dump.Articles = append(dump.Articles, DumpArticle{
Title: art.Title,
LinkTitle: art.LinkTitle,
MD: art.MD,
Created: art.Created,
Updated: art.Updated,
Public: art.Public,
verboseLog("dump:", p.Title, v)
dump.Pages = append(dump.Pages, DumpPage{
Title: p.Title,
LinkTitle: p.LinkTitle,
MD: p.MD,
Created: p.Created,
Updated: p.Updated,
Public: p.Public,
})
}
//TODO snippets
@ -73,7 +63,7 @@ func dump(path string, v bool) (err error) {
return json.NewEncoder(os.Stdout).Encode(dump)
}
func restore(path string, v bool) (err error) {
func Restore(path string, v bool) (err error) {
i, err := NewIndex(path)
if err != nil {
return
@ -83,7 +73,7 @@ func restore(path string, v bool) (err error) {
if err != nil {
return
}
var dump Dump
var dump DBDump
err = json.NewDecoder(os.Stdin).Decode(&dump)
if err != nil {
return