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) + } +}