feat(filehole): serve indexes from applet dir
This commit is contained in:
rodič
4ee3d438cb
revize
9c41526bc6
|
@ -1,3 +1,4 @@
|
|||
/filehole.db
|
||||
/filehole
|
||||
/data/
|
||||
/applet/
|
||||
|
|
21
main.go
21
main.go
|
@ -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)
|
||||
|
|
Načítá se…
Odkázat v novém úkolu