mirror of https://github.com/Xhofe/alist
feat: search api
parent
6591af58ea
commit
a73a40133d
|
@ -258,6 +258,13 @@ func InitSettings() {
|
||||||
Access: model.PRIVATE,
|
Access: model.PRIVATE,
|
||||||
Group: model.BACK,
|
Group: model.BACK,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Key: "enable search",
|
||||||
|
Value: "false",
|
||||||
|
Type: "bool",
|
||||||
|
Access: model.PUBLIC,
|
||||||
|
Group: model.BACK,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for i, _ := range settings {
|
for i, _ := range settings {
|
||||||
v := settings[i]
|
v := settings[i]
|
||||||
|
|
|
@ -85,6 +85,7 @@ var (
|
||||||
"Visitor WebDAV username", "Visitor WebDAV password",
|
"Visitor WebDAV username", "Visitor WebDAV password",
|
||||||
"default page size", "load type",
|
"default page size", "load type",
|
||||||
"ocr api", "favicon",
|
"ocr api", "favicon",
|
||||||
|
"enable search",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,9 @@ func SaveSearchFiles[T model.ISearchFile](key string, obj []T) {
|
||||||
|
|
||||||
func SetCache[T model.ISearchFile](path string, obj []T, account *model.Account) error {
|
func SetCache[T model.ISearchFile](path string, obj []T, account *model.Account) error {
|
||||||
key := KeyCache(path, account)
|
key := KeyCache(path, account)
|
||||||
|
if conf.GetBool("enable search") {
|
||||||
go SaveSearchFiles(key, obj)
|
go SaveSearchFiles(key, obj)
|
||||||
|
}
|
||||||
return conf.Cache.Set(conf.Ctx, key, obj, nil)
|
return conf.Cache.Set(conf.Ctx, key, obj, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
package controllers
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/Xhofe/alist/conf"
|
||||||
|
"github.com/Xhofe/alist/model"
|
||||||
|
"github.com/Xhofe/alist/server/common"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SearchReq struct {
|
||||||
|
Path string `json:"path"`
|
||||||
|
Keyword string `json:"keyword"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func Search(c *gin.Context) {
|
||||||
|
if conf.GetBool("enable search") {
|
||||||
|
common.ErrorStrResp(c, "Not allowed search", 403)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var req SearchReq
|
||||||
|
if err := c.ShouldBind(&req); err != nil {
|
||||||
|
common.ErrorResp(c, err, 400)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
files, err := model.SearchByNameAndPath(req.Path, req.Keyword)
|
||||||
|
if err != nil {
|
||||||
|
common.ErrorResp(c, err, 500)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
common.SuccessResp(c, files)
|
||||||
|
}
|
|
@ -25,6 +25,8 @@ func InitApiRouter(r *gin.Engine) {
|
||||||
path.POST("/path", controllers.Path)
|
path.POST("/path", controllers.Path)
|
||||||
path.POST("/preview", controllers.Preview)
|
path.POST("/preview", controllers.Preview)
|
||||||
|
|
||||||
|
public.POST("/search", controllers.Search)
|
||||||
|
|
||||||
//path.POST("/link",middlewares.Auth, controllers.Link)
|
//path.POST("/link",middlewares.Auth, controllers.Link)
|
||||||
public.POST("/upload", file.UploadFiles)
|
public.POST("/upload", file.UploadFiles)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue