mirror of
https://github.com/AlistGo/alist.git
synced 2025-05-17 03:32:43 +08:00

* refactor: abstract search interface * wip: ~ * fix cycle import * objs update hook * wip: ~ * Delete search/none * auto update index while cache changed * db searcher TODO: bleve init issue cannot open index, metadata missing * fix size type why float64?? * fix typo * fix nil pointer using * api adapt ui * bleve: fix clear & change struct
43 lines
929 B
Go
43 lines
929 B
Go
package handles
|
|
|
|
import (
|
|
"github.com/alist-org/alist/v3/internal/model"
|
|
"github.com/alist-org/alist/v3/internal/search"
|
|
"github.com/alist-org/alist/v3/pkg/utils"
|
|
"github.com/alist-org/alist/v3/server/common"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type SearchResp struct {
|
|
model.SearchNode
|
|
Type int `json:"type"`
|
|
}
|
|
|
|
func Search(c *gin.Context) {
|
|
var req model.SearchReq
|
|
if err := c.ShouldBind(&req); err != nil {
|
|
common.ErrorResp(c, err, 400)
|
|
return
|
|
}
|
|
if err := req.Validate(); err != nil {
|
|
common.ErrorResp(c, err, 400)
|
|
return
|
|
}
|
|
nodes, total, err := search.Search(c, req)
|
|
if err != nil {
|
|
common.ErrorResp(c, err, 500)
|
|
return
|
|
}
|
|
common.SuccessResp(c, common.PageResp{
|
|
Content: utils.MustSliceConvert(nodes, nodeToSearchResp),
|
|
Total: total,
|
|
})
|
|
}
|
|
|
|
func nodeToSearchResp(node model.SearchNode) SearchResp {
|
|
return SearchResp{
|
|
SearchNode: node,
|
|
Type: utils.GetObjType(node.Name, node.IsDir),
|
|
}
|
|
}
|