9b395f5cc3
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
Build Chrome Extension / build (push) Has been cancelled
Trigger Website Rebuild (Docs Updated) / dispatch (push) Has been cancelled
37 lines
1.2 KiB
JavaScript
37 lines
1.2 KiB
JavaScript
import { AuthRequiredError } from '@jackwener/opencli/errors';
|
|
import { registerSiteAuthCommands } from '../_shared/site-auth.js';
|
|
import { apiGet, getSelfUid } from './utils.js';
|
|
|
|
async function hasBilibiliSessionCookies(page) {
|
|
const cookies = await page.getCookies({ url: 'https://www.bilibili.com' });
|
|
const names = new Set(cookies.map(cookie => cookie.name));
|
|
return names.has('SESSDATA') && names.has('DedeUserID');
|
|
}
|
|
|
|
async function verifyBilibiliIdentity(page) {
|
|
await page.goto('https://www.bilibili.com');
|
|
const uid = await getSelfUid(page);
|
|
const payload = await apiGet(page, '/x/space/wbi/acc/info', { params: { mid: uid }, signed: true });
|
|
const data = payload?.data ?? {};
|
|
return {
|
|
id: String(data.mid ?? uid),
|
|
username: data.name ?? '',
|
|
level: data.level ?? 0,
|
|
};
|
|
}
|
|
|
|
registerSiteAuthCommands({
|
|
site: 'bilibili',
|
|
domain: 'www.bilibili.com',
|
|
loginUrl: 'https://passport.bilibili.com/login',
|
|
columns: ['id', 'username', 'level'],
|
|
quickCheck: hasBilibiliSessionCookies,
|
|
verify: verifyBilibiliIdentity,
|
|
poll: async (page) => {
|
|
if (!await hasBilibiliSessionCookies(page)) {
|
|
throw new AuthRequiredError('bilibili.com', 'Waiting for Bilibili session cookies');
|
|
}
|
|
return verifyBilibiliIdentity(page);
|
|
},
|
|
});
|