mirror of
https://github.com/go-gitea/gitea
synced 2024-11-15 22:41:44 +01:00
Fix container download counter (#19287)
* Increment counter on manifest download. * Refactor GetPackageFileStream method.
This commit is contained in:
parent
242d71035a
commit
08d199245a
4 changed files with 7 additions and 14 deletions
|
@ -367,7 +367,7 @@ func GetBlob(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
s, err := packages_module.NewContentStore().Get(packages_module.BlobHash256Key(blob.Blob.HashSHA256))
|
s, _, err := packages_service.GetPackageFileStream(ctx, blob.File)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
apiError(ctx, http.StatusInternalServerError, err)
|
apiError(ctx, http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
|
@ -506,7 +506,7 @@ func GetManifest(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
s, err := packages_module.NewContentStore().Get(packages_module.BlobHash256Key(manifest.Blob.HashSHA256))
|
s, _, err := packages_service.GetPackageFileStream(ctx, manifest.File)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
apiError(ctx, http.StatusInternalServerError, err)
|
apiError(ctx, http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -376,13 +376,7 @@ func DownloadSymbolFile(ctx *context.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pv, err := packages_model.GetVersionByID(ctx, pfs[0].VersionID)
|
s, _, err := packages_service.GetPackageFileStream(ctx, pfs[0])
|
||||||
if err != nil {
|
|
||||||
apiError(ctx, http.StatusInternalServerError, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
s, _, err := packages_service.GetPackageFileStream(ctx, pv, pfs[0])
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == packages_model.ErrPackageNotExist || err == packages_model.ErrPackageFileNotExist {
|
if err == packages_model.ErrPackageNotExist || err == packages_model.ErrPackageFileNotExist {
|
||||||
apiError(ctx, http.StatusNotFound, err)
|
apiError(ctx, http.StatusNotFound, err)
|
||||||
|
|
|
@ -331,7 +331,6 @@ func DownloadPackageFile(ctx *context.Context) {
|
||||||
|
|
||||||
s, _, err := packages_service.GetPackageFileStream(
|
s, _, err := packages_service.GetPackageFileStream(
|
||||||
ctx,
|
ctx,
|
||||||
ctx.Package.Descriptor.Version,
|
|
||||||
pf,
|
pf,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -426,7 +426,7 @@ func GetFileStreamByPackageVersionAndFileID(ctx context.Context, owner *user_mod
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return GetPackageFileStream(ctx, pv, pf)
|
return GetPackageFileStream(ctx, pf)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFileStreamByPackageVersion returns the content of the specific package file
|
// GetFileStreamByPackageVersion returns the content of the specific package file
|
||||||
|
@ -436,11 +436,11 @@ func GetFileStreamByPackageVersion(ctx context.Context, pv *packages_model.Packa
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return GetPackageFileStream(ctx, pv, pf)
|
return GetPackageFileStream(ctx, pf)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPackageFileStream returns the content of the specific package file
|
// GetPackageFileStream returns the content of the specific package file
|
||||||
func GetPackageFileStream(ctx context.Context, pv *packages_model.PackageVersion, pf *packages_model.PackageFile) (io.ReadCloser, *packages_model.PackageFile, error) {
|
func GetPackageFileStream(ctx context.Context, pf *packages_model.PackageFile) (io.ReadCloser, *packages_model.PackageFile, error) {
|
||||||
pb, err := packages_model.GetBlobByID(ctx, pf.BlobID)
|
pb, err := packages_model.GetBlobByID(ctx, pf.BlobID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
|
@ -449,7 +449,7 @@ func GetPackageFileStream(ctx context.Context, pv *packages_model.PackageVersion
|
||||||
s, err := packages_module.NewContentStore().Get(packages_module.BlobHash256Key(pb.HashSHA256))
|
s, err := packages_module.NewContentStore().Get(packages_module.BlobHash256Key(pb.HashSHA256))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if pf.IsLead {
|
if pf.IsLead {
|
||||||
if err := packages_model.IncrementDownloadCounter(ctx, pv.ID); err != nil {
|
if err := packages_model.IncrementDownloadCounter(ctx, pf.VersionID); err != nil {
|
||||||
log.Error("Error incrementing download counter: %v", err)
|
log.Error("Error incrementing download counter: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue