@@ -13,15 +13,34 @@ function sign() {
1313 if ( authUrlVal && authHeaderVal ) {
1414 const url = { url : authUrlVal , headers : JSON . parse ( authHeaderVal ) }
1515 chavy . get ( url , ( error , response , data ) => {
16- chavy . log ( `${ cookieName } , auth_refresh - data: ${ data } ` )
17- chavy . log ( `${ cookieName } , auth_refresh - oldCookie: ${ cookieVal } ` )
18- let result = JSON . parse ( data . match ( / \( ( [ ^ \) ] * ) \) / ) [ 1 ] )
16+ // chavy.log(`${cookieName}, auth_refresh - data: ${data}`)
17+ // chavy.log(`${cookieName}, auth_refresh - old-cookie: ${cookieVal}`)
18+ // chavy.log(`${cookieName}, auth_refresh - set-cookie: ${response.headers['Set-Cookie']}`)
19+ const result = JSON . parse ( data . match ( / \( ( [ ^ \) ] * ) \) / ) [ 1 ] )
20+ let respcookie = response . headers [ 'Set-Cookie' ]
21+ // chavy.log(`${cookieName}, auth_refresh - Expires: ${respcookie.indexOf('Expires=') >= 0 ? respcookie.match(/Expires=(.*?)GMT/)[1] : '无'}`)
22+ respcookie = respcookie . replace ( / E x p i r e s = ( .* ?) G M T , ? ? / g, '' )
23+ respcookie = respcookie . replace ( / P a t h = ( .* ?) ; ? / g, '' )
24+ respcookie = respcookie . replace ( / D o m a i n = ( .* ?) ; ? / g, '' )
25+ respcookie = respcookie . replace ( / ; $ / g, '' )
1926 if ( result . errcode == 0 ) {
20- if ( result . vuserid ) cookieVal = cookieVal . replace ( / v u s e r i d = [ ^ ; ] * / , `vuserid=${ result . vuserid } ` )
21- if ( result . vusession ) cookieVal = cookieVal . replace ( / v u s e s s i o n = [ ^ ; ] * / , `vusession=${ result . vusession } ` )
22- if ( result . next_refresh_time ) cookieVal = cookieVal . replace ( / n e x t _ r e f r e s h _ t i m e = [ ^ ; ] * / , `next_refresh_time=${ result . next_refresh_time } ` )
23- if ( result . access_token ) cookieVal = cookieVal . replace ( / a c c e s s _ t o k e n = [ ^ ; ] * / , `access_token=${ result . access_token } ` )
24- chavy . log ( `${ cookieName } , auth_refresh - newCookie: ${ cookieVal } ` )
27+ for ( setcookie of respcookie . split ( ';' ) ) {
28+ const setcookieKey = setcookie . split ( '=' ) [ 0 ]
29+ const setcookieVal = setcookie . split ( '=' ) [ 1 ]
30+ if ( setcookieKey && cookieVal . indexOf ( setcookieKey ) >= 0 ) {
31+ cookieVal = cookieVal . replace ( new RegExp ( `${ setcookieKey } =[^;]*` ) , `${ setcookieKey } =${ setcookieVal } ` )
32+ } else {
33+ cookieVal += `; ${ setcookieKey } =${ setcookieVal } `
34+ }
35+ // chavy.log(`${cookieName}, auth_refresh - set-cookie: ${setcookieKey} = ${setcookieVal}`)
36+ }
37+ for ( resultcookie in result ) {
38+ if ( cookieVal . indexOf ( resultcookie ) >= 0 ) {
39+ cookieVal = cookieVal . replace ( new RegExp ( `${ resultcookie } =[^;]*` , 'g' ) , `${ resultcookie } =${ result [ resultcookie ] } ` )
40+ // chavy.log(`${cookieName}, auth_refresh - ret-cookie: ${resultcookie} = ${result[resultcookie]}`)
41+ }
42+ }
43+ // chavy.log(`${cookieName}, auth_refresh - new-cookie: ${cookieVal}`)
2544 chavy . setdata ( cookieVal , cookieKey )
2645 signapp ( )
2746 }
@@ -31,6 +50,8 @@ function sign() {
3150 }
3251}
3352
53+ function refreshSetCookie ( ) { }
54+
3455function signapp ( ) {
3556 const timestamp = Math . round ( new Date ( ) . getTime ( ) / 1000 ) . toString ( )
3657 let url = { url : `https://vip.video.qq.com/fcgi-bin/comm_cgi?name=hierarchical_task_system&cmd=2&_=${ timestamp } ` , headers : { Cookie : cookieVal } }
@@ -107,7 +128,7 @@ function init() {
107128 }
108129 if ( isQuanX ( ) ) {
109130 url . method = 'GET'
110- $task . fetch ( url ) . then ( ( resp ) => cb ( null , { } , resp . body ) )
131+ $task . fetch ( url ) . then ( ( resp ) => cb ( null , resp , resp . body ) )
111132 }
112133 }
113134 post = ( url , cb ) => {
@@ -116,7 +137,7 @@ function init() {
116137 }
117138 if ( isQuanX ( ) ) {
118139 url . method = 'POST'
119- $task . fetch ( url ) . then ( ( resp ) => cb ( null , { } , resp . body ) )
140+ $task . fetch ( url ) . then ( ( resp ) => cb ( null , resp , resp . body ) )
120141 }
121142 }
122143 done = ( value = { } ) => {
0 commit comments