@@ -71,6 +71,7 @@ import (
71
71
72
72
"code.gitea.io/gitea/models/actions"
73
73
"code.gitea.io/gitea/models/db"
74
+ "code.gitea.io/gitea/modules/httplib"
74
75
"code.gitea.io/gitea/modules/json"
75
76
"code.gitea.io/gitea/modules/log"
76
77
"code.gitea.io/gitea/modules/setting"
@@ -184,8 +185,8 @@ type artifactRoutes struct {
184
185
fs storage.ObjectStorage
185
186
}
186
187
187
- func (ar artifactRoutes ) buildArtifactURL (runID int64 , artifactHash , suffix string ) string {
188
- uploadURL := strings .TrimSuffix (setting . AppURL , "/" ) + strings .TrimSuffix (ar .prefix , "/" ) +
188
+ func (ar artifactRoutes ) buildArtifactURL (ctx * ArtifactContext , runID int64 , artifactHash , suffix string ) string {
189
+ uploadURL := strings .TrimSuffix (httplib . GuessCurrentAppURL ( ctx ) , "/" ) + strings .TrimSuffix (ar .prefix , "/" ) +
189
190
strings .ReplaceAll (artifactRouteBase , "{run_id}" , strconv .FormatInt (runID , 10 )) +
190
191
"/" + artifactHash + "/" + suffix
191
192
return uploadURL
@@ -224,7 +225,7 @@ func (ar artifactRoutes) getUploadArtifactURL(ctx *ArtifactContext) {
224
225
// use md5(artifact_name) to create upload url
225
226
artifactHash := fmt .Sprintf ("%x" , md5 .Sum ([]byte (req .Name )))
226
227
resp := getUploadArtifactResponse {
227
- FileContainerResourceURL : ar .buildArtifactURL (runID , artifactHash , "upload" + retentionQuery ),
228
+ FileContainerResourceURL : ar .buildArtifactURL (ctx , runID , artifactHash , "upload" + retentionQuery ),
228
229
}
229
230
log .Debug ("[artifact] get upload url: %s" , resp .FileContainerResourceURL )
230
231
ctx .JSON (http .StatusOK , resp )
@@ -365,7 +366,7 @@ func (ar artifactRoutes) listArtifacts(ctx *ArtifactContext) {
365
366
artifactHash := fmt .Sprintf ("%x" , md5 .Sum ([]byte (art .ArtifactName )))
366
367
item := listArtifactsResponseItem {
367
368
Name : art .ArtifactName ,
368
- FileContainerResourceURL : ar .buildArtifactURL (runID , artifactHash , "download_url" ),
369
+ FileContainerResourceURL : ar .buildArtifactURL (ctx , runID , artifactHash , "download_url" ),
369
370
}
370
371
items = append (items , item )
371
372
values [art .ArtifactName ] = true
@@ -437,7 +438,7 @@ func (ar artifactRoutes) getDownloadArtifactURL(ctx *ArtifactContext) {
437
438
}
438
439
}
439
440
if downloadURL == "" {
440
- downloadURL = ar .buildArtifactURL (runID , strconv .FormatInt (artifact .ID , 10 ), "download" )
441
+ downloadURL = ar .buildArtifactURL (ctx , runID , strconv .FormatInt (artifact .ID , 10 ), "download" )
441
442
}
442
443
item := downloadArtifactResponseItem {
443
444
Path : util .PathJoinRel (itemPath , artifact .ArtifactPath ),
0 commit comments