mirror of
https://github.com/Monibuca/plugin-preview.git
synced 2025-12-24 13:38:02 +08:00
增加索引页面
This commit is contained in:
7
main.go
7
main.go
@@ -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])))
|
||||
|
||||
Reference in New Issue
Block a user