@@ -71,6 +71,7 @@ import (
7171
7272 "code.gitea.io/gitea/models/actions"
7373 "code.gitea.io/gitea/models/db"
74+ "code.gitea.io/gitea/modules/httplib"
7475 "code.gitea.io/gitea/modules/json"
7576 "code.gitea.io/gitea/modules/log"
7677 "code.gitea.io/gitea/modules/setting"
@@ -184,8 +185,8 @@ type artifactRoutes struct {
184185 fs storage.ObjectStorage
185186}
186187
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 * context. Context , runID int64 , artifactHash , suffix string ) string {
189+ uploadURL := strings .TrimSuffix (httplib . GuessCurrentAppURL ( ctx ) , "/" ) + strings .TrimSuffix (ar .prefix , "/" ) +
189190 strings .ReplaceAll (artifactRouteBase , "{run_id}" , strconv .FormatInt (runID , 10 )) +
190191 "/" + artifactHash + "/" + suffix
191192 return uploadURL
@@ -224,7 +225,7 @@ func (ar artifactRoutes) getUploadArtifactURL(ctx *ArtifactContext) {
224225 // use md5(artifact_name) to create upload url
225226 artifactHash := fmt .Sprintf ("%x" , md5 .Sum ([]byte (req .Name )))
226227 resp := getUploadArtifactResponse {
227- FileContainerResourceURL : ar .buildArtifactURL (runID , artifactHash , "upload" + retentionQuery ),
228+ FileContainerResourceURL : ar .buildArtifactURL (ctx , runID , artifactHash , "upload" + retentionQuery ),
228229 }
229230 log .Debug ("[artifact] get upload url: %s" , resp .FileContainerResourceURL )
230231 ctx .JSON (http .StatusOK , resp )
@@ -365,7 +366,7 @@ func (ar artifactRoutes) listArtifacts(ctx *ArtifactContext) {
365366 artifactHash := fmt .Sprintf ("%x" , md5 .Sum ([]byte (art .ArtifactName )))
366367 item := listArtifactsResponseItem {
367368 Name : art .ArtifactName ,
368- FileContainerResourceURL : ar .buildArtifactURL (runID , artifactHash , "download_url" ),
369+ FileContainerResourceURL : ar .buildArtifactURL (ctx , runID , artifactHash , "download_url" ),
369370 }
370371 items = append (items , item )
371372 values [art .ArtifactName ] = true
@@ -437,7 +438,7 @@ func (ar artifactRoutes) getDownloadArtifactURL(ctx *ArtifactContext) {
437438 }
438439 }
439440 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" )
441442 }
442443 item := downloadArtifactResponseItem {
443444 Path : util .PathJoinRel (itemPath , artifact .ArtifactPath ),
0 commit comments