From c51ed903ea329ae42b25d4f6d7719e5b2cff46b7 Mon Sep 17 00:00:00 2001 From: George Harvey <11440490+HarvsG@users.noreply.github.com> Date: Thu, 26 Sep 2019 20:19:48 +0100 Subject: [PATCH 1/3] allow external rendering of other filetypes fixes #4996 and #7614 allows rendering of non-tex files, or otherwise accounted for filetypes --- routers/repo/view.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/routers/repo/view.go b/routers/repo/view.go index 00790a4ef35be..6700c5f47afba 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -342,7 +342,22 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st ctx.Data["IsAudioFile"] = true case base.IsImageFile(buf): ctx.Data["IsImageFile"] = true + default: + d, _ := ioutil.ReadAll(dataRc) + buf = append(buf, d...) + + if fileSize >= setting.UI.MaxDisplayFileSize { + ctx.Data["IsFileTooLarge"] = true + break + } + + if markupType := markup.Type(blob.Name()); markupType != "" { + ctx.Data["IsMarkup"] = true + ctx.Data["MarkupType"] = markupType + ctx.Data["FileContent"] = string(markup.Render(blob.Name(), buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas())) + } } + if ctx.Repo.CanEnableEditor() { ctx.Data["CanDeleteFile"] = true From 2e6bd5bf7bfec379c8401f0d2623060401f6e2d1 Mon Sep 17 00:00:00 2001 From: George Harvey <11440490+HarvsG@users.noreply.github.com> Date: Fri, 27 Sep 2019 14:08:45 +0100 Subject: [PATCH 2/3] Moves flie-size check before read() And performs gofmt -s --- routers/repo/view.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/routers/repo/view.go b/routers/repo/view.go index 6700c5f47afba..7fbf126fc0922 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -343,21 +343,21 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st case base.IsImageFile(buf): ctx.Data["IsImageFile"] = true default: - d, _ := ioutil.ReadAll(dataRc) - buf = append(buf, d...) - if fileSize >= setting.UI.MaxDisplayFileSize { ctx.Data["IsFileTooLarge"] = true break } + d, _ := ioutil.ReadAll(dataRc) + buf = append(buf, d...) + if markupType := markup.Type(blob.Name()); markupType != "" { ctx.Data["IsMarkup"] = true ctx.Data["MarkupType"] = markupType ctx.Data["FileContent"] = string(markup.Render(blob.Name(), buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas())) - } + } + } - if ctx.Repo.CanEnableEditor() { ctx.Data["CanDeleteFile"] = true From bdfa7d6a92ed76ff1c5c0ed3d2751a0ace35b7cf Mon Sep 17 00:00:00 2001 From: George Harvey <11440490+HarvsG@users.noreply.github.com> Date: Fri, 27 Sep 2019 15:47:10 +0100 Subject: [PATCH 3/3] Only reads if markType is detected --- routers/repo/view.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/routers/repo/view.go b/routers/repo/view.go index 7fbf126fc0922..047d2a03429e0 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -348,10 +348,9 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st break } - d, _ := ioutil.ReadAll(dataRc) - buf = append(buf, d...) - if markupType := markup.Type(blob.Name()); markupType != "" { + d, _ := ioutil.ReadAll(dataRc) + buf = append(buf, d...) ctx.Data["IsMarkup"] = true ctx.Data["MarkupType"] = markupType ctx.Data["FileContent"] = string(markup.Render(blob.Name(), buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas()))