fix: recognize qdreader uid from response body
This commit is contained in:
+22
-3
@@ -25,21 +25,40 @@ function parseCookie(cookie) {
|
||||
return jar
|
||||
}
|
||||
function b64decode(s) {
|
||||
try { return decodeURIComponent(escape(atob(String(s || '')))) } catch (e) { return '' }
|
||||
let raw = String(s || '').trim()
|
||||
try { raw = decodeURIComponent(raw) } catch (e) {}
|
||||
raw = raw.replace(/-/g, '+').replace(/_/g, '/')
|
||||
while (raw.length % 4) raw += '='
|
||||
try { return decodeURIComponent(escape(atob(raw))) } catch (e) { return '' }
|
||||
}
|
||||
function uidFromQDHeader(qdheader) {
|
||||
const decoded = b64decode(qdheader)
|
||||
return decoded ? String(decoded.split('|')[0] || '').trim() : ''
|
||||
}
|
||||
function parseJson(s, def) { try { return JSON.parse(s) } catch (e) { return def } }
|
||||
function findUid(obj) {
|
||||
if (!obj || typeof obj !== 'object') return ''
|
||||
const keys = ['UserId', 'userId', 'UserID', 'userid', 'uid', 'UID']
|
||||
for (const key of keys) {
|
||||
const val = obj[key]
|
||||
if (val !== undefined && val !== null && String(val).trim()) return String(val).trim()
|
||||
}
|
||||
for (const key in obj) {
|
||||
const val = obj[key]
|
||||
if (val && typeof val === 'object') {
|
||||
const found = findUid(val)
|
||||
if (found) return found
|
||||
}
|
||||
}
|
||||
return ''
|
||||
}
|
||||
function getUid(cookie, body) {
|
||||
const jar = parseCookie(cookie)
|
||||
let uid = uidFromQDHeader(jar.QDHeader || jar.qdheader || jar.QDHEADER || '')
|
||||
if (uid) return uid
|
||||
if (jar.uid) return String(jar.uid)
|
||||
const obj = parseJson(body || '', null)
|
||||
uid = obj && obj.Data && obj.Data.UserInfo && (obj.Data.UserInfo.UserId || obj.Data.UserInfo.userId)
|
||||
return uid ? String(uid) : ''
|
||||
return findUid(obj)
|
||||
}
|
||||
function notify(title, sub, msg, opts) {
|
||||
try { $notify(title, sub || '', msg || '', opts || {}) } catch (e) { $notify(title, sub || '', msg || '') }
|
||||
|
||||
Reference in New Issue
Block a user