forked from Gitlink/gitea-1120-rc1
add search file
This commit is contained in:
parent
20ccfce2a3
commit
8d214da2fc
|
@ -676,7 +676,7 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
m.Get("", viewfile.CommitCount)
|
||||
})
|
||||
m.Group("/releases", func() {
|
||||
m.Get("/latest", viewfile.LatestRelease)
|
||||
m.Get("/latest", viewfile.LatestRelease) //待确认 to do;
|
||||
})
|
||||
//
|
||||
m.Group("/find", func() {
|
||||
|
|
|
@ -983,9 +983,9 @@ func FindFiles(ctx *context.APIContext) {
|
|||
ref = ctx.Repo.Repository.DefaultBranch
|
||||
}
|
||||
fmt.Println("***ref:",ref)
|
||||
keyword:= ctx.QueryTrim("keyword")
|
||||
keyword:= ctx.QueryTrim("q")
|
||||
if keyword == "" {
|
||||
keyword="README" //test
|
||||
//keyword="README" //test
|
||||
}
|
||||
|
||||
FindList,err:=FindFileFromPathExt(ctx,treePath,ref,keyword)
|
||||
|
@ -1014,38 +1014,47 @@ func FindFileFromPathExt(ctx *context.APIContext, treePath, ref, key string) (fi
|
|||
}
|
||||
}()
|
||||
}
|
||||
|
||||
|
||||
// Get the commit object for the ref
|
||||
commit, err := ctx.Repo.GitRepo.GetCommit(ref)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
tree, err := commit.SubTree(treePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
entries, err := tree.ListEntries()
|
||||
//entries, err := tree.ListEntries()
|
||||
//if err != nil {
|
||||
// return nil, err
|
||||
//}
|
||||
entries, err := tree.ListEntriesRecursive()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fileList =make([]*SearchFileItem,0,0)
|
||||
|
||||
for _, entry := range entries {
|
||||
if entry.IsDir() {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(strings.ToLower(entry.Name()),strings.ToLower( key)) || key=="" {
|
||||
if strings.Contains(strings.ToLower(entry.Name()),strings.ToLower(key)) || key=="" {
|
||||
name := entry.Name()
|
||||
isSymlink := entry.IsLink()
|
||||
target := entry
|
||||
_=target
|
||||
|
||||
if isSymlink {
|
||||
target, err = entry.FollowLinks()
|
||||
if err != nil && !git.IsErrBadLink(err) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
//isSymlink := entry.IsLink()
|
||||
//target := entry
|
||||
//_=target
|
||||
//
|
||||
//if isSymlink {
|
||||
// target, err = entry.FollowLinks()
|
||||
// if err != nil && !git.IsErrBadLink(err) {
|
||||
// return nil, err
|
||||
// }
|
||||
//}
|
||||
treePath=name
|
||||
selfURL, err := url.Parse(fmt.Sprintf("%s/contents/%s?ref=%s", ctx.Repo.Repository.APIURL(), treePath, ref))
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue