Skip to content

Commit 7844bf1

Browse files
authored
Download lfs in git and web workflow from minio/s3 directly (#16731)
1 parent 06f8264 commit 7844bf1

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

routers/web/repo/download.go

+12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"code.gitea.io/gitea/modules/httpcache"
1212
"code.gitea.io/gitea/modules/lfs"
1313
"code.gitea.io/gitea/modules/log"
14+
"code.gitea.io/gitea/modules/setting"
15+
"code.gitea.io/gitea/modules/storage"
1416
"code.gitea.io/gitea/routers/common"
1517
)
1618

@@ -47,6 +49,16 @@ func ServeBlobOrLFS(ctx *context.Context, blob *git.Blob) error {
4749
if httpcache.HandleGenericETagCache(ctx.Req, ctx.Resp, `"`+pointer.Oid+`"`) {
4850
return nil
4951
}
52+
53+
if setting.LFS.ServeDirect {
54+
//If we have a signed url (S3, object storage), redirect to this directly.
55+
u, err := storage.LFS.URL(pointer.RelativePath(), blob.Name())
56+
if u != nil && err == nil {
57+
ctx.Redirect(u.String())
58+
return nil
59+
}
60+
}
61+
5062
lfsDataRc, err := lfs.ReadMetaObject(meta.Pointer)
5163
if err != nil {
5264
return err

services/lfs/server.go

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
lfs_module "code.gitea.io/gitea/modules/lfs"
2222
"code.gitea.io/gitea/modules/log"
2323
"code.gitea.io/gitea/modules/setting"
24+
"code.gitea.io/gitea/modules/storage"
2425

2526
"github.com/golang-jwt/jwt"
2627
)
@@ -401,6 +402,13 @@ func buildObjectResponse(rc *requestContext, pointer lfs_module.Pointer, downloa
401402

402403
if download {
403404
rep.Actions["download"] = &lfs_module.Link{Href: rc.DownloadLink(pointer), Header: header}
405+
if setting.LFS.ServeDirect {
406+
//If we have a signed url (S3, object storage), redirect to this directly.
407+
u, err := storage.LFS.URL(pointer.RelativePath(), pointer.Oid)
408+
if u != nil && err == nil {
409+
rep.Actions["download"] = &lfs_module.Link{Href: u.String(), Header: header}
410+
}
411+
}
404412
}
405413
if upload {
406414
rep.Actions["upload"] = &lfs_module.Link{Href: rc.UploadLink(pointer), Header: header}

0 commit comments

Comments
 (0)