mirror of
https://github.com/Monibuca/plugin-jessica.git
synced 2025-10-18 14:00:48 +08:00
适配3.0
This commit is contained in:
29
main.go
29
main.go
@@ -1,15 +1,11 @@
|
||||
package jessica
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"mime"
|
||||
"net/http"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
. "github.com/Monibuca/engine/v2"
|
||||
"github.com/Monibuca/utils"
|
||||
. "github.com/Monibuca/engine/v3"
|
||||
"github.com/Monibuca/utils/v3"
|
||||
. "github.com/logrusorgru/aurora"
|
||||
)
|
||||
|
||||
@@ -25,7 +21,6 @@ var publicPath string
|
||||
func init() {
|
||||
plugin := &PluginConfig{
|
||||
Name: "Jessica",
|
||||
Type: PLUGIN_SUBSCRIBER,
|
||||
Config: &config,
|
||||
Run: run,
|
||||
}
|
||||
@@ -33,25 +28,11 @@ func init() {
|
||||
publicPath = filepath.Join(plugin.Dir, "ui", "public")
|
||||
}
|
||||
func run() {
|
||||
http.HandleFunc("/jessibuca/", jessibuca)
|
||||
if config.ListenAddr != "" || config.ListenAddrTLS != "" {
|
||||
Print(Green("Jessica start at"), BrightBlue(config.ListenAddr), BrightBlue(config.ListenAddrTLS))
|
||||
utils.Print(Green("Jessica start at"), BrightBlue(config.ListenAddr), BrightBlue(config.ListenAddrTLS))
|
||||
utils.ListenAddrs(config.ListenAddr, config.ListenAddrTLS, config.CertFile, config.KeyFile, http.HandlerFunc(WsHandler))
|
||||
} else {
|
||||
Print(Green("Jessica start reuse gateway port"))
|
||||
utils.Print(Green("Jessica start reuse gateway port"))
|
||||
http.HandleFunc("/jessica/", WsHandler)
|
||||
}
|
||||
}
|
||||
func jessibuca(w http.ResponseWriter, r *http.Request) {
|
||||
filePath := strings.TrimPrefix(r.URL.Path, "/jessibuca")
|
||||
if mime := mime.TypeByExtension(path.Ext(filePath)); mime != "" {
|
||||
w.Header().Set("Content-Type", mime)
|
||||
}
|
||||
if f, err := ioutil.ReadFile(filepath.Join(publicPath, filePath)); err == nil {
|
||||
if _, err = w.Write(f); err != nil {
|
||||
w.WriteHeader(500)
|
||||
}
|
||||
} else {
|
||||
w.WriteHeader(404)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user