added reindexing
This commit is contained in:
parent
407ec638fe
commit
bb22097b7b
17 changed files with 226 additions and 47 deletions
|
|
@ -206,11 +206,26 @@ func scanFile(ctx *Context, path string) (err error) {
|
|||
}
|
||||
|
||||
func indexHandler(ctx *Context) {
|
||||
path := strings.TrimPrefix(ctx.Path(), core.IndexPrefix)
|
||||
switch ctx.Method() {
|
||||
case "GET":
|
||||
err := scanFile(ctx, path)
|
||||
p, _ := filepath.Split(path)
|
||||
var (
|
||||
err error
|
||||
fpath string
|
||||
)
|
||||
path := ctx.Path()
|
||||
if strings.HasPrefix(path, core.IndexPrefix) {
|
||||
fpath = strings.TrimPrefix(path, core.IndexPrefix)
|
||||
err = scanFile(ctx, fpath)
|
||||
}
|
||||
if strings.HasPrefix(path, core.ReindexPrefix) {
|
||||
fpath = strings.TrimPrefix(path, core.ReindexPrefix)
|
||||
if fpath == "" {
|
||||
err = ctx.Srv.DB.ReindexAll()
|
||||
} else {
|
||||
err = ctx.Srv.DB.Reindex(fpath, nil)
|
||||
}
|
||||
}
|
||||
p, _ := filepath.Split(fpath)
|
||||
p = filepath.Dir(p)
|
||||
if err != nil {
|
||||
ctx.Template("iseHandler")
|
||||
|
|
@ -429,10 +444,10 @@ func dirHandler(ctx *Context) {
|
|||
}
|
||||
switch mode {
|
||||
case fs.IsDir:
|
||||
ctx.Data = webData{
|
||||
Title: "Directory Viewer",
|
||||
}
|
||||
dir := ctx.Srv.FS.ReadDir(path)
|
||||
ctx.Data = webData{
|
||||
Title: "Directory Viewer | " + path,
|
||||
}
|
||||
ctx.Srv.DB.GetIndexed(dir.Files)
|
||||
ctx.Data.Path = path
|
||||
ctx.Data.Data = dir
|
||||
|
|
@ -440,7 +455,7 @@ func dirHandler(ctx *Context) {
|
|||
ctx.Exec()
|
||||
case fs.IsFile:
|
||||
ctx.Data = webData{
|
||||
Title: "Document Viewer",
|
||||
Title: "Document Viewer | " + path,
|
||||
}
|
||||
ctx.Template("fileHandler")
|
||||
ctx.Data.Data = core.Path{
|
||||
|
|
@ -566,12 +581,12 @@ func searchHandler(ctx *Context) {
|
|||
if !ctx.CheckXsrf() {
|
||||
return
|
||||
}
|
||||
ctx.Data.Search = ctx.Form("search")
|
||||
if ctx.Data.Search == "" {
|
||||
ctx.Error("empty search request")
|
||||
return
|
||||
s := ctx.Form("search")
|
||||
ctx.Data.Search = s
|
||||
if s == "" {
|
||||
s = `""`
|
||||
}
|
||||
res, err := ctx.Srv.DB.Index.Search(ctx.Data.Search)
|
||||
res, err := ctx.Srv.DB.Index.Search(s)
|
||||
if err != nil {
|
||||
ctx.Error(err)
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue