Fixed favicon

This commit is contained in:
Pablu23
2024-02-26 19:17:17 +01:00
parent 8c5be57459
commit 87ec7aa1a8
5 changed files with 13 additions and 16 deletions

View File

@@ -72,6 +72,7 @@ func main() {
http.HandleFunc("POST /prev", s.HandlePrev) http.HandleFunc("POST /prev", s.HandlePrev)
http.HandleFunc("POST /exit", s.HandleExit) http.HandleFunc("POST /exit", s.HandleExit)
http.HandleFunc("POST /delete", s.HandleDelete) http.HandleFunc("POST /delete", s.HandleDelete)
http.HandleFunc("/favicon.ico", s.HandleFavicon)
go func() { go func() {
time.Sleep(300 * time.Millisecond) time.Sleep(300 * time.Millisecond)

View File

@@ -3,6 +3,7 @@ package server
import ( import (
"bytes" "bytes"
"cmp" "cmp"
_ "embed"
"fmt" "fmt"
"golang.org/x/text/cases" "golang.org/x/text/cases"
"golang.org/x/text/language" "golang.org/x/text/language"
@@ -198,6 +199,17 @@ func (s *Server) HandleImage(w http.ResponseWriter, r *http.Request) {
} }
} }
//go:embed favicon.ico
var ico []byte
func (s *Server) HandleFavicon(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "image/webp")
_, err := w.Write(ico)
if err != nil {
fmt.Println(err)
}
}
func (s *Server) HandleNext(w http.ResponseWriter, r *http.Request) { func (s *Server) HandleNext(w http.ResponseWriter, r *http.Request) {
fmt.Println("Received Next") fmt.Println("Received Next")

View File

@@ -43,8 +43,6 @@ func New(provider provider.Provider, db *database.Manager) *Server {
Mutex: &sync.Mutex{}, Mutex: &sync.Mutex{},
} }
s.AddIco()
return &s return &s
} }
@@ -209,16 +207,6 @@ func (s *Server) AppendImagesToBuf(html string) ([]view.Image, error) {
return images, nil return images, nil
} }
//go:embed favicon.ico
var ico []byte
func (s *Server) AddIco() {
buf := bytes.NewBuffer(ico)
s.Mutex.Lock()
s.ImageBuffers["favicon.ico"] = buf
s.Mutex.Unlock()
}
func addFileToRam(url string) (*bytes.Buffer, error) { func addFileToRam(url string) (*bytes.Buffer, error) {
// Get the data // Get the data
resp, err := http.Get(url) resp, err := http.Get(url)

View File

@@ -4,8 +4,6 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Main Menu</title> <title>Main Menu</title>
<link href="/img/favicon.ico" rel="icon" type="image/x-icon">
<style> <style>
body { body {
padding: 25px; padding: 25px;

View File

@@ -4,8 +4,6 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>{{.Title}}</title> <title>{{.Title}}</title>
<link href="/img/favicon.ico" rel="icon" type="image/x-icon">
<style> <style>
body {background-color: #171717} body {background-color: #171717}