2023-09-11 17:09:08 +00:00
|
|
|
/*
|
2024-01-14 18:39:14 +00:00
|
|
|
Copyright © 2024 Seednode <seednode@seedno.de>
|
2023-09-11 17:09:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"embed"
|
2024-01-30 19:07:59 +00:00
|
|
|
"fmt"
|
2023-09-11 17:09:08 +00:00
|
|
|
"net/http"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/julienschmidt/httprouter"
|
|
|
|
)
|
|
|
|
|
|
|
|
//go:embed favicons/*
|
|
|
|
var favicons embed.FS
|
|
|
|
|
2024-01-30 19:07:59 +00:00
|
|
|
func getFavicon(nonce string) string {
|
|
|
|
return fmt.Sprintf(`<link rel="apple-touch-icon" sizes="180x180" href="/favicons/apple-touch-icon.png">
|
2023-09-11 17:09:08 +00:00
|
|
|
<link rel="icon" type="image/png" sizes="32x32" href="/favicons/favicon-32x32.png">
|
|
|
|
<link rel="icon" type="image/png" sizes="16x16" href="/favicons/favicon-16x16.png">
|
2024-01-30 19:07:59 +00:00
|
|
|
<link rel="manifest" nonce=%q href="/favicons/site.webmanifest">
|
2023-09-11 17:09:08 +00:00
|
|
|
<link rel="mask-icon" href="/favicons/safari-pinned-tab.svg" color="#5bbad5">
|
|
|
|
<meta name="msapplication-TileColor" content="#da532c">
|
2024-01-30 19:07:59 +00:00
|
|
|
<meta name="theme-color" content="#ffffff">`, nonce)
|
|
|
|
}
|
2023-09-11 17:09:08 +00:00
|
|
|
|
2024-01-08 04:43:51 +00:00
|
|
|
func serveFavicons(errorChannel chan<- error) httprouter.Handle {
|
2023-09-11 17:09:08 +00:00
|
|
|
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
|
|
|
fname := strings.TrimPrefix(r.URL.Path, "/")
|
|
|
|
|
|
|
|
data, err := favicons.ReadFile(fname)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-01-15 14:51:41 +00:00
|
|
|
w.Header().Set("Content-Length", strconv.Itoa(len(data)))
|
2023-09-11 17:09:08 +00:00
|
|
|
|
2024-01-08 04:43:51 +00:00
|
|
|
_, err = w.Write(data)
|
|
|
|
if err != nil {
|
|
|
|
errorChannel <- err
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
2023-09-11 17:09:08 +00:00
|
|
|
}
|
|
|
|
}
|