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