diff options
author | ChristopherHX <christopher.homberger@web.de> | 2025-02-16 01:32:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-16 08:32:54 +0800 |
commit | 2b8cfb557d4b891bce8e67a3be280dc058c9791e (patch) | |
tree | 2dad4d6bac699fdc0a73101e5359e50d90c808a4 /routers/web/repo | |
parent | 01bf8da02e6febd0784f676e949910d6c5233d0e (diff) | |
download | gitea-2b8cfb557d4b891bce8e67a3be280dc058c9791e.tar.gz gitea-2b8cfb557d4b891bce8e67a3be280dc058c9791e.zip |
Artifacts download api for artifact actions v4 (#33510)
* download endpoint has to use 302 redirect
* fake blob download used if direct download not possible
* downloading v3 artifacts not possible
New repo apis based on GitHub Rest V3
- GET /runs/{run}/artifacts (Cannot use run index of url due to not
being unique)
- GET /artifacts
- GET + DELETE /artifacts/{artifact_id}
- GET /artifacts/{artifact_id}/zip
- (GET /artifacts/{artifact_id}/zip/raw this is a workaround for a http
302 assertion in actions/toolkit)
- api docs removed this is protected by a signed url like the internal
artifacts api and no longer usable with any token or swagger
- returns http 401 if the signature is invalid
- or change the artifact id
- or expired after 1 hour
Closes #33353
Closes #32124
---------
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'routers/web/repo')
-rw-r--r-- | routers/web/repo/actions/view.go | 18 |
1 files changed, 3 insertions, 15 deletions
diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go index 7099582c1b..0e71ce6ff8 100644 --- a/routers/web/repo/actions/view.go +++ b/routers/web/repo/actions/view.go @@ -26,7 +26,6 @@ import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" - "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/storage" "code.gitea.io/gitea/modules/templates" "code.gitea.io/gitea/modules/timeutil" @@ -669,7 +668,7 @@ func ArtifactsDownloadView(ctx *context_module.Context) { // if artifacts status is not uploaded-confirmed, treat it as not found for _, art := range artifacts { - if art.Status != int64(actions_model.ArtifactStatusUploadConfirmed) { + if art.Status != actions_model.ArtifactStatusUploadConfirmed { ctx.Error(http.StatusNotFound, "artifact not found") return } @@ -677,23 +676,12 @@ func ArtifactsDownloadView(ctx *context_module.Context) { ctx.Resp.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=%s.zip; filename*=UTF-8''%s.zip", url.PathEscape(artifactName), artifactName)) - // Artifacts using the v4 backend are stored as a single combined zip file per artifact on the backend - // The v4 backend enshures ContentEncoding is set to "application/zip", which is not the case for the old backend - if len(artifacts) == 1 && artifacts[0].ArtifactName+".zip" == artifacts[0].ArtifactPath && artifacts[0].ContentEncoding == "application/zip" { - art := artifacts[0] - if setting.Actions.ArtifactStorage.ServeDirect() { - u, err := storage.ActionsArtifacts.URL(art.StoragePath, art.ArtifactPath, nil) - if u != nil && err == nil { - ctx.Redirect(u.String()) - return - } - } - f, err := storage.ActionsArtifacts.Open(art.StoragePath) + if len(artifacts) == 1 && actions.IsArtifactV4(artifacts[0]) { + err := actions.DownloadArtifactV4(ctx.Base, artifacts[0]) if err != nil { ctx.Error(http.StatusInternalServerError, err.Error()) return } - _, _ = io.Copy(ctx.Resp, f) return } |