This commit is contained in:
2023-10-25 04:31:18 +08:00
parent 9af1e9d609
commit e8f0bc4ca0
2 changed files with 27 additions and 28 deletions

View File

@@ -4,8 +4,8 @@ import (
"context"
"fmt"
"log"
"net/url"
"net/http"
"net/url"
"runtime"
"strings"
"time"
@@ -603,7 +603,7 @@ func main() {
})
// 获取转换后的m3u8视频链接
http.HandleFunc("/video/", func(w http.ResponseWriter, r *http.Request) {
http.HandleFunc("/video", func(w http.ResponseWriter, r *http.Request) {
defer LogComponent(time.Now().UnixNano(), r) // 最后打印日志
queryParam := r.URL.Query().Get("url")
@@ -615,18 +615,15 @@ func main() {
}
fmt.Println("safeParam", safeParam)
urls := models.GetVideoM3U8(safeParam)
// 将对象转换为有缩进的JSON输出
json, err := json.MarshalIndent(&struct{Urls string `json:"urls"`}{
Urls: urls,
}, "", " ")
urls, err := models.GetVideoM3U8(safeParam)
if err != nil {
log.Println(err)
log.Println("获取视频链接失败", err)
w.WriteHeader(http.StatusBadRequest)
return
}
// 输出JSON
// 将对象转换为有缩进的JSON输出
json, _ := json.MarshalIndent(urls, "", " ")
w.Header().Set("Content-Type", "application/json")
w.Write(json)
})