增加索引页面

This commit is contained in:
dexter
2022-06-22 20:37:46 +08:00
parent ea770517a6
commit 8dd850d71d

View File

@@ -2,6 +2,7 @@ package preview
import (
"embed"
"fmt"
"mime"
"net/http"
"path/filepath"
@@ -23,6 +24,12 @@ func (p *PreviewConfig) OnEvent(event any) {
var plugin = InstallPlugin(&PreviewConfig{})
func (p *PreviewConfig) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/preview/" {
Streams.Range(func(s *Stream) {
w.Write([]byte(fmt.Sprintf("<a href='%s'>%s</a><br>", s.Path, s.Path)))
})
return
}
ss := strings.Split(r.URL.Path, "/")
if b, err := f.ReadFile("ui/" + ss[len(ss)-1]); err == nil {
w.Header().Set("Content-Type", mime.TypeByExtension(filepath.Ext(ss[len(ss)-1])))