@@ -7,6 +7,43 @@ import { get, post } from '../request'
77import { API_PATHS , MODULE_ACTIONS , PAGINATION } from '../config'
88import axios from 'axios'
99
10+ /**
11+ * 解析headers字段,支持对象和JSON字符串格式
12+ * @param {Object|string } headers - headers字段
13+ * @returns {Object } 解析后的headers对象
14+ */
15+ const parseHeaders = ( headers ) => {
16+ if ( ! headers ) {
17+ console . log ( '🔍 [Headers解析] 输入为空,返回空对象' )
18+ return { }
19+ }
20+
21+ console . log ( '🔍 [Headers解析] 输入数据:' , headers , '类型:' , typeof headers )
22+
23+ // 如果已经是对象,直接返回
24+ if ( typeof headers === 'object' && headers !== null ) {
25+ console . log ( '🔍 [Headers解析] 已是对象,直接返回:' , headers )
26+ return headers
27+ }
28+
29+ // 如果是字符串,尝试解析为JSON
30+ if ( typeof headers === 'string' ) {
31+ try {
32+ const parsed = JSON . parse ( headers )
33+ // 确保解析结果是对象
34+ const result = typeof parsed === 'object' && parsed !== null ? parsed : { }
35+ console . log ( '🔍 [Headers解析] JSON字符串解析成功:' , result )
36+ return result
37+ } catch ( error ) {
38+ console . warn ( '🔍 [Headers解析] JSON字符串解析失败:' , error , '原始数据:' , headers )
39+ return { }
40+ }
41+ }
42+
43+ console . log ( '🔍 [Headers解析] 未知类型,返回空对象' )
44+ return { }
45+ }
46+
1047/**
1148 * 处理extend参数,确保对象类型转换为JSON字符串
1249 * @param {string|object } extend - 扩展参数
@@ -222,13 +259,20 @@ export const parsePlayUrl = async (module, params) => {
222259 const playData = await getPlayData ( module , params )
223260 console . log ( 'T4播放解析响应:' , playData )
224261
262+ // 调试:显示原始headers数据
263+ const rawHeaders = playData ?. headers || playData ?. header
264+ if ( rawHeaders ) {
265+ console . log ( 'T4接口返回的原始headers:' , rawHeaders , '类型:' , typeof rawHeaders )
266+ }
267+
225268 // 处理解析结果
226269 const result = {
227270 success : true ,
228271 data : playData ,
229272 // 解析播放类型
230273 playType : 'direct' , // 默认直链
231274 url : '' ,
275+ headers : { } , // 添加headers字段
232276 needParse : false ,
233277 needSniff : false ,
234278 message : ''
@@ -241,29 +285,34 @@ export const parsePlayUrl = async (module, params) => {
241285 // 直链播放
242286 result . playType = 'direct'
243287 result . url = playData . url || playData . play_url || ''
288+ result . headers = parseHeaders ( playData . headers || playData . header )
244289 result . needParse = false
245290 result . needSniff = false
246291 result . message = '直链播放'
247292 } else if ( playData . parse === 1 ) {
248293 // 需要嗅探
249294 result . playType = 'sniff'
250295 result . url = playData . url || playData . play_url || ''
296+ result . headers = parseHeaders ( playData . headers || playData . header )
251297 result . needSniff = true
252298 result . message = '需要嗅探才能播放,尽情期待'
253299 } else if ( playData . jx === 1 ) {
254300 // 需要解析
255301 result . playType = 'parse'
256302 result . url = playData . url || playData . play_url || ''
303+ result . headers = parseHeaders ( playData . headers || playData . header )
257304 result . needParse = true
258305 result . message = '需要解析才能播放,尽情期待'
259306 } else {
260307 // 默认处理为直链
261308 result . url = playData . url || playData . play_url || playData
309+ result . headers = parseHeaders ( playData . headers || playData . header )
262310 result . message = '直链播放'
263311 }
264312 } else if ( typeof playData === 'string' ) {
265313 // 如果返回的是字符串,直接作为播放地址
266314 result . url = playData
315+ result . headers = { }
267316 result . message = '直链播放'
268317 }
269318
@@ -275,6 +324,7 @@ export const parsePlayUrl = async (module, params) => {
275324 error : error . message || '播放解析失败' ,
276325 playType : 'error' ,
277326 url : '' ,
327+ headers : { } ,
278328 needParse : false ,
279329 needSniff : false ,
280330 message : '播放解析失败: ' + ( error . message || '未知错误' )
0 commit comments