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
|
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)
|
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 {
|
type Result struct {
|
||||||
Title string
|
Title string
|
||||||
|
Section string
|
||||||
StoreTitle string
|
StoreTitle string
|
||||||
HTML template.HTML
|
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/render"
|
||||||
"git.giftfish.de/ston1th/gowiki/pkg/store"
|
"git.giftfish.de/ston1th/gowiki/pkg/store"
|
||||||
"io"
|
"io"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -26,10 +27,11 @@ You can customize it how you like.`
|
||||||
const blevePath = "bleve"
|
const blevePath = "bleve"
|
||||||
|
|
||||||
type DB struct {
|
type DB struct {
|
||||||
admin bool
|
admin bool
|
||||||
store store.Store
|
store store.Store
|
||||||
cache *cache.Cache
|
cache *cache.Cache
|
||||||
Index *index.Index
|
Index *index.Index
|
||||||
|
indexPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(cfg core.Config) (db *DB, err error) {
|
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 {
|
if err != nil {
|
||||||
return
|
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 {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -77,6 +80,18 @@ func (db *DB) Dump(w io.Writer) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) Restore(r io.Reader) (err 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)
|
err = db.store.Restore(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -185,6 +185,10 @@ func (db *DB) UpdateUserPassword(username, password string) error {
|
||||||
return db.store.Set(userPrefix+username, u)
|
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 {
|
func (db *DB) AdminUpdateUser(username, password string, admin bool) error {
|
||||||
if username == defUser && !admin {
|
if username == defUser && !admin {
|
||||||
return errors.New("user '" + defUser + "' cannot lose admin privileges")
|
return errors.New("user '" + defUser + "' cannot lose admin privileges")
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"git.giftfish.de/ston1th/godrop/v2"
|
"git.giftfish.de/ston1th/godrop/v2"
|
||||||
"git.giftfish.de/ston1th/gowiki/pkg/core"
|
"git.giftfish.de/ston1th/gowiki/pkg/core"
|
||||||
|
"git.giftfish.de/ston1th/gowiki/pkg/render"
|
||||||
"github.com/blevesearch/bleve"
|
"github.com/blevesearch/bleve"
|
||||||
"github.com/blevesearch/bleve/mapping"
|
"github.com/blevesearch/bleve/mapping"
|
||||||
"html/template"
|
"html/template"
|
||||||
|
|
@ -32,7 +33,7 @@ type Index struct {
|
||||||
i bleve.Index
|
i bleve.Index
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewIndex(path string) (i *Index, err error) {
|
func New(path string) (i *Index, err error) {
|
||||||
var bi bleve.Index
|
var bi bleve.Index
|
||||||
err = godrop.Unveil(path, "rwc")
|
err = godrop.Unveil(path, "rwc")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -102,16 +103,11 @@ func (i *Index) Search(search string) (results []core.Result, err error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
r := core.Result{StoreTitle: hit.ID}
|
r := core.Result{StoreTitle: hit.ID}
|
||||||
|
r.Section, r.Title = render.SplitStoreTitle(hit.ID)
|
||||||
d, err := i.i.Document(hit.ID)
|
d, err := i.i.Document(hit.ID)
|
||||||
if d == nil || err != nil {
|
if d == nil || err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for _, v := range d.Fields {
|
|
||||||
if v.Name() == "title" {
|
|
||||||
r.Title = string(v.Value())
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for fragField, frags := range hit.Fragments {
|
for fragField, frags := range hit.Fragments {
|
||||||
if fragField == "title" || fragField == "search" {
|
if fragField == "title" || fragField == "search" {
|
||||||
for _, f := range frags {
|
for _, f := range frags {
|
||||||
|
|
|
||||||
|
|
@ -453,7 +453,7 @@ const (
|
||||||
<div class="row mt-3">
|
<div class="row mt-3">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
{{range $item := .Data}}
|
{{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>
|
<pre class="wrap">{{$item.HTML}}</pre><br>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@
|
||||||
<div class="row mt-3">
|
<div class="row mt-3">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
{{range $item := .Data}}
|
{{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>
|
<pre class="wrap">{{$item.HTML}}</pre><br>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue