added reindexing
This commit is contained in:
parent
407ec638fe
commit
bb22097b7b
17 changed files with 226 additions and 47 deletions
|
|
@ -13,6 +13,7 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
|
@ -59,7 +60,7 @@ type Context struct {
|
|||
|
||||
type webData struct {
|
||||
Version string
|
||||
Time int64
|
||||
Time string
|
||||
|
||||
Title string
|
||||
BodyTitle string
|
||||
|
|
@ -98,7 +99,12 @@ func (c *Context) Exec() {
|
|||
}
|
||||
c.Data.User = c.User()
|
||||
c.Data.Login = c.LoggedOn()
|
||||
c.Data.Time = time.Since(c.Time).Nanoseconds() / 1e6
|
||||
|
||||
t := strconv.Itoa(int(time.Since(c.Time).Nanoseconds()/1e6)) + "ms"
|
||||
if t == "0ms" {
|
||||
t = strconv.Itoa(int(time.Since(c.Time).Nanoseconds()/1e5)) + "µs"
|
||||
}
|
||||
c.Data.Time = t
|
||||
|
||||
if c.Data.Msg != "" {
|
||||
c.Status(http.StatusBadRequest)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -48,7 +48,14 @@ var prefixRoutes = []route{
|
|||
jwtHandler(
|
||||
authHandler(
|
||||
indexHandler)),
|
||||
[]string{"GET", "POST"},
|
||||
[]string{"GET"},
|
||||
},
|
||||
{
|
||||
core.ReindexPrefix,
|
||||
jwtHandler(
|
||||
authHandler(
|
||||
indexHandler)),
|
||||
[]string{"GET"},
|
||||
},
|
||||
{
|
||||
core.UploadPrefix,
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue