Download lfs in git and web workflow from minio/s3 directly (#16731)
This commit is contained in:
parent
06f82641cb
commit
7844bf1430
2 changed files with 20 additions and 0 deletions
|
@ -11,6 +11,8 @@ import (
|
||||||
"code.gitea.io/gitea/modules/httpcache"
|
"code.gitea.io/gitea/modules/httpcache"
|
||||||
"code.gitea.io/gitea/modules/lfs"
|
"code.gitea.io/gitea/modules/lfs"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/storage"
|
||||||
"code.gitea.io/gitea/routers/common"
|
"code.gitea.io/gitea/routers/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -47,6 +49,16 @@ func ServeBlobOrLFS(ctx *context.Context, blob *git.Blob) error {
|
||||||
if httpcache.HandleGenericETagCache(ctx.Req, ctx.Resp, `"`+pointer.Oid+`"`) {
|
if httpcache.HandleGenericETagCache(ctx.Req, ctx.Resp, `"`+pointer.Oid+`"`) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if setting.LFS.ServeDirect {
|
||||||
|
//If we have a signed url (S3, object storage), redirect to this directly.
|
||||||
|
u, err := storage.LFS.URL(pointer.RelativePath(), blob.Name())
|
||||||
|
if u != nil && err == nil {
|
||||||
|
ctx.Redirect(u.String())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lfsDataRc, err := lfs.ReadMetaObject(meta.Pointer)
|
lfsDataRc, err := lfs.ReadMetaObject(meta.Pointer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -21,6 +21,7 @@ import (
|
||||||
lfs_module "code.gitea.io/gitea/modules/lfs"
|
lfs_module "code.gitea.io/gitea/modules/lfs"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"code.gitea.io/gitea/modules/storage"
|
||||||
|
|
||||||
"github.com/golang-jwt/jwt"
|
"github.com/golang-jwt/jwt"
|
||||||
)
|
)
|
||||||
|
@ -401,6 +402,13 @@ func buildObjectResponse(rc *requestContext, pointer lfs_module.Pointer, downloa
|
||||||
|
|
||||||
if download {
|
if download {
|
||||||
rep.Actions["download"] = &lfs_module.Link{Href: rc.DownloadLink(pointer), Header: header}
|
rep.Actions["download"] = &lfs_module.Link{Href: rc.DownloadLink(pointer), Header: header}
|
||||||
|
if setting.LFS.ServeDirect {
|
||||||
|
//If we have a signed url (S3, object storage), redirect to this directly.
|
||||||
|
u, err := storage.LFS.URL(pointer.RelativePath(), pointer.Oid)
|
||||||
|
if u != nil && err == nil {
|
||||||
|
rep.Actions["download"] = &lfs_module.Link{Href: u.String(), Header: header}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if upload {
|
if upload {
|
||||||
rep.Actions["upload"] = &lfs_module.Link{Href: rc.UploadLink(pointer), Header: header}
|
rep.Actions["upload"] = &lfs_module.Link{Href: rc.UploadLink(pointer), Header: header}
|
||||||
|
|
Loading…
Reference in a new issue