mirror of
https://github.com/Monibuca/plugin-record.git
synced 2025-10-07 01:33:14 +08:00
增加点播读取flv文件功能
This commit is contained in:
1
main.go
1
main.go
@@ -40,6 +40,7 @@ func init() {
|
|||||||
func run() {
|
func run() {
|
||||||
go AddHook(HOOK_PUBLISH, onPublish)
|
go AddHook(HOOK_PUBLISH, onPublish)
|
||||||
os.MkdirAll(config.Path, 0755)
|
os.MkdirAll(config.Path, 0755)
|
||||||
|
http.HandleFunc("/vod/", VodHandler)
|
||||||
http.HandleFunc("/api/record/flv/list", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/api/record/flv/list", func(w http.ResponseWriter, r *http.Request) {
|
||||||
CORS(w, r)
|
CORS(w, r)
|
||||||
if files, err := tree(config.Path, 0); err == nil {
|
if files, err := tree(config.Path, 0); err == nil {
|
||||||
|
20
vod.go
Normal file
20
vod.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package record
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
func VodHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
streamPath := r.RequestURI[5:]
|
||||||
|
filePath := filepath.Join(config.Path, streamPath)
|
||||||
|
if file, err := os.Open(filePath); err == nil {
|
||||||
|
w.Header().Set("Transfer-Encoding", "chunked")
|
||||||
|
w.Header().Set("Content-Type", "video/x-flv")
|
||||||
|
io.Copy(w, file)
|
||||||
|
} else {
|
||||||
|
w.WriteHeader(404)
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user