feat(files): add search API and tests

This commit is contained in:
hexxa 2022-07-23 13:01:43 +08:00 committed by Hexxa
parent 4fbdee0eca
commit 826d472a96
6 changed files with 85 additions and 1 deletions

View file

@ -30,6 +30,7 @@ const (
FilePathQuery = "fp"
ListDirQuery = "dp"
ShareIDQuery = "shid"
Keyword = "k"
// headers
rangeHeader = "Range"
@ -1151,6 +1152,25 @@ func (h *FileHandlers) GetSharingDir(c *gin.Context) {
c.JSON(200, &GetSharingDirResp{SharingDir: dirPath})
}
type SearchItemsResp struct {
Results []string `json:"results"`
}
func (h *FileHandlers) SearchItems(c *gin.Context) {
keyword := c.Query(Keyword)
if keyword == "" {
c.JSON(q.ErrResp(c, 400, errors.New("empty keyword")))
return
}
results, err := h.deps.FileIndex().Search(keyword)
if err != nil {
c.JSON(q.ErrResp(c, 500, err))
return
}
c.JSON(200, &SearchItemsResp{Results: results})
}
func (h *FileHandlers) GetStreamReader(userID uint64, fd io.Reader) (io.ReadCloser, error) {
pr, pw := io.Pipe()

View file

@ -61,6 +61,7 @@ func NewMultiUsersSvc(cfg gocfg.ICfg, deps *depidx.Deps) (*MultiUsersSvc, error)
apiRuleCname(db.AdminRole, "GET", "/v1/fs/files/chunks"): true,
apiRuleCname(db.AdminRole, "PATCH", "/v1/fs/files/copy"): true,
apiRuleCname(db.AdminRole, "PATCH", "/v1/fs/files/move"): true,
apiRuleCname(db.AdminRole, "GET", "/v1/fs/search"): true,
apiRuleCname(db.AdminRole, "GET", "/v1/fs/dirs"): true,
apiRuleCname(db.AdminRole, "GET", "/v1/fs/dirs/home"): true,
apiRuleCname(db.AdminRole, "POST", "/v1/fs/dirs"): true,
@ -98,6 +99,7 @@ func NewMultiUsersSvc(cfg gocfg.ICfg, deps *depidx.Deps) (*MultiUsersSvc, error)
apiRuleCname(db.UserRole, "GET", "/v1/fs/files/chunks"): true,
apiRuleCname(db.UserRole, "PATCH", "/v1/fs/files/copy"): true,
apiRuleCname(db.UserRole, "PATCH", "/v1/fs/files/move"): true,
apiRuleCname(db.UserRole, "GET", "/v1/fs/search"): true,
apiRuleCname(db.UserRole, "GET", "/v1/fs/dirs"): true,
apiRuleCname(db.UserRole, "GET", "/v1/fs/dirs/home"): true,
apiRuleCname(db.UserRole, "POST", "/v1/fs/dirs"): true,