mirror of
https://github.com/eyebluecn/tank.git
synced 2026-10-19 16:14:38 +00:00
feat: search dfs.
This commit is contained in:
@@ -77,6 +77,7 @@ func (this *MatterController) RegisterRoutes() map[string]func(writer http.Respo
|
||||
routeMap := make(map[string]func(writer http.ResponseWriter, request *http.Request))
|
||||
routeMap["/api/matter/detail"] = this.Wrap(this.Detail, USER_ROLE_USER)
|
||||
routeMap["/api/matter/page"] = this.Wrap(this.Page, USER_ROLE_USER)
|
||||
routeMap["/api/matter/search"] = this.Wrap(this.Search, USER_ROLE_USER)
|
||||
|
||||
routeMap["/api/matter/create/directory"] = this.Wrap(this.CreateDirectory, USER_ROLE_USER)
|
||||
routeMap["/api/matter/upload"] = this.Wrap(this.Upload, USER_ROLE_USER)
|
||||
@@ -174,6 +175,34 @@ func (this *MatterController) Page(writer http.ResponseWriter, request *http.Req
|
||||
return this.Success(pager)
|
||||
}
|
||||
|
||||
//DFS search.
|
||||
func (this *MatterController) Search(writer http.ResponseWriter, request *http.Request) *result.WebResult {
|
||||
|
||||
limit := util.ExtractRequestOptionalInt(request, "limit", 200)
|
||||
puuid := util.ExtractRequestString(request, "puuid")
|
||||
keyword := util.ExtractRequestString(request, "keyword")
|
||||
deletedStr := util.ExtractRequestOptionalString(request, "deleted", "")
|
||||
var deleted = false
|
||||
if deletedStr == TRUE {
|
||||
deleted = true
|
||||
}
|
||||
|
||||
user := this.checkUser(request)
|
||||
spaceUuid := util.ExtractRequestOptionalString(request, "spaceUuid", user.SpaceUuid)
|
||||
this.spaceService.CheckReadableByUuid(request, user, spaceUuid)
|
||||
|
||||
matters := this.matterService.DfsSearch(
|
||||
request,
|
||||
limit,
|
||||
puuid,
|
||||
keyword,
|
||||
spaceUuid,
|
||||
deleted,
|
||||
)
|
||||
|
||||
return this.Success(matters)
|
||||
}
|
||||
|
||||
func (this *MatterController) CreateDirectory(writer http.ResponseWriter, request *http.Request) *result.WebResult {
|
||||
|
||||
puuid := util.ExtractRequestString(request, "puuid")
|
||||
|
||||
@@ -354,6 +354,8 @@ func (this *MatterDao) FindByUuids(uuids []string, sortArray []builder.OrderPair
|
||||
|
||||
return matters
|
||||
}
|
||||
|
||||
// pagination is 0 base.
|
||||
func (this *MatterDao) PlainPage(
|
||||
page int,
|
||||
pageSize int,
|
||||
|
||||
@@ -137,6 +137,62 @@ func (this *MatterService) Page(
|
||||
return pager
|
||||
}
|
||||
|
||||
// search files by dfs.
|
||||
func (this *MatterService) DfsSearch(
|
||||
request *http.Request,
|
||||
limit int,
|
||||
puuid string,
|
||||
keyword string,
|
||||
spaceUuid string,
|
||||
deleted bool,
|
||||
) []*Matter {
|
||||
|
||||
deletedStr := FALSE
|
||||
if deleted {
|
||||
deletedStr = FALSE
|
||||
}
|
||||
|
||||
//find all matters including dir and files.
|
||||
_, matters := this.matterDao.PlainPage(0, limit, puuid, "", spaceUuid, keyword, "", deletedStr, nil, nil, nil)
|
||||
if len(matters) >= limit {
|
||||
return matters
|
||||
}
|
||||
|
||||
var resultList []*Matter
|
||||
for _, matter := range matters {
|
||||
if !matter.Dir {
|
||||
resultList = append(resultList, matter)
|
||||
}
|
||||
}
|
||||
|
||||
//dfs from puuid.
|
||||
_, dirMatters := this.matterDao.PlainPage(0, 1000, puuid, "", spaceUuid, keyword, "", "", nil, nil, nil)
|
||||
for _, dirMatter := range dirMatters {
|
||||
|
||||
//add dir if match.
|
||||
if strings.Contains(dirMatter.Name, keyword) {
|
||||
if deleted == dirMatter.Deleted {
|
||||
resultList = append(resultList, dirMatter)
|
||||
}
|
||||
}
|
||||
|
||||
remainLimit := limit - len(resultList)
|
||||
subMatters := this.DfsSearch(request, remainLimit, dirMatter.Uuid, keyword, spaceUuid, deleted)
|
||||
for _, subMatter := range subMatters {
|
||||
resultList = append(resultList, subMatter)
|
||||
}
|
||||
|
||||
//enough then return
|
||||
if len(resultList) >= limit {
|
||||
return resultList
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//not enough ,return.
|
||||
return resultList
|
||||
}
|
||||
|
||||
// Download. Support chunk download.
|
||||
func (this *MatterService) DownloadFile(
|
||||
writer http.ResponseWriter,
|
||||
|
||||
Reference in New Issue
Block a user