feat(filehole): serve indexes from applet dir

This commit is contained in:
hgc 2023-05-30 04:41:20 +00:00
rodič 4ee3d438cb
revize 9c41526bc6
2 změnil soubory, kde provedl 16 přidání a 6 odebrání

1
.gitignore vendorováno
Zobrazit soubor

@ -1,3 +1,4 @@
/filehole.db
/filehole
/data/
/applet/

21
main.go
Zobrazit soubor

@ -1,8 +1,10 @@
package main
import (
"io/fs"
"path"
"crypto/rand"
_ "embed"
"embed"
"html"
"io"
"net/http"
@ -141,8 +143,17 @@ func ExpiryDoer() {
}
}
//go:embed index.html
var indexPage []byte
//go:embed applet/**
var indexApplet embed.FS
// myFS implements fs.FS
type myFS struct {
content embed.FS
}
func (c myFS) Open(name string) (fs.File, error) {
return c.content.Open(path.Join("applet", name))
}
func main() {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
@ -209,9 +220,7 @@ func main() {
// Serve files from data dir statically
r.PathPrefix("/u/").Handler(http.StripPrefix("/u/", NoDirectoryList(http.FileServer(http.Dir(viper.GetString("filedir"))))))
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write(indexPage)
}).Methods("GET")
r.PathPrefix("/").Handler(http.FileServer(http.FS(myFS{indexApplet}))).Methods("GET")
r.HandleFunc("/", UploadHandler).Methods("POST")
http.Handle("/", r)