From 5f21655f77ee15cb98a3e2ee44199595be99f5ae Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Fri, 9 Feb 2024 21:14:50 +0000 Subject: [PATCH 1/2] Add support for serve direct. --- routers/api/actions/artifacts.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/routers/api/actions/artifacts.go b/routers/api/actions/artifacts.go index 3363c4c0e81b0..4fd2639b21eb0 100644 --- a/routers/api/actions/artifacts.go +++ b/routers/api/actions/artifacts.go @@ -63,6 +63,7 @@ package actions import ( "crypto/md5" + "errors" "fmt" "net/http" "strconv" @@ -426,7 +427,18 @@ func (ar artifactRoutes) getDownloadArtifactURL(ctx *ArtifactContext) { var items []downloadArtifactResponseItem for _, artifact := range artifacts { - downloadURL := ar.buildArtifactURL(runID, strconv.FormatInt(artifact.ID, 10), "download") + var downloadURL string + if setting.Actions.ArtifactStorage.MinioConfig.ServeDirect { + u, err := ar.fs.URL(artifact.StoragePath, artifact.ArtifactName) + if err != nil && !errors.Is(err, storage.ErrURLNotSupported) { + log.Error("Error getting serve direct url: %v", err) + ctx.Error(http.StatusInternalServerError, err.Error()) + return + } + downloadURL = u.String() + } else { + downloadURL = ar.buildArtifactURL(runID, strconv.FormatInt(artifact.ID, 10), "download") + } item := downloadArtifactResponseItem{ Path: util.PathJoinRel(itemPath, artifact.ArtifactPath), ItemType: "file", From bebc04396b72e0929c7787d85fabaef7d4d31029 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Sun, 11 Feb 2024 23:13:00 +0100 Subject: [PATCH 2/2] Fallback to local download url. --- routers/api/actions/artifacts.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/routers/api/actions/artifacts.go b/routers/api/actions/artifacts.go index 4fd2639b21eb0..9fbd3f045d759 100644 --- a/routers/api/actions/artifacts.go +++ b/routers/api/actions/artifacts.go @@ -432,11 +432,12 @@ func (ar artifactRoutes) getDownloadArtifactURL(ctx *ArtifactContext) { u, err := ar.fs.URL(artifact.StoragePath, artifact.ArtifactName) if err != nil && !errors.Is(err, storage.ErrURLNotSupported) { log.Error("Error getting serve direct url: %v", err) - ctx.Error(http.StatusInternalServerError, err.Error()) - return } - downloadURL = u.String() - } else { + if u != nil { + downloadURL = u.String() + } + } + if downloadURL == "" { downloadURL = ar.buildArtifactURL(runID, strconv.FormatInt(artifact.ID, 10), "download") } item := downloadArtifactResponseItem{