Add 404 page
This commit is contained in:
parent
6eee86d682
commit
d05f7f868d
|
@ -32,6 +32,11 @@ func handleMedia(c *fiber.Ctx, url string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if res.StatusCode == 404 {
|
||||
c.Status(404)
|
||||
return c.Render("errors/404", nil)
|
||||
}
|
||||
|
||||
c.Set("Content-Type", res.Header.Get("Content-Type"));
|
||||
contentLen, _ := strconv.Atoi(res.Header.Get("Content-Length"))
|
||||
return c.SendStream(res.Body, contentLen)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package pages
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"codeberg.org/video-prize-ranch/rimgo/api"
|
||||
|
@ -18,14 +17,14 @@ func HandlePost(c *fiber.Ctx) error {
|
|||
switch {
|
||||
case strings.HasPrefix(c.Path(), "/a"):
|
||||
post, err = api.FetchAlbum(c.Params("postID"))
|
||||
println(post.Title)
|
||||
case strings.HasPrefix(c.Path(), "/gallery"):
|
||||
post, err = api.FetchPosts(c.Params("postID"))
|
||||
default:
|
||||
post, err = api.FetchMedia(c.Params("postID"))
|
||||
}
|
||||
if post.Id == "" || strings.Contains(err.Error(), "404") {
|
||||
return fmt.Errorf("404 page not found")
|
||||
if post.Id == "" || (err != nil && strings.Contains(err.Error(), "404")) {
|
||||
c.Status(404)
|
||||
return c.Render("errors/404", nil)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -32,6 +32,10 @@ func HandleTag(c *fiber.Ctx) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if tag.Display == "" {
|
||||
c.Status(404)
|
||||
return c.Render("errors/404", nil)
|
||||
}
|
||||
|
||||
return c.Render("tag", fiber.Map{
|
||||
"tag": tag,
|
||||
|
|
|
@ -46,6 +46,11 @@ func HandleUser(c *fiber.Ctx) error {
|
|||
}
|
||||
|
||||
wg.Wait()
|
||||
if user.Username == "" {
|
||||
c.Status(404)
|
||||
return c.Render("errors/404", nil)
|
||||
}
|
||||
|
||||
return c.Render("user", fiber.Map{
|
||||
"user": user,
|
||||
"submissions": submissions,
|
||||
|
|
|
@ -37,6 +37,10 @@ main {
|
|||
margin: 0 24vw;
|
||||
}
|
||||
|
||||
.errorTitle {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.posts {
|
||||
margin-top: 1em;
|
||||
display: grid;
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
{{> 'partials/head' }}
|
||||
|
||||
<title>404 - rimgo</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{{> 'partials/header' }}
|
||||
|
||||
<main>
|
||||
<h2 class="errorTitle">404 Not Found</h2>
|
||||
<p class="errorTitle">Click <a href="/">here</a> to return to home.</p>
|
||||
</main>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in New Issue