From ead7f0ac39c84910cfe7ae052106a25e4e669d6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AE=87=E7=BF=94?= <11123448@vivo.xyz> Date: Thu, 24 Jun 2021 15:44:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=82=B9=E6=92=AD=E8=AF=BB?= =?UTF-8?q?=E5=8F=96flv=E6=96=87=E4=BB=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 1 + vod.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 vod.go diff --git a/main.go b/main.go index 9f4fb3d..05b36ba 100644 --- a/main.go +++ b/main.go @@ -40,6 +40,7 @@ func init() { func run() { go AddHook(HOOK_PUBLISH, onPublish) os.MkdirAll(config.Path, 0755) + http.HandleFunc("/vod/", VodHandler) http.HandleFunc("/api/record/flv/list", func(w http.ResponseWriter, r *http.Request) { CORS(w, r) if files, err := tree(config.Path, 0); err == nil { diff --git a/vod.go b/vod.go new file mode 100644 index 0000000..ba9b880 --- /dev/null +++ b/vod.go @@ -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) + } +}