better search view and admin user reset
This commit is contained in:
parent
c8adfd2ef9
commit
4812a60367
7 changed files with 54 additions and 14 deletions
|
|
@ -190,6 +190,30 @@ func Run(version string) {
|
|||
return nil
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "resetadmin",
|
||||
Usage: "reset the admin users password to the default (gowiki needs to be stopped)",
|
||||
Flags: defaultFlags(nil),
|
||||
Action: func(c *cli.Context) error {
|
||||
var err error
|
||||
if err = loadConfig(); err != nil {
|
||||
stdlog.Fatal("resetadmin: ", err)
|
||||
}
|
||||
DB, err := db.New(config)
|
||||
if err != nil {
|
||||
stdlog.Fatal("resetadmin: ", err)
|
||||
}
|
||||
err = DB.ResetAdmin()
|
||||
if err != nil {
|
||||
stdlog.Fatal("resetadmin: ", err)
|
||||
}
|
||||
err = DB.Close()
|
||||
if err != nil {
|
||||
stdlog.Fatal("resetadmin: ", err)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
}
|
||||
app.Run(os.Args)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ func (u Users) Less(i, j int) bool { return u[i].Username < u[j].Username }
|
|||
|
||||
type Result struct {
|
||||
Title string
|
||||
Section string
|
||||
StoreTitle string
|
||||
HTML template.HTML
|
||||
}
|
||||
|
|
|
|||
25
pkg/db/db.go
25
pkg/db/db.go
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -185,6 +185,10 @@ func (db *DB) UpdateUserPassword(username, password string) error {
|
|||
return db.store.Set(userPrefix+username, u)
|
||||
}
|
||||
|
||||
func (db *DB) ResetAdmin() error {
|
||||
return db.UpdateUserPassword(defUser, defPassword)
|
||||
}
|
||||
|
||||
func (db *DB) AdminUpdateUser(username, password string, admin bool) error {
|
||||
if username == defUser && !admin {
|
||||
return errors.New("user '" + defUser + "' cannot lose admin privileges")
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"errors"
|
||||
"git.giftfish.de/ston1th/godrop/v2"
|
||||
"git.giftfish.de/ston1th/gowiki/pkg/core"
|
||||
"git.giftfish.de/ston1th/gowiki/pkg/render"
|
||||
"github.com/blevesearch/bleve"
|
||||
"github.com/blevesearch/bleve/mapping"
|
||||
"html/template"
|
||||
|
|
@ -32,7 +33,7 @@ type Index struct {
|
|||
i bleve.Index
|
||||
}
|
||||
|
||||
func NewIndex(path string) (i *Index, err error) {
|
||||
func New(path string) (i *Index, err error) {
|
||||
var bi bleve.Index
|
||||
err = godrop.Unveil(path, "rwc")
|
||||
if err != nil {
|
||||
|
|
@ -102,16 +103,11 @@ func (i *Index) Search(search string) (results []core.Result, err error) {
|
|||
continue
|
||||
}
|
||||
r := core.Result{StoreTitle: hit.ID}
|
||||
r.Section, r.Title = render.SplitStoreTitle(hit.ID)
|
||||
d, err := i.i.Document(hit.ID)
|
||||
if d == nil || err != nil {
|
||||
continue
|
||||
}
|
||||
for _, v := range d.Fields {
|
||||
if v.Name() == "title" {
|
||||
r.Title = string(v.Value())
|
||||
break
|
||||
}
|
||||
}
|
||||
for fragField, frags := range hit.Fragments {
|
||||
if fragField == "title" || fragField == "search" {
|
||||
for _, f := range frags {
|
||||
|
|
|
|||
|
|
@ -453,7 +453,7 @@ const (
|
|||
<div class="row mt-3">
|
||||
<div class="col">
|
||||
{{range $item := .Data}}
|
||||
<a href="/{{$item.StoreTitle}}"><b>{{$item.Title}}</b></a>
|
||||
<a href="/{{$item.StoreTitle}}"><b>{{$item.Section}} / {{$item.Title}}</b></a>
|
||||
<pre class="wrap">{{$item.HTML}}</pre><br>
|
||||
{{end}}
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue