mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-11 09:15:31 +02:00
simplify
This commit is contained in:
parent
c361782af9
commit
b7ae17c92a
@ -29,21 +29,6 @@ type mockArtifactFile struct {
|
||||
Content string
|
||||
}
|
||||
|
||||
type mockArtifactPreviewTemplateData struct {
|
||||
ArtifactName string
|
||||
PreviewFiles []mockArtifactPreviewTemplateFile
|
||||
RunURL string
|
||||
PreviewURL string
|
||||
PreviewRawURL string
|
||||
DownloadURL string
|
||||
SelectedPath string
|
||||
}
|
||||
|
||||
type mockArtifactPreviewTemplateFile struct {
|
||||
Path string
|
||||
Selected bool
|
||||
}
|
||||
|
||||
var mockActionsArtifactFiles = map[string][]mockArtifactFile{
|
||||
"artifact-b": {
|
||||
{
|
||||
@ -77,11 +62,6 @@ func normalizeMockArtifactPath(path string) string {
|
||||
return path
|
||||
}
|
||||
|
||||
func getMockArtifactFiles(name string) ([]mockArtifactFile, bool) {
|
||||
files, ok := mockActionsArtifactFiles[name]
|
||||
return files, ok
|
||||
}
|
||||
|
||||
func chooseMockArtifactPath(files []mockArtifactFile, requestedPath string) string {
|
||||
if len(files) == 0 {
|
||||
return ""
|
||||
@ -305,7 +285,7 @@ func fillViewRunResponseCurrentJob(ctx *context.Context, resp *actions.ViewRespo
|
||||
|
||||
func MockActionsArtifactDownload(ctx *context.Context) {
|
||||
artifactName := ctx.PathParam("artifact_name")
|
||||
files, ok := getMockArtifactFiles(artifactName)
|
||||
files, ok := mockActionsArtifactFiles[artifactName]
|
||||
if !ok {
|
||||
ctx.NotFound(nil)
|
||||
return
|
||||
@ -330,7 +310,7 @@ func MockActionsArtifactDownload(ctx *context.Context) {
|
||||
func MockActionsArtifactPreview(ctx *context.Context) {
|
||||
runID := ctx.PathParamInt64("run")
|
||||
artifactName := ctx.PathParam("artifact_name")
|
||||
files, ok := getMockArtifactFiles(artifactName)
|
||||
files, ok := mockActionsArtifactFiles[artifactName]
|
||||
if !ok {
|
||||
ctx.NotFound(nil)
|
||||
return
|
||||
@ -341,40 +321,30 @@ func MockActionsArtifactPreview(ctx *context.Context) {
|
||||
selectedPath = normalizeMockArtifactPath(ctx.Req.URL.Query().Get("path"))
|
||||
}
|
||||
selectedPath = chooseMockArtifactPath(files, selectedPath)
|
||||
templateFiles := make([]mockArtifactPreviewTemplateFile, 0, len(files))
|
||||
previewFiles := make([]actions.ArtifactPreviewFile, 0, len(files))
|
||||
for _, file := range files {
|
||||
templateFiles = append(templateFiles, mockArtifactPreviewTemplateFile{
|
||||
previewFiles = append(previewFiles, actions.ArtifactPreviewFile{
|
||||
Path: file.Path,
|
||||
Selected: file.Path == selectedPath,
|
||||
})
|
||||
}
|
||||
|
||||
previewURL := fmt.Sprintf("%s/devtest/repo-action-view/runs/%d/artifacts/%s/preview", setting.AppSubURL, runID, url.PathEscape(artifactName))
|
||||
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,
|
||||
PreviewFiles: templateFiles,
|
||||
RunURL: previewURL,
|
||||
PreviewURL: previewURL,
|
||||
PreviewRawURL: previewRawURL,
|
||||
DownloadURL: downloadURL,
|
||||
SelectedPath: selectedPath,
|
||||
}
|
||||
runURL := fmt.Sprintf("%s/devtest/repo-action-view/runs/%d", setting.AppSubURL, runID)
|
||||
previewURL := runURL + "/artifacts/" + url.PathEscape(artifactName) + "/preview"
|
||||
|
||||
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.Data["ArtifactName"] = artifactName
|
||||
ctx.Data["PreviewFiles"] = previewFiles
|
||||
ctx.Data["RunURL"] = runURL
|
||||
ctx.Data["PreviewURL"] = previewURL
|
||||
ctx.Data["PreviewRawURL"] = previewURL + "/raw"
|
||||
ctx.Data["DownloadURL"] = runURL + "/artifacts/" + url.PathEscape(artifactName)
|
||||
ctx.Data["SelectedPath"] = selectedPath
|
||||
ctx.HTML(http.StatusOK, "devtest/repo-action-artifact-preview")
|
||||
}
|
||||
|
||||
func MockActionsArtifactPreviewRaw(ctx *context.Context) {
|
||||
artifactName := ctx.PathParam("artifact_name")
|
||||
files, ok := getMockArtifactFiles(artifactName)
|
||||
files, ok := mockActionsArtifactFiles[artifactName]
|
||||
if !ok {
|
||||
ctx.NotFound(nil)
|
||||
return
|
||||
|
||||
@ -861,7 +861,7 @@ func setArtifactPreviewCSP(ctx *context_module.Context, st typesniffer.SniffedTy
|
||||
func previewArtifactByReader(ctx *context_module.Context, path string, _ int64, reader io.Reader) {
|
||||
buf := filebuffer.New(int(setting.UI.MaxDisplayFileSize), "")
|
||||
defer buf.Close()
|
||||
if _, err := io.Copy(buf, reader); err != nil {
|
||||
if _, err := io.Copy(buf, io.LimitReader(reader, setting.UI.MaxDisplayFileSize)); err != nil {
|
||||
ctx.ServerError("io.Copy", err)
|
||||
return
|
||||
}
|
||||
@ -879,16 +879,12 @@ func previewArtifactByReadSeeker(ctx *context_module.Context, path string, reade
|
||||
ctx.ServerError("ReadAtMost", err)
|
||||
return
|
||||
}
|
||||
if n < 0 {
|
||||
n = 0
|
||||
}
|
||||
buf = buf[:n]
|
||||
|
||||
if _, err := reader.Seek(0, io.SeekStart); err != nil {
|
||||
ctx.ServerError("Seek", err)
|
||||
return
|
||||
}
|
||||
buf = buf[:n]
|
||||
|
||||
st := typesniffer.DetectContentType(buf)
|
||||
if !isPreviewableArtifactType(st) {
|
||||
|
||||
@ -5,24 +5,4 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.artifact-preview-page {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.artifact-preview-title {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.artifact-preview-subtitle {
|
||||
color: var(--color-text-light-3);
|
||||
}
|
||||
|
||||
.artifact-preview-frame {
|
||||
width: 100%;
|
||||
min-height: 70vh;
|
||||
border: 1px solid var(--color-secondary);
|
||||
border-radius: var(--border-radius);
|
||||
}
|
||||
</style>
|
||||
{{template "base/footer" .}}
|
||||
|
||||
@ -9,25 +9,4 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.artifact-preview-page {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.artifact-preview-title {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.artifact-preview-subtitle {
|
||||
color: var(--color-text-light-3);
|
||||
}
|
||||
|
||||
.artifact-preview-frame {
|
||||
width: 100%;
|
||||
min-height: 70vh;
|
||||
border: 1px solid var(--color-secondary);
|
||||
border-radius: var(--border-radius);
|
||||
}
|
||||
</style>
|
||||
|
||||
{{template "base/footer" .}}
|
||||
|
||||
@ -1,3 +1,24 @@
|
||||
<style>
|
||||
.artifact-preview-page {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.artifact-preview-title {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.artifact-preview-subtitle {
|
||||
color: var(--color-text-light-3);
|
||||
}
|
||||
|
||||
.artifact-preview-frame {
|
||||
width: 100%;
|
||||
min-height: 70vh;
|
||||
border: 1px solid var(--color-secondary);
|
||||
border-radius: var(--border-radius);
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="ui top attached header tw-flex tw-items-center tw-justify-between">
|
||||
<div class="artifact-preview-title">
|
||||
<span class="tw-text-base tw-font-semibold">{{ctx.Locale.Tr "preview"}}: <span class="gt-ellipsis">{{.ArtifactName}}</span></span>
|
||||
|
||||
@ -38,10 +38,6 @@ function artifactPreviewURL(name: string): string {
|
||||
return `${artifactBaseURL(name)}/preview`;
|
||||
}
|
||||
|
||||
function artifactDownloadURL(name: string): string {
|
||||
return artifactBaseURL(name);
|
||||
}
|
||||
|
||||
async function deleteArtifact(name: string) {
|
||||
if (!window.confirm(locale.confirmDeleteArtifact.replace('%s', name))) return;
|
||||
await DELETE(artifactBaseURL(name));
|
||||
@ -138,7 +134,7 @@ async function deleteArtifact(name: string) {
|
||||
<span class="gt-ellipsis">{{ artifact.name }}</span>
|
||||
</a>
|
||||
<span class="job-artifact-actions">
|
||||
<a download :href="artifactDownloadURL(artifact.name)" :data-tooltip-content="locale.downloadFile">
|
||||
<a download :href="artifactBaseURL(artifact.name)" :data-tooltip-content="locale.downloadFile">
|
||||
<SvgIcon name="octicon-download" class="tw-text-text"/>
|
||||
</a>
|
||||
<a v-if="run.canDeleteArtifact" @click="deleteArtifact(artifact.name)">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user