-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Artifacts download api for artifact actions v4 #33510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 39 commits
32b6aef
f7a1dca
3f0cafd
ef5b069
26514c9
e7308ac
e129fe8
d5520bd
d3dbfcb
d50358f
bbb7017
fcb8d55
db619c3
f4b0811
c6f1557
dfae484
ae2202d
b4c318c
5e3c79d
b1b0ef3
e1ce404
59cf964
4721100
7a35443
e137972
44bde87
a18c8dd
f8ce2f6
5b76dbe
6009e63
8485044
f58f33d
d56cebf
ee37003
5d7bf81
3d1b156
e6629fc
7861808
8e48777
421b7b4
a00f7f8
156f0db
3df911a
4c1399d
a0ed53d
12c627a
f80f4d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2025 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package actions | ||
|
||
import ( | ||
"net/http" | ||
|
||
actions_model "code.gitea.io/gitea/models/actions" | ||
"code.gitea.io/gitea/modules/setting" | ||
"code.gitea.io/gitea/modules/storage" | ||
"code.gitea.io/gitea/services/context" | ||
) | ||
|
||
// Artifacts using the v4 backend are stored as a single combined zip file per artifact on the backend | ||
// The v4 backend ensures ContentEncoding is set to "application/zip", which is not the case for the old backend | ||
func IsArtifactV4(art *actions_model.ActionArtifact) bool { | ||
return art.ArtifactName+".zip" == art.ArtifactPath && art.ContentEncoding == "application/zip" | ||
} | ||
|
||
func DownloadArtifactV4ServeDirectOnly(ctx *context.Base, art *actions_model.ActionArtifact) (bool, error) { | ||
if setting.Actions.ArtifactStorage.ServeDirect() { | ||
u, err := storage.ActionsArtifacts.URL(art.StoragePath, art.ArtifactPath, nil) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right, currently the error return value seems to be accidentally not returned. But I want to make sure we get the expected behavior here, therefore I want some discussion about this before making changes If we just return the error here (without changing the callers), this error may get returned by the api instead of triggering the fallback ( tunneling blob via gitea ). What do we want to do with this error?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's fine to keep as other behaviors, no need to introduce too many changes at the moment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I think it's OK to keep the current behavior. Maybe we can add some logs for this error later to help us debug cases where |
||
if u != nil && err == nil { | ||
ctx.Redirect(u.String(), http.StatusFound) | ||
return true, nil | ||
} | ||
} | ||
return false, nil | ||
} | ||
|
||
func DownloadArtifactV4Fallback(ctx *context.Base, art *actions_model.ActionArtifact) error { | ||
f, err := storage.ActionsArtifacts.Open(art.StoragePath) | ||
if err != nil { | ||
return err | ||
} | ||
defer f.Close() | ||
http.ServeContent(ctx.Resp, ctx.Req, art.ArtifactName+".zip", art.CreatedUnix.AsLocalTime(), f) | ||
return nil | ||
} | ||
|
||
func DownloadArtifactV4(ctx *context.Base, art *actions_model.ActionArtifact) error { | ||
ok, err := DownloadArtifactV4ServeDirectOnly(ctx, art) | ||
if ok || err != nil { | ||
return err | ||
} | ||
return DownloadArtifactV4Fallback(ctx, art) | ||
} |
Uh oh!
There was an error while loading. Please reload this page.