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

@ -100,7 +100,7 @@ func Page(stuff string) string {
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"> <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<style> <style>
html { background: #f4f4f4; color: #455164; font-size: 16px; font-family: -apple-system,system-ui,BlinkMacSystemFont,Roboto,"Helvetica Neue",Arial,sans-serif; } html { background: #f4f4f4; color: #455164; font-size: 16px; font-family: -apple-system,system-ui,BlinkMacSystemFont,Roboto,"Helvetica Neue",Arial,sans-serif; }
body { text-align: center; padding-top: 50px; text-align: center; } body { text-align: center; padding-top: 50px; text-align: center; margin: 0; }
h1 { font-weight: 200; line-height: 1em; font-size: 40px; } h1 { font-weight: 200; line-height: 1em; font-size: 40px; }
p { opacity: 0.8; font-size: 1.05em; } p { opacity: 0.8; font-size: 1.05em; }
</style> </style>

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