dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit b36f3a06838f2e6353d524d7fe3e540a4341ef48
parent 25fd3c06b1580fe9f0152f93263136d8117fd6f8
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Tue, 31 Jan 2023 14:41:52 -0800

404 page for uploads

Diffstat:
Mpkg/web/handlers/handlers.go | 10+++++-----
Apkg/web/public/views/pages/standalone/upload404.gohtml | 22++++++++++++++++++++++
2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go @@ -3963,17 +3963,17 @@ func UploadsDownloadHandler(c echo.Context) error { filename := c.Param("filename") file, err := database.GetUploadByFileName(filename) if err != nil { - return c.Redirect(http.StatusFound, "/") + return c.Render(http.StatusOK, "standalone.upload404", nil) } if !file.Exists() { logrus.Error(filename + " does not exists") - return c.Redirect(http.StatusFound, "/") + return c.Render(http.StatusOK, "standalone.upload404", nil) } if file.FileSize < config.MaxFileSizeBeforeDownload { fi, decFileBytes, err := file.GetContent() if err != nil || fi.IsDir() { - return echo.NotFoundHandler(c) + return c.Render(http.StatusOK, "standalone.upload404", nil) } buf := bytes.NewReader(decFileBytes) @@ -3981,7 +3981,7 @@ func UploadsDownloadHandler(c echo.Context) error { mimeType, err := GetFileContentType(buf) _, err = buf.Seek(0, io.SeekStart) if err != nil { - return echo.NotFoundHandler(c) + return c.Render(http.StatusOK, "standalone.upload404", nil) } // Serve images @@ -4042,7 +4042,7 @@ func UploadsDownloadHandler(c echo.Context) error { fi, decFileBytes, err := file.GetContent() if err != nil { - return echo.NotFoundHandler(c) + return c.Render(http.StatusOK, "standalone.upload404", nil) } buf := bytes.NewReader(decFileBytes) diff --git a/pkg/web/public/views/pages/standalone/upload404.gohtml b/pkg/web/public/views/pages/standalone/upload404.gohtml @@ -0,0 +1,21 @@ +{{ define "content" }} + <div id="parent"> + <div class="container" id="form_login"> + <div class="row"> + <div class="col-8 offset-2 col-md-8 offset-md-2 col-sm-8 col-lg-6 offset-lg-3 col-xl-4 offset-xl-4"> + <div class="card" style="background-color: rgba(0, 0, 0, 0.7);"> + <div class="card-header" style="background-color: rgba(50, 50, 50, 0.7); color: #ccc;"> + <strong>{{ t "Upload file not found" . }}</strong> + </div> + <div class="card-body"> + <p> + This file no longer exists.<br /> + Uploaded files are automatically deleted after 24h. + </p> + </div> + </div> + </div> + </div> + </div> + </div> +{{ end }} +\ No newline at end of file