|
|
@ -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,6 +92,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { |
|
|
|
} |
|
|
|
} |
|
|
|
count = opts.Counter(opts.Private) |
|
|
|
count = opts.Counter(opts.Private) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
if isKeywordValid(keyword) { |
|
|
|
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{ |
|
|
|
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{ |
|
|
|
Keyword: keyword, |
|
|
|
Keyword: keyword, |
|
|
|
OrderBy: opts.OrderBy, |
|
|
|
OrderBy: opts.OrderBy, |
|
|
@ -94,6 +105,7 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
ctx.Data["Keyword"] = keyword |
|
|
|
ctx.Data["Keyword"] = keyword |
|
|
|
ctx.Data["Total"] = count |
|
|
|
ctx.Data["Total"] = count |
|
|
|
ctx.Data["Page"] = paginater.New(int(count), opts.PageSize, page, 5) |
|
|
|
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() |
|
|
|
count = opts.Counter() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
if isKeywordValid(keyword) { |
|
|
|
users, count, err = models.SearchUserByName(&models.SearchUserOptions{ |
|
|
|
users, count, err = models.SearchUserByName(&models.SearchUserOptions{ |
|
|
|
Keyword: keyword, |
|
|
|
Keyword: keyword, |
|
|
|
Type: opts.Type, |
|
|
|
Type: opts.Type, |
|
|
@ -168,6 +181,7 @@ func RenderUserSearch(ctx *context.Context, opts *UserSearchOptions) { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
ctx.Data["Keyword"] = keyword |
|
|
|
ctx.Data["Keyword"] = keyword |
|
|
|
ctx.Data["Total"] = count |
|
|
|
ctx.Data["Total"] = count |
|
|
|
ctx.Data["Page"] = paginater.New(int(count), opts.PageSize, page, 5) |
|
|
|
ctx.Data["Page"] = paginater.New(int(count), opts.PageSize, page, 5) |
|
|
|