Skip to content

Refactor packages (func name & UI) #34773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions routers/api/packages/alpine/alpine.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func GetRepositoryFile(ctx *context.Context) {
return
}

s, u, pf, err := packages_service.GetFileStreamByPackageVersion(
s, u, pf, err := packages_service.OpenFileForDownloadByPackageVersion(
ctx,
pv,
&packages_service.PackageFileInfo{
Expand Down Expand Up @@ -216,7 +216,7 @@ func DownloadPackageFile(ctx *context.Context) {
}
}

s, u, pf, err := packages_service.GetPackageFileStream(ctx, pfs[0])
s, u, pf, err := packages_service.OpenFileForDownload(ctx, pfs[0])
if err != nil {
if errors.Is(err, util.ErrNotExist) {
apiError(ctx, http.StatusNotFound, err)
Expand Down
2 changes: 1 addition & 1 deletion routers/api/packages/arch/arch.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func GetPackageOrRepositoryFile(ctx *context.Context) {
return
}

s, u, pf, err := packages_service.GetPackageFileStream(ctx, pfs[0])
s, u, pf, err := packages_service.OpenFileForDownload(ctx, pfs[0])
if err != nil {
if errors.Is(err, util.ErrNotExist) {
apiError(ctx, http.StatusNotFound, err)
Expand Down
2 changes: 1 addition & 1 deletion routers/api/packages/cargo/cargo.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func ListOwners(ctx *context.Context) {

// DownloadPackageFile serves the content of a package
func DownloadPackageFile(ctx *context.Context) {
s, u, pf, err := packages_service.GetFileStreamByPackageNameAndVersion(
s, u, pf, err := packages_service.OpenFileForDownloadByPackageNameAndVersion(
ctx,
&packages_service.PackageInfo{
Owner: ctx.Package.Owner,
Expand Down
2 changes: 1 addition & 1 deletion routers/api/packages/chef/chef.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ func DownloadPackage(ctx *context.Context) {

pf := pd.Files[0].File

s, u, _, err := packages_service.GetPackageFileStream(ctx, pf)
s, u, _, err := packages_service.OpenFileForDownload(ctx, pf)
if err != nil {
apiError(ctx, http.StatusInternalServerError, err)
return
Expand Down
2 changes: 1 addition & 1 deletion routers/api/packages/composer/composer.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func PackageMetadata(ctx *context.Context) {

// DownloadPackageFile serves the content of a package
func DownloadPackageFile(ctx *context.Context) {
s, u, pf, err := packages_service.GetFileStreamByPackageNameAndVersion(
s, u, pf, err := packages_service.OpenFileForDownloadByPackageNameAndVersion(
ctx,
&packages_service.PackageInfo{
Owner: ctx.Package.Owner,
Expand Down
2 changes: 1 addition & 1 deletion routers/api/packages/conan/conan.go
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ func downloadFile(ctx *context.Context, fileFilter container.Set[string], fileKe
return
}

s, u, pf, err := packages_service.GetFileStreamByPackageNameAndVersion(
s, u, pf, err := packages_service.OpenFileForDownloadByPackageNameAndVersion(
ctx,
&packages_service.PackageInfo{
Owner: ctx.Package.Owner,
Expand Down
2 changes: 1 addition & 1 deletion routers/api/packages/conda/conda.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func DownloadPackageFile(ctx *context.Context) {

pf := pfs[0]

s, u, _, err := packages_service.GetPackageFileStream(ctx, pf)
s, u, _, err := packages_service.OpenFileForDownload(ctx, pf)
if err != nil {
apiError(ctx, http.StatusInternalServerError, err)
return
Expand Down
2 changes: 1 addition & 1 deletion routers/api/packages/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ func DeleteManifest(ctx *context.Context) {
func serveBlob(ctx *context.Context, pfd *packages_model.PackageFileDescriptor) {
serveDirectReqParams := make(url.Values)
serveDirectReqParams.Set("response-content-type", pfd.Properties.GetByName(container_module.PropertyMediaType))
s, u, _, err := packages_service.GetPackageBlobStream(ctx, pfd.File, pfd.Blob, serveDirectReqParams)
s, u, _, err := packages_service.OpenBlobForDownload(ctx, pfd.File, pfd.Blob, serveDirectReqParams)
if err != nil {
apiError(ctx, http.StatusInternalServerError, err)
return
Expand Down
2 changes: 1 addition & 1 deletion routers/api/packages/cran/cran.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func downloadPackageFile(ctx *context.Context, opts *cran_model.SearchOptions) {
return
}

s, u, _, err := packages_service.GetPackageFileStream(ctx, pf)
s, u, _, err := packages_service.OpenFileForDownload(ctx, pf)
if err != nil {
if errors.Is(err, util.ErrNotExist) {
apiError(ctx, http.StatusNotFound, err)
Expand Down
6 changes: 3 additions & 3 deletions routers/api/packages/debian/debian.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func GetRepositoryFile(ctx *context.Context) {
key += "|" + component + "|" + architecture
}

s, u, pf, err := packages_service.GetFileStreamByPackageVersion(
s, u, pf, err := packages_service.OpenFileForDownloadByPackageVersion(
ctx,
pv,
&packages_service.PackageFileInfo{
Expand Down Expand Up @@ -106,7 +106,7 @@ func GetRepositoryFileByHash(ctx *context.Context) {
return
}

s, u, pf, err := packages_service.GetPackageFileStream(ctx, pfs[0])
s, u, pf, err := packages_service.OpenFileForDownload(ctx, pfs[0])
if err != nil {
if errors.Is(err, util.ErrNotExist) {
apiError(ctx, http.StatusNotFound, err)
Expand Down Expand Up @@ -210,7 +210,7 @@ func DownloadPackageFile(ctx *context.Context) {
name := ctx.PathParam("name")
version := ctx.PathParam("version")

s, u, pf, err := packages_service.GetFileStreamByPackageNameAndVersion(
s, u, pf, err := packages_service.OpenFileForDownloadByPackageNameAndVersion(
ctx,
&packages_service.PackageInfo{
Owner: ctx.Package.Owner,
Expand Down
2 changes: 1 addition & 1 deletion routers/api/packages/generic/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func apiError(ctx *context.Context, status int, obj any) {

// DownloadPackageFile serves the specific generic package.
func DownloadPackageFile(ctx *context.Context) {
s, u, pf, err := packages_service.GetFileStreamByPackageNameAndVersion(
s, u, pf, err := packages_service.OpenFileForDownloadByPackageNameAndVersion(
ctx,
&packages_service.PackageInfo{
Owner: ctx.Package.Owner,
Expand Down
2 changes: 1 addition & 1 deletion routers/api/packages/goproxy/goproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func DownloadPackageFile(ctx *context.Context) {
return
}

s, u, _, err := packages_service.GetPackageFileStream(ctx, pfs[0])
s, u, _, err := packages_service.OpenFileForDownload(ctx, pfs[0])
if err != nil {
if errors.Is(err, util.ErrNotExist) {
apiError(ctx, http.StatusNotFound, err)
Expand Down
2 changes: 1 addition & 1 deletion routers/api/packages/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func DownloadPackageFile(ctx *context.Context) {
return
}

s, u, pf, err := packages_service.GetFileStreamByPackageVersion(
s, u, pf, err := packages_service.OpenFileForDownloadByPackageVersion(
ctx,
pvs[0],
&packages_service.PackageFileInfo{
Expand Down
2 changes: 1 addition & 1 deletion routers/api/packages/maven/maven.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func servePackageFile(ctx *context.Context, params parameters, serveContent bool
return
}

s, u, _, err := packages_service.GetPackageBlobStream(ctx, pf, pb, nil)
s, u, _, err := packages_service.OpenBlobForDownload(ctx, pf, pb, nil)
if err != nil {
apiError(ctx, http.StatusInternalServerError, err)
return
Expand Down
4 changes: 2 additions & 2 deletions routers/api/packages/npm/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func DownloadPackageFile(ctx *context.Context) {
packageVersion := ctx.PathParam("version")
filename := ctx.PathParam("filename")

s, u, pf, err := packages_service.GetFileStreamByPackageNameAndVersion(
s, u, pf, err := packages_service.OpenFileForDownloadByPackageNameAndVersion(
ctx,
&packages_service.PackageInfo{
Owner: ctx.Package.Owner,
Expand Down Expand Up @@ -132,7 +132,7 @@ func DownloadPackageFileByName(ctx *context.Context) {
return
}

s, u, pf, err := packages_service.GetFileStreamByPackageVersion(
s, u, pf, err := packages_service.OpenFileForDownloadByPackageVersion(
ctx,
pvs[0],
&packages_service.PackageFileInfo{
Expand Down
4 changes: 2 additions & 2 deletions routers/api/packages/nuget/nuget.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func DownloadPackageFile(ctx *context.Context) {
packageVersion := ctx.PathParam("version")
filename := ctx.PathParam("filename")

s, u, pf, err := packages_service.GetFileStreamByPackageNameAndVersion(
s, u, pf, err := packages_service.OpenFileForDownloadByPackageNameAndVersion(
ctx,
&packages_service.PackageInfo{
Owner: ctx.Package.Owner,
Expand Down Expand Up @@ -669,7 +669,7 @@ func DownloadSymbolFile(ctx *context.Context) {
return
}

s, u, pf, err := packages_service.GetPackageFileStream(ctx, pfs[0])
s, u, pf, err := packages_service.OpenFileForDownload(ctx, pfs[0])
if err != nil {
if errors.Is(err, packages_model.ErrPackageNotExist) || errors.Is(err, packages_model.ErrPackageFileNotExist) {
apiError(ctx, http.StatusNotFound, err)
Expand Down
2 changes: 1 addition & 1 deletion routers/api/packages/pub/pub.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func DownloadPackageFile(ctx *context.Context) {

pf := pd.Files[0].File

s, u, _, err := packages_service.GetPackageFileStream(ctx, pf)
s, u, _, err := packages_service.OpenFileForDownload(ctx, pf)
if err != nil {
apiError(ctx, http.StatusInternalServerError, err)
return
Expand Down
2 changes: 1 addition & 1 deletion routers/api/packages/pypi/pypi.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func DownloadPackageFile(ctx *context.Context) {
packageVersion := ctx.PathParam("version")
filename := ctx.PathParam("filename")

s, u, pf, err := packages_service.GetFileStreamByPackageNameAndVersion(
s, u, pf, err := packages_service.OpenFileForDownloadByPackageNameAndVersion(
ctx,
&packages_service.PackageInfo{
Owner: ctx.Package.Owner,
Expand Down
4 changes: 2 additions & 2 deletions routers/api/packages/rpm/rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func GetRepositoryFile(ctx *context.Context) {
return
}

s, u, pf, err := packages_service.GetFileStreamByPackageVersion(
s, u, pf, err := packages_service.OpenFileForDownloadByPackageVersion(
ctx,
pv,
&packages_service.PackageFileInfo{
Expand Down Expand Up @@ -220,7 +220,7 @@ func DownloadPackageFile(ctx *context.Context) {
name := ctx.PathParam("name")
version := ctx.PathParam("version")

s, u, pf, err := packages_service.GetFileStreamByPackageNameAndVersion(
s, u, pf, err := packages_service.OpenFileForDownloadByPackageNameAndVersion(
ctx,
&packages_service.PackageInfo{
Owner: ctx.Package.Owner,
Expand Down
2 changes: 1 addition & 1 deletion routers/api/packages/rubygems/rubygems.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func DownloadPackageFile(ctx *context.Context) {
return
}

s, u, pf, err := packages_service.GetFileStreamByPackageVersion(
s, u, pf, err := packages_service.OpenFileForDownloadByPackageVersion(
ctx,
pvs[0],
&packages_service.PackageFileInfo{
Expand Down
2 changes: 1 addition & 1 deletion routers/api/packages/swift/swift.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ func DownloadPackageFile(ctx *context.Context) {

pf := pd.Files[0].File

s, u, _, err := packages_service.GetPackageFileStream(ctx, pf)
s, u, _, err := packages_service.OpenFileForDownload(ctx, pf)
if err != nil {
apiError(ctx, http.StatusInternalServerError, err)
return
Expand Down
2 changes: 1 addition & 1 deletion routers/api/packages/vagrant/vagrant.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func UploadPackageFile(ctx *context.Context) {
}

func DownloadPackageFile(ctx *context.Context) {
s, u, pf, err := packages_service.GetFileStreamByPackageNameAndVersion(
s, u, pf, err := packages_service.OpenFileForDownloadByPackageNameAndVersion(
ctx,
&packages_service.PackageInfo{
Owner: ctx.Package.Owner,
Expand Down
4 changes: 2 additions & 2 deletions routers/web/user/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,9 @@ func DownloadPackageFile(ctx *context.Context) {
return
}

s, u, _, err := packages_service.GetPackageFileStream(ctx, pf)
s, u, _, err := packages_service.OpenFileForDownload(ctx, pf)
if err != nil {
ctx.ServerError("GetPackageFileStream", err)
ctx.ServerError("OpenFileForDownload", err)
return
}

Expand Down
22 changes: 11 additions & 11 deletions services/packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,8 @@ func DeletePackageFile(ctx context.Context, pf *packages_model.PackageFile) erro
return packages_model.DeleteFileByID(ctx, pf.ID)
}

// GetFileStreamByPackageNameAndVersion returns the content of the specific package file
func GetFileStreamByPackageNameAndVersion(ctx context.Context, pvi *PackageInfo, pfi *PackageFileInfo) (io.ReadSeekCloser, *url.URL, *packages_model.PackageFile, error) {
// OpenFileForDownloadByPackageNameAndVersion returns the content of the specific package file and increases the download counter.
func OpenFileForDownloadByPackageNameAndVersion(ctx context.Context, pvi *PackageInfo, pfi *PackageFileInfo) (io.ReadSeekCloser, *url.URL, *packages_model.PackageFile, error) {
log.Trace("Getting package file stream: %v, %v, %s, %s, %s, %s", pvi.Owner.ID, pvi.PackageType, pvi.Name, pvi.Version, pfi.Filename, pfi.CompositeKey)

pv, err := packages_model.GetVersionByNameAndVersion(ctx, pvi.Owner.ID, pvi.PackageType, pvi.Name, pvi.Version)
Expand All @@ -576,27 +576,27 @@ func GetFileStreamByPackageNameAndVersion(ctx context.Context, pvi *PackageInfo,
return nil, nil, nil, err
}

return GetFileStreamByPackageVersion(ctx, pv, pfi)
return OpenFileForDownloadByPackageVersion(ctx, pv, pfi)
}

// GetFileStreamByPackageVersion returns the content of the specific package file
func GetFileStreamByPackageVersion(ctx context.Context, pv *packages_model.PackageVersion, pfi *PackageFileInfo) (io.ReadSeekCloser, *url.URL, *packages_model.PackageFile, error) {
// OpenFileForDownloadByPackageVersion returns the content of the specific package file and increases the download counter.
func OpenFileForDownloadByPackageVersion(ctx context.Context, pv *packages_model.PackageVersion, pfi *PackageFileInfo) (io.ReadSeekCloser, *url.URL, *packages_model.PackageFile, error) {
pf, err := packages_model.GetFileForVersionByName(ctx, pv.ID, pfi.Filename, pfi.CompositeKey)
if err != nil {
return nil, nil, nil, err
}

return GetPackageFileStream(ctx, pf)
return OpenFileForDownload(ctx, pf)
}

// GetPackageFileStream returns the content of the specific package file
func GetPackageFileStream(ctx context.Context, pf *packages_model.PackageFile) (io.ReadSeekCloser, *url.URL, *packages_model.PackageFile, error) {
// OpenFileForDownload returns the content of the specific package file and increases the download counter.
func OpenFileForDownload(ctx context.Context, pf *packages_model.PackageFile) (io.ReadSeekCloser, *url.URL, *packages_model.PackageFile, error) {
pb, err := packages_model.GetBlobByID(ctx, pf.BlobID)
if err != nil {
return nil, nil, nil, err
}

return GetPackageBlobStream(ctx, pf, pb, nil)
return OpenBlobForDownload(ctx, pf, pb, nil)
}

func OpenBlobStream(pb *packages_model.PackageBlob) (io.ReadSeekCloser, error) {
Expand All @@ -605,9 +605,9 @@ func OpenBlobStream(pb *packages_model.PackageBlob) (io.ReadSeekCloser, error) {
return cs.OpenBlob(key)
}

// GetPackageBlobStream returns the content of the specific package blob
// OpenBlobForDownload returns the content of the specific package blob and increases the download counter.
// If the storage supports direct serving and it's enabled, only the direct serving url is returned.
func GetPackageBlobStream(ctx context.Context, pf *packages_model.PackageFile, pb *packages_model.PackageBlob, serveDirectReqParams url.Values) (io.ReadSeekCloser, *url.URL, *packages_model.PackageFile, error) {
func OpenBlobForDownload(ctx context.Context, pf *packages_model.PackageFile, pb *packages_model.PackageBlob, serveDirectReqParams url.Values) (io.ReadSeekCloser, *url.URL, *packages_model.PackageFile, error) {
key := packages_module.BlobHash256Key(pb.HashSHA256)

cs := packages_module.NewContentStore()
Expand Down
4 changes: 2 additions & 2 deletions templates/package/content/container.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
{{end}}
</h4>
<div class="ui attached segment tw-break-anywhere">
<table class="ui very basic compact table">
<table class="ui very basic compact table tw-font-mono">
<tbody>
{{range $imageMetadata.ImageLayers}}
<tr>
Expand All @@ -98,7 +98,7 @@
{{if $imageMetadata.Labels}}
<h4 class="ui top attached header">{{ctx.Locale.Tr "packages.container.labels"}}</h4>
<div class="ui attached segment">
<table class="ui very basic compact table">
<table class="ui very basic compact table tw-font-mono">
<thead>
<tr>
<th>{{ctx.Locale.Tr "packages.container.labels.key"}}</th>
Expand Down
8 changes: 4 additions & 4 deletions templates/package/shared/view.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
{{end}}
</div>
</div>
<div class="issue-content">
<div class="issue-content-left">
<div class="packages-content">
<div class="packages-content-left">
{{template "package/content/alpine" .}}
{{template "package/content/arch" .}}
{{template "package/content/cargo" .}}
Expand All @@ -35,7 +35,7 @@
{{template "package/content/swift" .}}
{{template "package/content/vagrant" .}}
</div>
<div class="issue-content-right ui segment">
<div class="ui segment packages-content-right">
<strong>{{ctx.Locale.Tr "packages.details"}}</strong>
<div class="ui relaxed list flex-items-block">
<div class="item">{{svg .PackageDescriptor.Package.Type.SVGName}} {{.PackageDescriptor.Package.Type.Name}}</div>
Expand Down Expand Up @@ -76,7 +76,7 @@
{{range .PackageDescriptor.Files}}
<div class="item">
<a href="{{$packageVersionLink}}/files/{{.File.ID}}">{{.File.Name}}</a>
<span class="text small file-size">{{FileSize .Blob.Size}}</span>
<span class="text small tw-whitespace-nowrap">{{FileSize .Blob.Size}}</span>
</div>
{{end}}
</div>
Expand Down
1 change: 1 addition & 0 deletions web_src/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
@import "./repo/reactions.css";
@import "./repo/clone.css";
@import "./repo/commit-sign.css";
@import "./repo/packages.css";

@import "./editor/fileeditor.css";
@import "./editor/combomarkdowneditor.css";
Expand Down
4 changes: 0 additions & 4 deletions web_src/css/repo.css
Original file line number Diff line number Diff line change
Expand Up @@ -1227,10 +1227,6 @@ td .commit-summary {
font-weight: var(--font-weight-normal);
}

.repository.packages .file-size {
white-space: nowrap;
}

.repository .activity-header {
display: flex;
justify-content: space-between;
Expand Down
Loading
Loading