2014-02-13 01:49:46 +08:00
|
|
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
2019-02-19 00:00:27 +08:00
|
|
|
// Copyright 2019 The Gitea Authors. All rights reserved.
|
2014-02-13 01:49:46 +08:00
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package routers
|
|
|
|
|
2014-02-13 03:54:09 +08:00
|
|
|
import (
|
2017-02-11 12:00:01 +08:00
|
|
|
"bytes"
|
2019-02-28 16:01:42 +08:00
|
|
|
"net/url"
|
2017-02-11 12:00:01 +08:00
|
|
|
"strings"
|
2014-09-06 05:28:09 +08:00
|
|
|
|
2016-11-11 00:24:48 +08:00
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
"code.gitea.io/gitea/modules/base"
|
|
|
|
"code.gitea.io/gitea/modules/context"
|
2019-02-19 15:19:28 +08:00
|
|
|
"code.gitea.io/gitea/modules/log"
|
2018-03-16 22:04:33 +08:00
|
|
|
"code.gitea.io/gitea/modules/search"
|
2016-11-11 00:24:48 +08:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2017-10-25 01:36:19 +08:00
|
|
|
"code.gitea.io/gitea/modules/util"
|
2016-11-11 00:24:48 +08:00
|
|
|
"code.gitea.io/gitea/routers/user"
|
2017-02-15 14:01:50 +08:00
|
|
|
|
|
|
|
"github.com/Unknwon/paginater"
|
2014-02-13 03:54:09 +08:00
|
|
|
)
|
|
|
|
|
2014-06-23 01:14:03 +08:00
|
|
|
const (
|
2016-11-18 11:03:03 +08:00
|
|
|
// tplHome home page template
|
|
|
|
tplHome base.TplName = "home"
|
|
|
|
// tplExploreRepos explore repositories page template
|
|
|
|
tplExploreRepos base.TplName = "explore/repos"
|
|
|
|
// tplExploreUsers explore users page template
|
|
|
|
tplExploreUsers base.TplName = "explore/users"
|
|
|
|
// tplExploreOrganizations explore organizations page template
|
|
|
|
tplExploreOrganizations base.TplName = "explore/organizations"
|
2018-03-16 22:04:33 +08:00
|
|
|
// tplExploreCode explore code page template
|
|
|
|
tplExploreCode base.TplName = "explore/code"
|
2014-06-23 01:14:03 +08:00
|
|
|
)
|
|
|
|
|
2016-11-18 11:03:03 +08:00
|
|
|
// Home render home page
|
2016-03-12 00:56:52 +08:00
|
|
|
func Home(ctx *context.Context) {
|
2014-03-15 22:34:33 +08:00
|
|
|
if ctx.IsSigned {
|
2014-08-10 12:02:00 +08:00
|
|
|
if !ctx.User.IsActive && setting.Service.RegisterEmailConfirm {
|
|
|
|
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
|
2016-11-18 11:03:03 +08:00
|
|
|
ctx.HTML(200, user.TplActivate)
|
2019-02-19 15:19:28 +08:00
|
|
|
} else if !ctx.User.IsActive || ctx.User.ProhibitLogin {
|
|
|
|
log.Info("Failed authentication attempt for %s from %s", ctx.User.Name, ctx.RemoteAddr())
|
|
|
|
ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
|
|
|
|
ctx.HTML(200, "user/auth/prohibit_login")
|
2019-02-28 16:01:42 +08:00
|
|
|
} else if ctx.User.MustChangePassword {
|
|
|
|
ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
|
|
|
|
ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/change_password"
|
|
|
|
ctx.SetCookie("redirect_to", url.QueryEscape(setting.AppSubURL+ctx.Req.RequestURI), 0, setting.AppSubURL)
|
|
|
|
ctx.Redirect(setting.AppSubURL + "/user/settings/change_password")
|
2014-08-10 12:02:00 +08:00
|
|
|
} else {
|
|
|
|
user.Dashboard(ctx)
|
|
|
|
}
|
2014-03-06 21:33:17 +08:00
|
|
|
return
|
2018-06-15 11:42:46 +08:00
|
|
|
// Check non-logged users landing page.
|
|
|
|
} else if setting.LandingPageURL != setting.LandingPageHome {
|
|
|
|
ctx.Redirect(setting.AppSubURL + string(setting.LandingPageURL))
|
|
|
|
return
|
2014-03-06 21:33:17 +08:00
|
|
|
}
|
2014-03-25 00:43:51 +08:00
|
|
|
|
|
|
|
// Check auto-login.
|
2014-07-26 12:24:27 +08:00
|
|
|
uname := ctx.GetCookie(setting.CookieUserName)
|
|
|
|
if len(uname) != 0 {
|
2016-11-27 18:14:25 +08:00
|
|
|
ctx.Redirect(setting.AppSubURL + "/user/login")
|
2014-03-25 00:43:51 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2014-05-25 03:28:31 +08:00
|
|
|
ctx.Data["PageIsHome"] = true
|
2018-03-16 22:04:33 +08:00
|
|
|
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
|
2016-11-18 11:03:03 +08:00
|
|
|
ctx.HTML(200, tplHome)
|
2014-02-13 01:49:46 +08:00
|
|
|
}
|
2014-03-16 15:41:22 +08:00
|
|
|
|
2016-11-18 11:03:03 +08:00
|
|
|
// RepoSearchOptions when calling search repositories
|
2016-03-16 02:23:12 +08:00
|
|
|
type RepoSearchOptions struct {
|
2017-10-11 04:37:18 +08:00
|
|
|
OwnerID int64
|
2016-03-16 02:23:12 +08:00
|
|
|
Private bool
|
|
|
|
PageSize int
|
|
|
|
TplName base.TplName
|
|
|
|
}
|
|
|
|
|
2016-12-01 18:52:57 +08:00
|
|
|
var (
|
|
|
|
nullByte = []byte{0x00}
|
|
|
|
)
|
|
|
|
|
|
|
|
func isKeywordValid(keyword string) bool {
|
|
|
|
return !bytes.Contains([]byte(keyword), nullByte)
|
|
|
|
}
|
|
|
|
|
2016-11-18 11:03:03 +08:00
|
|
|
// RenderRepoSearch render repositories search page
|
2016-03-16 02:23:12 +08:00
|
|
|
func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
|
2015-09-01 19:04:35 +08:00
|
|
|
page := ctx.QueryInt("page")
|
2016-07-24 14:32:46 +08:00
|
|
|
if page <= 0 {
|
2015-09-01 19:04:35 +08:00
|
|
|
page = 1
|
|
|
|
}
|
|
|
|
|
2016-03-12 04:33:12 +08:00
|
|
|
var (
|
2016-12-24 22:42:26 +08:00
|
|
|
repos []*models.Repository
|
|
|
|
count int64
|
|
|
|
err error
|
2017-09-22 20:53:21 +08:00
|
|
|
orderBy models.SearchOrderBy
|
2016-03-12 04:33:12 +08:00
|
|
|
)
|
2016-12-24 22:42:26 +08:00
|
|
|
|
2017-10-05 13:02:43 +08:00
|
|
|
ctx.Data["SortType"] = ctx.Query("sort")
|
2016-12-24 22:42:26 +08:00
|
|
|
switch ctx.Query("sort") {
|
2017-10-05 13:02:43 +08:00
|
|
|
case "newest":
|
|
|
|
orderBy = models.SearchOrderByNewest
|
2016-12-24 22:42:26 +08:00
|
|
|
case "oldest":
|
2017-09-22 20:53:21 +08:00
|
|
|
orderBy = models.SearchOrderByOldest
|
2016-12-24 22:42:26 +08:00
|
|
|
case "recentupdate":
|
2017-09-22 20:53:21 +08:00
|
|
|
orderBy = models.SearchOrderByRecentUpdated
|
2016-12-24 22:42:26 +08:00
|
|
|
case "leastupdate":
|
2017-09-22 20:53:21 +08:00
|
|
|
orderBy = models.SearchOrderByLeastUpdated
|
2016-12-24 22:42:26 +08:00
|
|
|
case "reversealphabetically":
|
2017-09-22 20:53:21 +08:00
|
|
|
orderBy = models.SearchOrderByAlphabeticallyReverse
|
2016-12-24 22:42:26 +08:00
|
|
|
case "alphabetically":
|
2017-09-22 20:53:21 +08:00
|
|
|
orderBy = models.SearchOrderByAlphabetically
|
2017-05-02 16:34:28 +08:00
|
|
|
case "reversesize":
|
2017-09-22 20:53:21 +08:00
|
|
|
orderBy = models.SearchOrderBySizeReverse
|
2017-05-02 16:34:28 +08:00
|
|
|
case "size":
|
2017-09-22 20:53:21 +08:00
|
|
|
orderBy = models.SearchOrderBySize
|
2018-05-24 09:03:42 +08:00
|
|
|
case "moststars":
|
|
|
|
orderBy = models.SearchOrderByStarsReverse
|
|
|
|
case "feweststars":
|
|
|
|
orderBy = models.SearchOrderByStars
|
|
|
|
case "mostforks":
|
|
|
|
orderBy = models.SearchOrderByForksReverse
|
|
|
|
case "fewestforks":
|
|
|
|
orderBy = models.SearchOrderByForks
|
2016-12-24 22:42:26 +08:00
|
|
|
default:
|
2017-10-05 13:02:43 +08:00
|
|
|
ctx.Data["SortType"] = "recentupdate"
|
|
|
|
orderBy = models.SearchOrderByRecentUpdated
|
2016-12-24 22:42:26 +08:00
|
|
|
}
|
2015-09-01 19:04:35 +08:00
|
|
|
|
2017-02-11 12:00:01 +08:00
|
|
|
keyword := strings.Trim(ctx.Query("q"), " ")
|
2018-09-13 10:33:48 +08:00
|
|
|
topicOnly := ctx.QueryBool("topic")
|
2017-10-11 04:37:18 +08:00
|
|
|
|
|
|
|
repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
|
2017-10-27 05:16:13 +08:00
|
|
|
Page: page,
|
|
|
|
PageSize: opts.PageSize,
|
|
|
|
OrderBy: orderBy,
|
|
|
|
Private: opts.Private,
|
|
|
|
Keyword: keyword,
|
|
|
|
OwnerID: opts.OwnerID,
|
|
|
|
AllPublic: true,
|
2018-09-13 10:33:48 +08:00
|
|
|
TopicOnly: topicOnly,
|
2017-10-11 04:37:18 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
2018-01-11 05:34:17 +08:00
|
|
|
ctx.ServerError("SearchRepositoryByName", err)
|
2017-10-11 04:37:18 +08:00
|
|
|
return
|
2014-09-06 05:28:09 +08:00
|
|
|
}
|
2016-03-12 04:33:12 +08:00
|
|
|
ctx.Data["Keyword"] = keyword
|
|
|
|
ctx.Data["Total"] = count
|
2016-03-16 02:23:12 +08:00
|
|
|
ctx.Data["Page"] = paginater.New(int(count), opts.PageSize, page, 5)
|
2014-09-06 05:28:09 +08:00
|
|
|
ctx.Data["Repos"] = repos
|
2018-03-16 22:04:33 +08:00
|
|
|
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
|
2014-09-06 05:28:09 +08:00
|
|
|
|
2016-03-16 02:23:12 +08:00
|
|
|
ctx.HTML(200, opts.TplName)
|
2016-03-12 04:33:12 +08:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:03:03 +08:00
|
|
|
// ExploreRepos render explore repositories page
|
2016-03-12 04:33:12 +08:00
|
|
|
func ExploreRepos(ctx *context.Context) {
|
|
|
|
ctx.Data["Title"] = ctx.Tr("explore")
|
|
|
|
ctx.Data["PageIsExplore"] = true
|
|
|
|
ctx.Data["PageIsExploreRepositories"] = true
|
2018-03-16 22:04:33 +08:00
|
|
|
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
|
2016-03-12 04:33:12 +08:00
|
|
|
|
2017-10-11 04:37:18 +08:00
|
|
|
var ownerID int64
|
|
|
|
if ctx.User != nil && !ctx.User.IsAdmin {
|
|
|
|
ownerID = ctx.User.ID
|
|
|
|
}
|
|
|
|
|
2016-03-16 02:23:12 +08:00
|
|
|
RenderRepoSearch(ctx, &RepoSearchOptions{
|
2016-07-24 00:23:54 +08:00
|
|
|
PageSize: setting.UI.ExplorePagingNum,
|
2017-10-11 04:37:18 +08:00
|
|
|
OwnerID: ownerID,
|
|
|
|
Private: ctx.User != nil,
|
2016-11-18 11:03:03 +08:00
|
|
|
TplName: tplExploreRepos,
|
2016-03-16 02:23:12 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-11-18 11:03:03 +08:00
|
|
|
// RenderUserSearch render user search page
|
2017-10-25 01:36:19 +08:00
|
|
|
func RenderUserSearch(ctx *context.Context, opts *models.SearchUserOptions, tplName base.TplName) {
|
|
|
|
opts.Page = ctx.QueryInt("page")
|
|
|
|
if opts.Page <= 1 {
|
|
|
|
opts.Page = 1
|
2016-03-12 04:33:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2016-12-24 22:42:26 +08:00
|
|
|
users []*models.User
|
|
|
|
count int64
|
|
|
|
err error
|
2018-05-24 09:03:42 +08:00
|
|
|
orderBy models.SearchOrderBy
|
2016-03-12 04:33:12 +08:00
|
|
|
)
|
|
|
|
|
2016-12-24 22:42:26 +08:00
|
|
|
ctx.Data["SortType"] = ctx.Query("sort")
|
|
|
|
switch ctx.Query("sort") {
|
2017-10-05 13:02:43 +08:00
|
|
|
case "newest":
|
2018-05-24 09:03:42 +08:00
|
|
|
orderBy = models.SearchOrderByIDReverse
|
2016-12-24 22:42:26 +08:00
|
|
|
case "oldest":
|
2018-05-24 09:03:42 +08:00
|
|
|
orderBy = models.SearchOrderByID
|
2016-12-24 22:42:26 +08:00
|
|
|
case "recentupdate":
|
2018-05-24 09:03:42 +08:00
|
|
|
orderBy = models.SearchOrderByRecentUpdated
|
2016-12-24 22:42:26 +08:00
|
|
|
case "leastupdate":
|
2018-05-24 09:03:42 +08:00
|
|
|
orderBy = models.SearchOrderByLeastUpdated
|
2016-12-24 22:42:26 +08:00
|
|
|
case "reversealphabetically":
|
2018-05-24 09:03:42 +08:00
|
|
|
orderBy = models.SearchOrderByAlphabeticallyReverse
|
2016-12-24 22:42:26 +08:00
|
|
|
case "alphabetically":
|
2018-05-24 09:03:42 +08:00
|
|
|
orderBy = models.SearchOrderByAlphabetically
|
2016-12-24 22:42:26 +08:00
|
|
|
default:
|
2017-10-05 13:02:43 +08:00
|
|
|
ctx.Data["SortType"] = "alphabetically"
|
2018-05-24 09:03:42 +08:00
|
|
|
orderBy = models.SearchOrderByAlphabetically
|
2016-12-24 22:42:26 +08:00
|
|
|
}
|
|
|
|
|
2017-10-25 01:36:19 +08:00
|
|
|
opts.Keyword = strings.Trim(ctx.Query("q"), " ")
|
|
|
|
opts.OrderBy = orderBy
|
|
|
|
if len(opts.Keyword) == 0 || isKeywordValid(opts.Keyword) {
|
|
|
|
users, count, err = models.SearchUsers(opts)
|
2016-03-12 04:33:12 +08:00
|
|
|
if err != nil {
|
2018-01-11 05:34:17 +08:00
|
|
|
ctx.ServerError("SearchUsers", err)
|
2016-03-12 04:33:12 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2017-10-25 01:36:19 +08:00
|
|
|
ctx.Data["Keyword"] = opts.Keyword
|
2016-03-12 04:33:12 +08:00
|
|
|
ctx.Data["Total"] = count
|
2017-10-25 01:36:19 +08:00
|
|
|
ctx.Data["Page"] = paginater.New(int(count), opts.PageSize, opts.Page, 5)
|
2016-03-12 04:33:12 +08:00
|
|
|
ctx.Data["Users"] = users
|
2017-01-01 10:51:10 +08:00
|
|
|
ctx.Data["ShowUserEmail"] = setting.UI.ShowUserEmail
|
2018-03-16 22:04:33 +08:00
|
|
|
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
|
2016-03-12 04:33:12 +08:00
|
|
|
|
2017-10-25 01:36:19 +08:00
|
|
|
ctx.HTML(200, tplName)
|
2016-03-12 04:33:12 +08:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:03:03 +08:00
|
|
|
// ExploreUsers render explore users page
|
2016-03-12 04:33:12 +08:00
|
|
|
func ExploreUsers(ctx *context.Context) {
|
|
|
|
ctx.Data["Title"] = ctx.Tr("explore")
|
|
|
|
ctx.Data["PageIsExplore"] = true
|
|
|
|
ctx.Data["PageIsExploreUsers"] = true
|
2018-03-16 22:04:33 +08:00
|
|
|
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
|
2016-03-12 04:33:12 +08:00
|
|
|
|
2017-10-25 01:36:19 +08:00
|
|
|
RenderUserSearch(ctx, &models.SearchUserOptions{
|
2016-11-08 00:53:22 +08:00
|
|
|
Type: models.UserTypeIndividual,
|
2016-07-24 00:23:54 +08:00
|
|
|
PageSize: setting.UI.ExplorePagingNum,
|
2017-10-25 01:36:19 +08:00
|
|
|
IsActive: util.OptionalBoolTrue,
|
2019-02-19 00:00:27 +08:00
|
|
|
Private: true,
|
2017-10-25 01:36:19 +08:00
|
|
|
}, tplExploreUsers)
|
2014-09-06 05:28:09 +08:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:03:03 +08:00
|
|
|
// ExploreOrganizations render explore organizations page
|
2016-09-01 21:08:05 +08:00
|
|
|
func ExploreOrganizations(ctx *context.Context) {
|
|
|
|
ctx.Data["Title"] = ctx.Tr("explore")
|
|
|
|
ctx.Data["PageIsExplore"] = true
|
|
|
|
ctx.Data["PageIsExploreOrganizations"] = true
|
2018-03-16 22:04:33 +08:00
|
|
|
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
|
2016-09-01 21:08:05 +08:00
|
|
|
|
2019-02-19 00:00:27 +08:00
|
|
|
var ownerID int64
|
|
|
|
if ctx.User != nil && !ctx.User.IsAdmin {
|
|
|
|
ownerID = ctx.User.ID
|
|
|
|
}
|
|
|
|
|
2017-10-25 01:36:19 +08:00
|
|
|
RenderUserSearch(ctx, &models.SearchUserOptions{
|
2016-11-08 00:53:22 +08:00
|
|
|
Type: models.UserTypeOrganization,
|
2016-09-01 21:08:05 +08:00
|
|
|
PageSize: setting.UI.ExplorePagingNum,
|
2019-02-19 00:00:27 +08:00
|
|
|
Private: ctx.User != nil,
|
|
|
|
OwnerID: ownerID,
|
2017-10-25 01:36:19 +08:00
|
|
|
}, tplExploreOrganizations)
|
2016-09-01 21:08:05 +08:00
|
|
|
}
|
|
|
|
|
2018-03-16 22:04:33 +08:00
|
|
|
// ExploreCode render explore code page
|
|
|
|
func ExploreCode(ctx *context.Context) {
|
|
|
|
if !setting.Indexer.RepoIndexerEnabled {
|
|
|
|
ctx.Redirect("/explore", 302)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled
|
|
|
|
ctx.Data["Title"] = ctx.Tr("explore")
|
|
|
|
ctx.Data["PageIsExplore"] = true
|
|
|
|
ctx.Data["PageIsExploreCode"] = true
|
|
|
|
|
|
|
|
keyword := strings.TrimSpace(ctx.Query("q"))
|
|
|
|
page := ctx.QueryInt("page")
|
|
|
|
if page <= 0 {
|
|
|
|
page = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
repoIDs []int64
|
|
|
|
err error
|
|
|
|
isAdmin bool
|
|
|
|
userID int64
|
|
|
|
)
|
|
|
|
if ctx.User != nil {
|
|
|
|
userID = ctx.User.ID
|
|
|
|
isAdmin = ctx.User.IsAdmin
|
|
|
|
}
|
|
|
|
|
|
|
|
// guest user or non-admin user
|
|
|
|
if ctx.User == nil || !isAdmin {
|
|
|
|
repoIDs, err = models.FindUserAccessibleRepoIDs(userID)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("SearchResults", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
total int
|
|
|
|
searchResults []*search.Result
|
|
|
|
)
|
|
|
|
|
|
|
|
// if non-admin login user, we need check UnitTypeCode at first
|
|
|
|
if ctx.User != nil && len(repoIDs) > 0 {
|
|
|
|
repoMaps, err := models.GetRepositoriesMapByIDs(repoIDs)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("SearchResults", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var rightRepoMap = make(map[int64]*models.Repository, len(repoMaps))
|
|
|
|
repoIDs = make([]int64, 0, len(repoMaps))
|
|
|
|
for id, repo := range repoMaps {
|
|
|
|
if repo.CheckUnitUser(userID, isAdmin, models.UnitTypeCode) {
|
|
|
|
rightRepoMap[id] = repo
|
|
|
|
repoIDs = append(repoIDs, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Data["RepoMaps"] = rightRepoMap
|
|
|
|
|
|
|
|
total, searchResults, err = search.PerformSearch(repoIDs, keyword, page, setting.UI.RepoSearchPagingNum)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("SearchResults", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// if non-login user or isAdmin, no need to check UnitTypeCode
|
|
|
|
} else if (ctx.User == nil && len(repoIDs) > 0) || isAdmin {
|
|
|
|
total, searchResults, err = search.PerformSearch(repoIDs, keyword, page, setting.UI.RepoSearchPagingNum)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("SearchResults", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var loadRepoIDs = make([]int64, 0, len(searchResults))
|
|
|
|
for _, result := range searchResults {
|
|
|
|
var find bool
|
|
|
|
for _, id := range loadRepoIDs {
|
|
|
|
if id == result.RepoID {
|
|
|
|
find = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !find {
|
|
|
|
loadRepoIDs = append(loadRepoIDs, result.RepoID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
repoMaps, err := models.GetRepositoriesMapByIDs(loadRepoIDs)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("SearchResults", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Data["RepoMaps"] = repoMaps
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Data["Keyword"] = keyword
|
|
|
|
pager := paginater.New(total, setting.UI.RepoSearchPagingNum, page, 5)
|
|
|
|
ctx.Data["Page"] = pager
|
|
|
|
ctx.Data["SearchResults"] = searchResults
|
|
|
|
ctx.Data["RequireHighlightJS"] = true
|
|
|
|
ctx.Data["PageIsViewCode"] = true
|
|
|
|
ctx.HTML(200, tplExploreCode)
|
|
|
|
}
|
|
|
|
|
2016-11-18 11:03:03 +08:00
|
|
|
// NotFound render 404 page
|
2016-03-12 00:56:52 +08:00
|
|
|
func NotFound(ctx *context.Context) {
|
2014-03-23 20:40:40 +08:00
|
|
|
ctx.Data["Title"] = "Page Not Found"
|
2018-01-11 05:34:17 +08:00
|
|
|
ctx.NotFound("home.NotFound", nil)
|
2014-03-23 13:48:01 +08:00
|
|
|
}
|