summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-03-27 14:14:34 +0100
committerEarl Warren <contact@earl-warren.org>2024-03-30 07:17:31 +0100
commit94515b0db06288df035a22a90831aafd222054bc (patch)
treef1a326ced78fb440673fcb1b081de3ae4b207d04 /routers
parentFix: Organization Interface Display Issue (#30133) (diff)
downloadforgejo-94515b0db06288df035a22a90831aafd222054bc.tar.xz
forgejo-94515b0db06288df035a22a90831aafd222054bc.zip
Refactor render (#30136)
(cherry picked from commit f1707f4562158853552d57394b8b1fea6df645b0)
Diffstat (limited to 'routers')
-rw-r--r--routers/web/repo/render.go15
1 files changed, 7 insertions, 8 deletions
diff --git a/routers/web/repo/render.go b/routers/web/repo/render.go
index 10fa21c60e..e64db03e20 100644
--- a/routers/web/repo/render.go
+++ b/routers/web/repo/render.go
@@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/modules/charset"
"code.gitea.io/gitea/modules/git"
+ "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markup"
"code.gitea.io/gitea/modules/typesniffer"
"code.gitea.io/gitea/modules/util"
@@ -44,20 +45,17 @@ func RenderFile(ctx *context.Context) {
isTextFile := st.IsText()
rd := charset.ToUTF8WithFallbackReader(io.MultiReader(bytes.NewReader(buf), dataRc), charset.ConvertOpts{})
+ ctx.Resp.Header().Add("Content-Security-Policy", "frame-src 'self'; sandbox allow-scripts")
if markupType := markup.Type(blob.Name()); markupType == "" {
if isTextFile {
- _, err = io.Copy(ctx.Resp, rd)
- if err != nil {
- ctx.ServerError("Copy", err)
- }
- return
+ _, _ = io.Copy(ctx.Resp, rd)
+ } else {
+ http.Error(ctx.Resp, "Unsupported file type render", http.StatusInternalServerError)
}
- ctx.Error(http.StatusInternalServerError, "Unsupported file type render")
return
}
- ctx.Resp.Header().Add("Content-Security-Policy", "frame-src 'self'; sandbox allow-scripts")
err = markup.Render(&markup.RenderContext{
Ctx: ctx,
RelativePath: ctx.Repo.TreePath,
@@ -71,7 +69,8 @@ func RenderFile(ctx *context.Context) {
InStandalonePage: true,
}, rd, ctx.Resp)
if err != nil {
- ctx.ServerError("Render", err)
+ log.Error("Failed to render file %q: %v", ctx.Repo.TreePath, err)
+ http.Error(ctx.Resp, "Failed to render file", http.StatusInternalServerError)
return
}
}