|
|
@ -9,6 +9,8 @@ import ( |
|
|
|
|
|
|
|
|
|
|
|
"github.com/Unknwon/paginater" |
|
|
|
"github.com/Unknwon/paginater" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"bytes" |
|
|
|
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models" |
|
|
|
"code.gitea.io/gitea/models" |
|
|
|
"code.gitea.io/gitea/modules/base" |
|
|
|
"code.gitea.io/gitea/modules/base" |
|
|
|
"code.gitea.io/gitea/modules/context" |
|
|
|
"code.gitea.io/gitea/modules/context" |
|
|
@ -60,6 +62,14 @@ type RepoSearchOptions struct { |
|
|
|
TplName base.TplName |
|
|
|
TplName base.TplName |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
|
|
|
|
nullByte = []byte{0x00} |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func isKeywordValid(keyword string) bool { |
|
|
|
|
|
|
|
return !bytes.Contains([]byte(keyword), nullByte) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// RenderRepoSearch render repositories search page
|
|
|
|
// RenderRepoSearch render repositories search page
|
|
|
|
func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { |
|
|
|
func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { |
|
|
|
page := ctx.QueryInt("page") |
|
|
|
page := ctx.QueryInt("page") |
|
|
@ -82,16 +92,18 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { |
|
|
|
} |
|
|
|
} |
|
|
|
count = opts.Counter(opts.Private) |
|
|
|
count = opts.Counter(opts.Private) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{ |
|
|
|
if isKeywordValid(keyword) { |
|
|
|
Keyword: keyword, |
|
|
|
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{ |
|
|
|
OrderBy: opts.OrderBy, |
|
|
|
Keyword: keyword, |
|
|
|
Private: opts.Private, |
|
|
|
OrderBy: opts.OrderBy, |
|
|
|
Page: page, |
|
|
|
Private: opts.Private, |
|
|
|
PageSize: opts.PageSize, |
|
|
|
Page: page, |
|
|
|
}) |
|
|
|
PageSize: opts.PageSize, |
|
|
|
if err != nil { |
|
|
|
}) |
|
|
|
ctx.Handle(500, "SearchRepositoryByName", err) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
ctx.Handle(500, "SearchRepositoryByName", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Data["Keyword"] = keyword |
|
|
|
ctx.Data["Keyword"] = keyword |
|
|
@ -156,16 +168,18 @@ func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) { |
|
|
|
} |
|
|
|
} |
|
|
|
count = opts.Counter() |
|
|
|
count = opts.Counter() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
users, count, err = models.SearchUserByName(&models.SearchUserOptions{ |
|
|
|
if isKeywordValid(keyword) { |
|
|
|
Keyword: keyword, |
|
|
|
users, count, err = models.SearchUserByName(&models.SearchUserOptions{ |
|
|
|
Type: opts.Type, |
|
|
|
Keyword: keyword, |
|
|
|
OrderBy: opts.OrderBy, |
|
|
|
Type: opts.Type, |
|
|
|
Page: page, |
|
|
|
OrderBy: opts.OrderBy, |
|
|
|
PageSize: opts.PageSize, |
|
|
|
Page: page, |
|
|
|
}) |
|
|
|
PageSize: opts.PageSize, |
|
|
|
if err != nil { |
|
|
|
}) |
|
|
|
ctx.Handle(500, "SearchUserByName", err) |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
ctx.Handle(500, "SearchUserByName", err) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
ctx.Data["Keyword"] = keyword |
|
|
|
ctx.Data["Keyword"] = keyword |
|
|
|