2022-03-30 08:42:47 +00:00
|
|
|
// Copyright 2021 The Gitea Authors. All rights reserved.
|
2022-11-27 18:20:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-03-30 08:42:47 +00:00
|
|
|
|
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models/db"
|
|
|
|
"code.gitea.io/gitea/models/packages"
|
2022-07-27 11:58:21 +00:00
|
|
|
"code.gitea.io/gitea/models/unit"
|
2022-03-30 08:42:47 +00:00
|
|
|
"code.gitea.io/gitea/modules/base"
|
2024-03-02 15:42:31 +00:00
|
|
|
"code.gitea.io/gitea/modules/optional"
|
2022-03-30 08:42:47 +00:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2024-02-27 07:12:22 +00:00
|
|
|
"code.gitea.io/gitea/services/context"
|
2022-03-30 08:42:47 +00: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 01:59:10 +00:00
|
|
|
OwnerID: ctx.ContextUser.ID,
|
|
|
|
RepoID: ctx.Repo.Repository.ID,
|
|
|
|
Type: packages.Type(packageType),
|
|
|
|
Name: packages.SearchValue{Value: query},
|
2024-03-02 15:42:31 +00:00
|
|
|
IsInternal: optional.Some(false),
|
2022-03-30 08:42:47 +00: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-28 23:31:54 +00:00
|
|
|
ctx.Data["AvailableTypes"] = packages.TypeList
|
2022-03-30 08:42:47 +00:00
|
|
|
ctx.Data["HasPackages"] = hasPackages
|
2022-07-27 11:58:21 +00:00
|
|
|
if ctx.Repo != nil {
|
|
|
|
ctx.Data["CanWritePackages"] = ctx.IsUserRepoWriter([]unit.Type{unit.TypePackages}) || ctx.IsUserSiteAdmin()
|
|
|
|
}
|
2022-03-30 08:42:47 +00:00
|
|
|
ctx.Data["PackageDescriptors"] = pds
|
|
|
|
ctx.Data["Total"] = total
|
2022-05-07 16:21:15 +00:00
|
|
|
ctx.Data["RepositoryAccessMap"] = map[int64]bool{ctx.Repo.Repository.ID: true} // There is only the current repository
|
2022-03-30 08:42:47 +00: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)
|
|
|
|
}
|