diff --git a/routers/web/devtest/mock_actions.go b/routers/web/devtest/mock_actions.go index 87b25d86fc..48acb90094 100644 --- a/routers/web/devtest/mock_actions.go +++ b/routers/web/devtest/mock_actions.go @@ -6,7 +6,6 @@ package devtest import ( "archive/zip" "fmt" - "html/template" "io" mathRand "math/rand/v2" "net/http" @@ -31,12 +30,13 @@ type mockArtifactFile struct { } type mockArtifactPreviewTemplateData struct { - ArtifactName string - Files []mockArtifactPreviewTemplateFile - PreviewURL string - PreviewRaw string - DownloadURL string - SelectedPath string + ArtifactName string + PreviewFiles []mockArtifactPreviewTemplateFile + RunURL string + PreviewURL string + PreviewRawURL string + DownloadURL string + SelectedPath string } type mockArtifactPreviewTemplateFile struct { @@ -69,40 +69,6 @@ var mockActionsArtifactFiles = map[string][]mockArtifactFile{ }, } -var mockArtifactPreviewTemplate = template.Must(template.New("mock-artifact-preview").Parse(` - - - - Artifact Preview - - - -

Preview: {{.ArtifactName}}

-

Reload | Download ZIP

-
-
- {{range .Files}} - {{.Path}} - {{end}} -
-
- {{if .SelectedPath}} - - {{else}} -

No files

- {{end}} -
-
- -`)) - func normalizeMockArtifactPath(path string) string { path = util.PathJoinRelX(path) if path == "." { @@ -387,19 +353,23 @@ func MockActionsArtifactPreview(ctx *context.Context) { previewRawURL := previewURL + "/raw" downloadURL := fmt.Sprintf("%s/devtest/repo-action-view/runs/%d/artifacts/%s", setting.AppSubURL, runID, url.PathEscape(artifactName)) data := mockArtifactPreviewTemplateData{ - ArtifactName: artifactName, - Files: templateFiles, - PreviewURL: previewURL, - PreviewRaw: previewRawURL, - DownloadURL: downloadURL, - SelectedPath: selectedPath, + ArtifactName: artifactName, + PreviewFiles: templateFiles, + RunURL: previewURL, + PreviewURL: previewURL, + PreviewRawURL: previewRawURL, + DownloadURL: downloadURL, + SelectedPath: selectedPath, } - ctx.Resp.Header().Set("Content-Type", "text/html; charset=utf-8") - if err := mockArtifactPreviewTemplate.Execute(ctx.Resp, data); err != nil { - ctx.ServerError("mockArtifactPreviewTemplate.Execute", err) - return - } + ctx.Data["ArtifactName"] = data.ArtifactName + ctx.Data["PreviewFiles"] = data.PreviewFiles + ctx.Data["RunURL"] = data.RunURL + ctx.Data["PreviewURL"] = data.PreviewURL + ctx.Data["PreviewRawURL"] = data.PreviewRawURL + ctx.Data["DownloadURL"] = data.DownloadURL + ctx.Data["SelectedPath"] = data.SelectedPath + ctx.HTML(http.StatusOK, "devtest/repo-action-artifact-preview") } func MockActionsArtifactPreviewRaw(ctx *context.Context) { @@ -410,7 +380,11 @@ func MockActionsArtifactPreviewRaw(ctx *context.Context) { return } - selectedPath := chooseMockArtifactPath(files, normalizeMockArtifactPath(ctx.Req.URL.Query().Get("path"))) + selectedPath := normalizeMockArtifactPath(strings.TrimPrefix(ctx.PathParam("*"), "/")) + if selectedPath == "" { + selectedPath = normalizeMockArtifactPath(ctx.Req.URL.Query().Get("path")) + } + selectedPath = chooseMockArtifactPath(files, selectedPath) if selectedPath == "" { ctx.NotFound(nil) return @@ -442,5 +416,6 @@ func MockActionsArtifactPreviewRaw(ctx *context.Context) { ctx.ServeContent(strings.NewReader(selectedFile.Content), context.ServeHeaderOptions{ Filename: selectedFile.Path, ContentLength: &size, + ContentType: "text/plain; charset=utf-8", }) } diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go index b45e453702..d2ce14bcd0 100644 --- a/routers/web/repo/actions/view.go +++ b/routers/web/repo/actions/view.go @@ -905,7 +905,8 @@ func previewArtifactByReadSeeker(ctx *context_module.Context, path string, reade return } ctx.ServeContent(reader, context_module.ServeHeaderOptions{ - Filename: path, + Filename: path, + ContentType: st.GetMimeType(), }) } diff --git a/templates/devtest/repo-action-artifact-preview.tmpl b/templates/devtest/repo-action-artifact-preview.tmpl new file mode 100644 index 0000000000..2855f431a3 --- /dev/null +++ b/templates/devtest/repo-action-artifact-preview.tmpl @@ -0,0 +1,28 @@ +{{template "base/head" .}} +
+
+ {{template "shared/actions/artifact_preview_content" .}} +
+
+ + +{{template "base/footer" .}} diff --git a/templates/repo/actions/artifact_preview.tmpl b/templates/repo/actions/artifact_preview.tmpl index 86993f271d..d557f21518 100644 --- a/templates/repo/actions/artifact_preview.tmpl +++ b/templates/repo/actions/artifact_preview.tmpl @@ -3,43 +3,9 @@
{{template "repo/header" .}} -
- - -
-
- -
-
- {{if .SelectedPath}} - - {{else}} -
{{ctx.Locale.Tr "none"}}
- {{end}} -
-
+
+ {{template "base/alert" .}} + {{template "shared/actions/artifact_preview_content" .}}
@@ -48,22 +14,10 @@ margin-top: 1rem; } -.artifact-preview-header { - display: flex; - align-items: center; - justify-content: space-between; - gap: 1rem; - margin-bottom: 1rem; -} - .artifact-preview-title { min-width: 0; } -.artifact-preview-title .ui.header { - margin-bottom: 0.25rem; -} - .artifact-preview-subtitle { color: var(--color-text-light-3); } diff --git a/templates/shared/actions/artifact_preview_content.tmpl b/templates/shared/actions/artifact_preview_content.tmpl new file mode 100644 index 0000000000..0c787777a6 --- /dev/null +++ b/templates/shared/actions/artifact_preview_content.tmpl @@ -0,0 +1,38 @@ +
+
+ {{ctx.Locale.Tr "preview"}}: {{.ArtifactName}} + +
+ + {{svg "octicon-download"}} + {{ctx.Locale.Tr "repo.download_file"}} + +
+ +
+
+
+ +
+
+ {{if .SelectedPath}} + + {{else}} +
{{ctx.Locale.Tr "none"}}
+ {{end}} +
+
+
diff --git a/web_src/js/components/RepoActionView.vue b/web_src/js/components/RepoActionView.vue index 74e23f11d9..46460ba501 100644 --- a/web_src/js/components/RepoActionView.vue +++ b/web_src/js/components/RepoActionView.vue @@ -133,12 +133,12 @@ async function deleteArtifact(name: string) {