修复:files接口无法正确加载

This commit is contained in:
yystopf 2023-03-20 10:01:03 +08:00
parent a8c396aef6
commit ef95802907
2 changed files with 6 additions and 21 deletions

View File

@ -140,7 +140,7 @@ func Routers(ctx gocontext.Context) *web.Route {
m.Post("", bind(hat_api.BatchChangeFileOptions{}), repo.BatchChangeFile)
}, reqRepoWriter(unit.TypeCode), reqToken())
}, reqRepoReader(unit.TypeCode))
m.Get("/find", reqRepoReader(unit.TypeCode), repo.FindFiles)
m.Get("/find", context.RepoRef(), reqRepoReader(unit.TypeCode), repo.FindFiles)
m.Group("/git", func() {
m.Group("/commits", func() {
m.Get("/{sha}", repo.GetSingleCommit)

View File

@ -266,12 +266,10 @@ func FindFiles(ctx *context.APIContext) {
keyWords := ctx.FormString("q")
var fileList []*SearchFileItem
var err error
if keyWords != "" {
fileList, err = FindFileFromPath(ctx, treePath, ref, keyWords)
if err != nil {
ctx.Error(http.StatusInternalServerError, "FindFileFromPath", err)
return
}
fileList, err = FindFileFromPath(ctx, treePath, ref, keyWords)
if err != nil {
ctx.Error(http.StatusInternalServerError, "FindFileFromPath", err)
return
}
ctx.JSON(http.StatusOK, fileList)
}
@ -287,18 +285,6 @@ type SearchFileItem struct {
}
func FindFileFromPath(ctx *context.APIContext, treePath, ref, key string) (fileList []*SearchFileItem, err error) {
if ctx.Repo.GitRepo == nil {
ctx.Repo.GitRepo, err = git.OpenRepository(ctx, ctx.Repo.Repository.RepoPath())
if err != nil {
ctx.ServerError("OpenRepository", err)
return nil, err
}
defer func() {
if ctx.Repo.GitRepo != nil {
ctx.Repo.GitRepo.Close()
}
}()
}
// get the commit object for the ref
commit, err := ctx.Repo.GitRepo.GetCommit(ref)
if err != nil {
@ -315,7 +301,7 @@ func FindFileFromPath(ctx *context.APIContext, treePath, ref, key string) (fileL
ctx.ServerError("ListEntries", err3)
return nil, err3
}
fileList = make([]*SearchFileItem, 0, 0)
fileList = make([]*SearchFileItem, 0)
for _, entry := range entries {
if entry.IsDir() {
@ -345,7 +331,6 @@ func FindFileFromPath(ctx *context.APIContext, treePath, ref, key string) (fileL
Name: filename,
Path: treePath,
SHA: entry.ID.String(),
Type: entry.Type(),
Size: entry.Size(),
URL: &selfURLString,
HTMLURL: &htmlURLString,