]> source.dussan.org Git - gitea.git/commitdiff
Allows external rendering of other filetypes 2 (#8300)
authorGeorge Harvey <11440490+HarvsG@users.noreply.github.com>
Mon, 21 Oct 2019 06:54:18 +0000 (07:54 +0100)
committerzeripath <art27@cantab.net>
Mon, 21 Oct 2019 06:54:18 +0000 (07:54 +0100)
* allow external rendering of other filetypes

fixes #4996 and #7614
allows rendering of non-tex files, or otherwise accounted for filetypes

* Moves flie-size check before read()

And performs gofmt -s

* Only reads if markType is detected

routers/repo/view.go

index c4e6a69220aaaf6ffb82a13305c67376c66ee75f..a2e431e43597b5cac408f22d569f6ea528ab5707 100644 (file)
@@ -346,6 +346,20 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
                ctx.Data["IsAudioFile"] = true
        case base.IsImageFile(buf):
                ctx.Data["IsImageFile"] = true
+       default:
+               if fileSize >= setting.UI.MaxDisplayFileSize {
+                       ctx.Data["IsFileTooLarge"] = true
+                       break
+               }
+
+               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()))
+               }
+
        }
 
        if ctx.Repo.CanEnableEditor() {