2022-03-30 16:42:47 +08:00
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
2022-11-28 02:20:29 +08:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-03-30 16:42:47 +08:00
|
|
|
|
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
|
|
"code.gitea.io/gitea/models/packages"
|
2022-07-27 19:58:21 +08:00
|
|
|
"code.gitea.io/gitea/models/unit"
|
2022-03-30 16:42:47 +08:00
|
|
|
"code.gitea.io/gitea/modules/base"
|
2024-03-02 23:42:31 +08:00
|
|
|
"code.gitea.io/gitea/modules/optional"
|
2022-03-30 16:42:47 +08:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2024-02-27 15:12:22 +08:00
|
|
|
"code.gitea.io/gitea/services/context"
|
2022-03-30 16:42:47 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
tplPackagesList base.TplName = "repo/packages"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Packages displays a list of all packages in the repository
|
|
|
|
func Packages(ctx *context.Context) {
|
|
|
|
page := ctx.FormInt("page")
|
|
|
|
if page <= 1 {
|
|
|
|
page = 1
|
|
|
|
}
|
|
|
|
query := ctx.FormTrim("q")
|
|
|
|
packageType := ctx.FormTrim("type")
|
|
|
|
|
|
|
|
pvs, total, err := packages.SearchLatestVersions(ctx, &packages.PackageSearchOptions{
|
|
|
|
Paginator: &db.ListOptions{
|
|
|
|
PageSize: setting.UI.PackagesPagingNum,
|
|
|
|
Page: page,
|
|
|
|
},
|
2022-07-27 09:59:10 +08:00
|
|
|
OwnerID: ctx.ContextUser.ID,
|
|
|
|
RepoID: ctx.Repo.Repository.ID,
|
|
|
|
Type: packages.Type(packageType),
|
|
|
|
Name: packages.SearchValue{Value: query},
|
2024-03-02 23:42:31 +08:00
|
|
|
IsInternal: optional.Some(false),
|
2022-03-30 16:42:47 +08:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("SearchLatestVersions", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
pds, err := packages.GetPackageDescriptors(ctx, pvs)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("GetPackageDescriptors", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
hasPackages, err := packages.HasRepositoryPackages(ctx, ctx.Repo.Repository.ID)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("HasRepositoryPackages", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.Data["Title"] = ctx.Tr("packages.title")
|
|
|
|
ctx.Data["IsPackagesPage"] = true
|
|
|
|
ctx.Data["Query"] = query
|
|
|
|
ctx.Data["PackageType"] = packageType
|
2022-12-29 07:31:54 +08:00
|
|
|
ctx.Data["AvailableTypes"] = packages.TypeList
|
2022-03-30 16:42:47 +08:00
|
|
|
ctx.Data["HasPackages"] = hasPackages
|
2022-07-27 19:58:21 +08:00
|
|
|
if ctx.Repo != nil {
|
|
|
|
ctx.Data["CanWritePackages"] = ctx.IsUserRepoWriter([]unit.Type{unit.TypePackages}) || ctx.IsUserSiteAdmin()
|
|
|
|
}
|
2022-03-30 16:42:47 +08:00
|
|
|
ctx.Data["PackageDescriptors"] = pds
|
|
|
|
ctx.Data["Total"] = total
|
2022-05-08 00:21:15 +08:00
|
|
|
ctx.Data["RepositoryAccessMap"] = map[int64]bool{ctx.Repo.Repository.ID: true} // There is only the current repository
|
2022-03-30 16:42:47 +08:00
|
|
|
|
|
|
|
pager := context.NewPagination(int(total), setting.UI.PackagesPagingNum, page, 5)
|
|
|
|
pager.AddParam(ctx, "q", "Query")
|
|
|
|
pager.AddParam(ctx, "type", "PackageType")
|
|
|
|
ctx.Data["Page"] = pager
|
|
|
|
|
|
|
|
ctx.HTML(http.StatusOK, tplPackagesList)
|
|
|
|
}
|