| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| import { request, get, post, sleep } from './http.js';
|
| import config from './config.js';
|
|
|
| const API_BASE = config.siteBase;
|
|
|
|
|
|
|
| function humanDelay(baseMs) {
|
| return Math.floor(baseMs * (0.8 + Math.random() * 1.7));
|
| }
|
|
|
|
|
|
|
| |
| |
| |
| |
| |
|
|
| async function stepRegister(account) {
|
| console.log(' [Step 1] ๆไบคๆณจๅ...');
|
|
|
| const resp = await post(`${API_BASE}/api/register`, {
|
| email: account.email,
|
| password: account.password,
|
| isAdvertisingAccepted: false,
|
| mainSiteUrl: `${config.siteBase}/api`,
|
| utmSource: '',
|
| utmCampaign: '',
|
| connectBusiness: '',
|
| yandexClientId: '',
|
| }, {
|
| headers: {
|
| 'Origin': config.siteBase,
|
| 'Referer': config.signupUrl,
|
| 'Accept-Language': 'en',
|
| },
|
| });
|
|
|
| const body = resp.text();
|
| console.log(` ็ถๆ: ${resp.status}`);
|
| console.log(` ๅๅบ: ${body.substring(0, 200)}`);
|
|
|
| if (resp.status === 201 || resp.ok) {
|
| const sessionCookie = resp.cookies.get('connect.sid');
|
| console.log(` Session: ${sessionCookie ? sessionCookie.substring(0, 50) + '...' : 'ๆ '}`);
|
| return { success: true, cookies: resp.cookies };
|
| }
|
|
|
| let errorMsg = body;
|
| try {
|
| const json = JSON.parse(body);
|
| errorMsg = json.message || json.error || body;
|
| } catch {}
|
|
|
| throw new Error(`ๆณจๅๅคฑ่ดฅ (${resp.status}): ${errorMsg}`);
|
| }
|
|
|
| |
| |
| |
|
|
| async function stepGetVerifyToken(mailProvider, senderFilter) {
|
| console.log(' [Step 2] ็ญๅพ
้ช่ฏ้ฎไปถ...');
|
|
|
| const pollOptions = {
|
| initialDelay: 8000,
|
| maxAttempts: 15,
|
| pollInterval: 5000,
|
| };
|
|
|
| const code = await mailProvider.fetchVerificationCode(senderFilter, pollOptions);
|
| if (code) {
|
| console.log(` ้ช่ฏ็ : ${code}`);
|
| return code;
|
| }
|
|
|
| return null;
|
| }
|
|
|
| |
| |
| |
| |
|
|
| async function stepVerify(email, token, cookies) {
|
| console.log(' [Step 3] ๆไบค้ช่ฏ...');
|
|
|
| const resp = await post(`${API_BASE}/api/register/verify`, {
|
| email,
|
| token,
|
| connectBusiness: '',
|
| syncToken: '',
|
| }, {
|
| cookies,
|
| headers: {
|
| 'Origin': config.siteBase,
|
| 'Referer': `${config.siteBase}/app/verify`,
|
| 'Accept-Language': 'en',
|
| },
|
| });
|
|
|
| const body = resp.text();
|
| console.log(` ็ถๆ: ${resp.status}`);
|
| console.log(` ๅๅบ: ${body.substring(0, 300)}`);
|
|
|
| if (resp.ok) {
|
| let data;
|
| try { data = JSON.parse(body); } catch { data = { raw: body }; }
|
| return { success: true, data, cookies: resp.cookies };
|
| }
|
|
|
| throw new Error(`้ช่ฏๅคฑ่ดฅ (${resp.status}): ${body.substring(0, 200)}`);
|
| }
|
|
|
| |
| |
| |
|
|
| async function stepLogin(email, password) {
|
| console.log(' [Step 4] ็ปๅฝ...');
|
|
|
| await sleep(humanDelay(1000));
|
|
|
| const resp = await post(`${API_BASE}/api/login`, {
|
| email,
|
| password,
|
| }, {
|
| headers: {
|
| 'Origin': config.siteBase,
|
| 'Referer': `${config.siteBase}/app/auth/sign-in`,
|
| 'Accept-Language': 'en',
|
| },
|
| });
|
|
|
| const body = resp.text();
|
| console.log(` ็ถๆ: ${resp.status}`);
|
| console.log(` ๅๅบ: ${body.substring(0, 300)}`);
|
|
|
| if (resp.ok) {
|
| let data;
|
| try { data = JSON.parse(body); } catch { data = { raw: body }; }
|
| return {
|
| success: true,
|
| data,
|
| cookies: resp.cookies,
|
| sessionCookie: resp.cookies.get('connect.sid'),
|
| };
|
| }
|
|
|
| console.log(' ็ปๅฝๅคฑ่ดฅ๏ผๅฏ่ฝ้่ฆๅ
้ช่ฏ้ฎ็ฎฑ๏ผ');
|
| return { success: false, status: resp.status, body };
|
| }
|
|
|
|
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| export async function register(account, mailProvider) {
|
| console.log(`\n โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ`);
|
| console.log(` ๆณจๅ: ${account.email}`);
|
| console.log(` โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n`);
|
|
|
| try {
|
|
|
| await sleep(humanDelay(500));
|
| const regResult = await stepRegister(account);
|
|
|
|
|
| const senderFilter = config.senderFilter || 'chataibot';
|
| const token = await stepGetVerifyToken(mailProvider, senderFilter);
|
| if (!token) {
|
| console.log('\n [่ญฆๅ] ๆช่ทๅๅฐ้ช่ฏ็ ๏ผ่ดฆๅทๅทฒๅๅปบไฝๆช้ช่ฏ');
|
| console.log(' ่ฏทๆๅจๆฃๆฅ้ฎ็ฎฑๅฎๆ้ช่ฏ');
|
| return {
|
| success: true,
|
| verified: false,
|
| account,
|
| session: { cookies: regResult.cookies },
|
| cookies: regResult.cookies,
|
| };
|
| }
|
|
|
|
|
| await sleep(humanDelay(1000));
|
| const verifyResult = await stepVerify(account.email, token, regResult.cookies);
|
|
|
|
|
| await sleep(humanDelay(1500));
|
| const loginResult = await stepLogin(account.email, account.password);
|
|
|
| return {
|
| success: true,
|
| verified: true,
|
| account,
|
| session: loginResult.data || verifyResult.data,
|
| cookies: loginResult.cookies || verifyResult.cookies || regResult.cookies,
|
| loginSuccess: loginResult.success,
|
| };
|
| } catch (e) {
|
| console.log(`\n [้่ฏฏ] ${e.message}`);
|
| return {
|
| success: false,
|
| account,
|
| error: e.message,
|
| };
|
| }
|
| }
|
|
|
| |
| |
|
|
| export async function probe() {
|
| console.log('\n โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ');
|
| console.log(' โ ChatAIBot.pro API ๆขๆต โ');
|
| console.log(' โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n');
|
|
|
| const endpoints = [
|
| ['GET', '/api/register', null],
|
| ['POST', '/api/register', { email: 'probe@test.com', password: 'Probe123!' }],
|
| ['POST', '/api/register/verify', { email: 'probe@test.com', token: 'test' }],
|
| ['POST', '/api/login', { email: 'probe@test.com', password: 'Probe123!' }],
|
| ['POST', '/api/logout', {}],
|
| ];
|
|
|
| const results = [];
|
|
|
| for (const [method, path, body] of endpoints) {
|
| try {
|
| const opts = {
|
| headers: {
|
| 'Origin': config.siteBase,
|
| 'Referer': config.signupUrl,
|
| },
|
| followRedirect: false,
|
| timeout: 10000,
|
| };
|
|
|
| let resp;
|
| if (method === 'POST') {
|
| resp = await post(`${API_BASE}${path}`, body, opts);
|
| } else {
|
| resp = await get(`${API_BASE}${path}`, opts);
|
| }
|
|
|
| const text = resp.text();
|
| const status = resp.status;
|
|
|
| console.log(` ${status} ${method} ${path}`);
|
| console.log(` ${text.substring(0, 200)}`);
|
| console.log(` Cookies: ${[...resp.cookies.keys()].join(', ') || 'ๆ '}`);
|
|
|
| results.push({ method, path, status, body: text.substring(0, 200) });
|
| } catch (e) {
|
| results.push({ method, path, status: 0, error: e.message });
|
| }
|
| }
|
|
|
| return results;
|
| }
|
|
|