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