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