better search view and admin user reset

This commit is contained in:
ston1th 2019-06-11 19:56:08 +02:00
commit 4812a60367
7 changed files with 54 additions and 14 deletions

View file

@ -10,6 +10,7 @@ import (
"git.giftfish.de/ston1th/gowiki/pkg/render"
"git.giftfish.de/ston1th/gowiki/pkg/store"
"io"
"os"
"path/filepath"
)
@ -26,10 +27,11 @@ You can customize it how you like.`
const blevePath = "bleve"
type DB struct {
admin bool
store store.Store
cache *cache.Cache
Index *index.Index
admin bool
store store.Store
cache *cache.Cache
Index *index.Index
indexPath string
}
func New(cfg core.Config) (db *DB, err error) {
@ -43,7 +45,8 @@ func New(cfg core.Config) (db *DB, err error) {
if err != nil {
return
}
db.Index, err = index.NewIndex(filepath.Join(cfg.DataDir, blevePath))
db.indexPath = filepath.Join(cfg.DataDir, blevePath)
db.Index, err = index.New(db.indexPath)
if err != nil {
return
}
@ -77,6 +80,18 @@ func (db *DB) Dump(w io.Writer) error {
}
func (db *DB) Restore(r io.Reader) (err error) {
err = db.Index.Close()
if err != nil {
return
}
err = os.RemoveAll(db.indexPath)
if err != nil {
return
}
db.Index, err = index.New(db.indexPath)
if err != nil {
return
}
err = db.store.Restore(r)
if err != nil {
return