(raw, data)
| 108 | } |
| 109 | |
| 110 | function GetAuth(raw, data) { |
| 111 | raw.headers = formatHeaders(raw.headers); |
| 112 | const uid = raw.headers['x-bili-mid']; |
| 113 | // cookies may not always be present in app. |
| 114 | const cookie = raw.headers.cookie?.split(/(SESSDATA=[a-zA-Z0-9%_-]+)/)[1]; |
| 115 | const access_key = raw.url.split(/access_key=([a-zA-Z0-9_-]+)/)[1]; |
| 116 | if (uid && (cookie?.includes('SESSDATA=') || access_key)) { |
| 117 | if (!data.account || !data.account[uid]) { |
| 118 | notifyMsg.push(`账号: ${uid} 写入鉴权成功!🎉`); |
| 119 | } else { |
| 120 | $.info(`账号: ${uid} 更新鉴权成功!🎉`); |
| 121 | } |
| 122 | data.account = { |
| 123 | ...data.account, [uid]: { |
| 124 | ...data.account?.[uid], |
| 125 | ...(cookie && { cookie }), |
| 126 | ...(access_key && { access_key }) |
| 127 | } |
| 128 | } |
| 129 | } else { |
| 130 | $.error(`写入授权失败, 数据缺失.`) |
| 131 | } |
| 132 | return $.setjson(data, $.name); |
| 133 | } |
| 134 | |
| 135 | function formatHeaders(h) { |
| 136 | return Object.keys(h).reduce((t, i) => (t[i.toLowerCase()] = h[i], t), {}) |
no test coverage detected