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
53 lines
2.2 KiB
JavaScript
53 lines
2.2 KiB
JavaScript
import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
|
|
import { registerSiteAuthCommands } from '../_shared/site-auth.js';
|
|
|
|
async function hasPowerchinaSessionCookie(page) {
|
|
const cookies = await page.getCookies({ url: 'https://zhaopin.powerchina.cn' });
|
|
// JSESSIONID / SESSION are issued for anonymous Java sessions too; gate only on
|
|
// the auth-token cookies so the login poll doesn't navigate away mid-login.
|
|
return cookies.some(c => /^(Admin-Token|access_token)$/i.test(c.name) && c.value);
|
|
}
|
|
|
|
async function verifyPowerchinaIdentity(page) {
|
|
if (!await hasPowerchinaSessionCookie(page)) {
|
|
throw new AuthRequiredError('powerchina.cn', 'Powerchina session cookies missing — anonymous');
|
|
}
|
|
await page.goto('https://zhaopin.powerchina.cn/index');
|
|
await page.wait(3);
|
|
const probe = await page.evaluate(`
|
|
(() => {
|
|
if (/\\/login(\\b|$|\\?)/.test(location.pathname)) {
|
|
return { kind: 'auth', detail: 'Powerchina redirected to /login — anonymous' };
|
|
}
|
|
const bodyText = document.body?.innerText || '';
|
|
if (/欢迎登录.*【登录】|请登录|您未登录/.test(bodyText)) {
|
|
return { kind: 'auth', detail: 'Powerchina shows 欢迎登录 prompt — anonymous' };
|
|
}
|
|
const el = document.querySelector('.user-info, .userName, .personalCenter [class*=name]');
|
|
const userName = (el?.innerText || '').trim();
|
|
if (!userName) {
|
|
return { kind: 'auth', detail: 'Powerchina no user name DOM — anonymous or layout changed' };
|
|
}
|
|
return { ok: true, name: userName };
|
|
})()
|
|
`);
|
|
if (probe?.kind === 'auth') throw new AuthRequiredError('powerchina.cn', probe.detail);
|
|
if (!probe?.ok) throw new CommandExecutionError(`Unexpected Powerchina probe: ${JSON.stringify(probe)}`);
|
|
return { name: probe.name };
|
|
}
|
|
|
|
registerSiteAuthCommands({
|
|
site: 'powerchina',
|
|
domain: 'powerchina.cn',
|
|
loginUrl: 'https://zhaopin.powerchina.cn/login',
|
|
columns: ['name'],
|
|
quickCheck: hasPowerchinaSessionCookie,
|
|
verify: verifyPowerchinaIdentity,
|
|
poll: async (page) => {
|
|
if (!await hasPowerchinaSessionCookie(page)) {
|
|
throw new AuthRequiredError('powerchina.cn', 'Waiting for Powerchina session cookies');
|
|
}
|
|
return verifyPowerchinaIdentity(page);
|
|
},
|
|
});
|