MCPcopy Create free account
hub / github.com/NobyDa/Script / GetAuth

Function GetAuth

Bilibili-DailyBonus/Manga.js:110–133  ·  view source on GitHub ↗
(raw, data)

Source from the content-addressed store, hash-verified

108}
109
110function 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
135function formatHeaders(h) {
136 return Object.keys(h).reduce((t, i) => (t[i.toLowerCase()] = h[i], t), {})

Callers 1

Manga.jsFile · 0.70

Calls 4

formatHeadersFunction · 0.70
infoMethod · 0.45
errorMethod · 0.45
setjsonMethod · 0.45

Tested by

no test coverage detected