mirror of
https://github.com/go-gitea/gitea.git
synced 2024-09-01 14:56:30 +00:00
getting storage object instead of reading bytes
This commit is contained in:
parent
1ea4d48b39
commit
faff9d9c57
@ -155,13 +155,13 @@ func Get(ctx *context.Context) {
|
||||
// Packages are stored in different way from pacman databases, and loaded
|
||||
// with LoadPackageFile function.
|
||||
if strings.HasSuffix(file, "tar.zst") || strings.HasSuffix(file, "zst.sig") {
|
||||
pkgdata, err := arch_service.LoadFile(ctx, distro, file)
|
||||
pkg, err := arch_service.GetFileObject(ctx, distro, file)
|
||||
if err != nil {
|
||||
apiError(ctx, http.StatusNotFound, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.ServeContent(bytes.NewReader(pkgdata), &context.ServeHeaderOptions{
|
||||
ctx.ServeContent(pkg, &context.ServeHeaderOptions{
|
||||
Filename: file,
|
||||
CacheDuration: time.Minute * 5,
|
||||
})
|
||||
|
@ -6,7 +6,6 @@ package arch
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
@ -19,6 +18,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/packages"
|
||||
"code.gitea.io/gitea/modules/packages/arch"
|
||||
"code.gitea.io/gitea/modules/storage"
|
||||
pkg_service "code.gitea.io/gitea/services/packages"
|
||||
)
|
||||
|
||||
@ -107,7 +107,7 @@ func SaveFile(ctx *context.Context, p *SaveFileParams) (int64, error) {
|
||||
|
||||
// Get data related to provided file name and distribution, and update download
|
||||
// counter if actual package file is retrieved from database.
|
||||
func LoadFile(ctx *context.Context, distro, file string) ([]byte, error) {
|
||||
func GetFileObject(ctx *context.Context, distro, file string) (storage.Object, error) {
|
||||
db := db.GetEngine(ctx)
|
||||
|
||||
pkgfile := &pkg_model.PackageFile{CompositeKey: distro + "-" + file}
|
||||
@ -131,12 +131,7 @@ func LoadFile(ctx *context.Context, distro, file string) ([]byte, error) {
|
||||
|
||||
cs := packages.NewContentStore()
|
||||
|
||||
obj, err := cs.Get(packages.BlobHash256Key(blob.HashSHA256))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return io.ReadAll(obj)
|
||||
return cs.Get(packages.BlobHash256Key(blob.HashSHA256))
|
||||
}
|
||||
|
||||
// Automatically connect repository to pushed package, if package with provided
|
||||
|
Loading…
Reference in New Issue
Block a user