mirror of https://github.com/Xhofe/alist
				
				
				
			
		
			
				
	
	
		
			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),
 | |
| 	}
 | |
| }
 |