improve (404): SVG artwork from pixeltrue.com

This commit is contained in:
Mickael Kerjean
2020-08-05 11:48:25 +10:00
parent 8fcb721c13
commit f2fa1f489e
2 changed files with 10 additions and 7 deletions

View File

@ -28,8 +28,7 @@ func IndexHandler(_path string) func(App, http.ResponseWriter, *http.Request) {
return func(ctx App, res http.ResponseWriter, req *http.Request) {
urlObj, err := URL.Parse(req.URL.String())
if err != nil {
res.WriteHeader(http.StatusInternalServerError)
res.Write([]byte(Page("<h1>404 - Not Found</h1>")))
NotFoundHandler(ctx, res, req)
return
}
url := urlObj.Path
@ -40,15 +39,14 @@ func IndexHandler(_path string) func(App, http.ResponseWriter, *http.Request) {
} else if url != "/" && strings.HasPrefix(url, "/s/") == false &&
strings.HasPrefix(url, "/view/") == false && strings.HasPrefix(url, "/files/") == false &&
url != "/login" && url != "/logout" && strings.HasPrefix(url, "/admin") == false {
res.WriteHeader(http.StatusNotFound)
res.Write([]byte(Page("<h1>404 - Not Found</h1>")))
NotFoundHandler(ctx, res, req)
return
}
ua := req.Header.Get("User-Agent");
if strings.Contains(ua, "MSIE ") || strings.Contains(ua, "Edge/"){
// Microsoft is behaving on many occasion differently than Firefox / Chrome.
// I have neither the time / motivation for it to work properly
res.WriteHeader(http.StatusBadRequest)
res.WriteHeader(http.StatusBadRequest)
res.Write([]byte(
Page(`
<h1>Internet explorer is not supported</h1>
@ -65,6 +63,11 @@ func IndexHandler(_path string) func(App, http.ResponseWriter, *http.Request) {
}
}
func NotFoundHandler(ctx App, res http.ResponseWriter, req *http.Request) {
res.WriteHeader(http.StatusNotFound)
res.Write([]byte(Page(`<img style="max-width:800px" src="/assets/icons/404.svg" />`)))
}
func AboutHandler(ctx App, res http.ResponseWriter, req *http.Request) {
t, _ := template.New("about").Parse(Page(`
<h1> {{index .App 0}} </h1>
@ -158,6 +161,6 @@ func hashFileContent(path string, n int) string {
if err != nil {
return ""
}
defer f.Close()
defer f.Close()
return HashStream(f, n)
}