Download protocol.js from bingn/ikun2: direct link, hf CLI and curl.
- Browser
- Download file 9.14 kB
-
https://huggingface.co/spaces/bingn/ikun2/resolve/main/protocol.js
- Command line
-
hf download hf://spaces/bingn/ikun2/protocol.js
-
curl -L -o protocol.js https://huggingface.co/spaces/bingn/ikun2/resolve/main/protocol.js
9.14 kB
| /** | |
| * protocol.js - ChatAIBot.pro ็บฏ HTTP ๅ่ฎฎๆณจๅๆจกๅ | |
| * | |
| * ๅทฒ็กฎ่ฎค็ API ็ซฏ็น (Express + Apache/Ubuntu): | |
| * POST /api/register โ 201 {"success":true} (ๆณจๅ, ่ฟๅ connect.sid session cookie) | |
| * POST /api/register/verify โ 200 (้ช่ฏ, ้่ฆ {email, token}) | |
| * POST /api/login โ 200 (็ปๅฝ, ้่ฆ {email, password}) | |
| * POST /api/logout โ 200 OK | |
| * | |
| * ๆณจๅๆต็จ (้ๅ่ชๅ็ซฏ sign-up chunk + module 40933): | |
| * 1. POST /api/register { email, password, isAdvertisingAccepted, mainSiteUrl, | |
| * utmSource, utmCampaign, connectBusiness, yandexClientId } | |
| * Headers: Content-Type: application/json, Accept-Language: en | |
| * โ 201 {"success":true} + Set-Cookie: connect.sid | |
| * 2. ้ฎไปถไธญๅ ๅซ 6 ไฝๆฐๅญ้ช่ฏ็ (token) | |
| * ๆ ผๅผ: "Your code: 528135" | |
| * 3. POST /api/register/verify { email, token, connectBusiness, syncToken } | |
| * โ ้ช่ฏๅฎๆ๏ผ่ดฆๅทๆฟๆดป | |
| * 4. POST /api/login { email, password } | |
| * โ ่ทๅ session | |
| */ | |
| 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)); | |
| } | |
| // ==================== ๆณจๅๆญฅ้ชค ==================== | |
| /** | |
| * Step 1: ๆณจๅ่ดฆๅท | |
| * POST /api/register | |
| * ้ๅ่ชๅ็ซฏ sign-up-d2a668c82094de73.js + module 40933 | |
| * ๆต่งๅจๅ้็ๅฎๆดๅญๆฎตๅ headers | |
| */ | |
| 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}`); | |
| } | |
| /** | |
| * Step 2: ไป้ฎ็ฎฑ่ทๅ 6 ไฝ้ช่ฏ็ | |
| * chataibot.pro ็้ช่ฏ็ ๅฐฑๆฏ token๏ผๆฏไธไธช 6 ไฝๆฐๅญ | |
| */ | |
| 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; | |
| } | |
| /** | |
| * Step 3: ๆไบค้ช่ฏ็ | |
| * POST /api/register/verify { email, token, connectBusiness, syncToken } | |
| * ้ๅ่ชๅ็ซฏ: verify ่ฟๅ้ connectBusiness ๅ syncToken | |
| */ | |
| 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)}`); | |
| } | |
| /** | |
| * Step 4: ็ปๅฝ่ทๅ session | |
| * POST /api/login | |
| */ | |
| 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 }; | |
| } | |
| // ==================== ไธปๆณจๅๆต็จ ==================== | |
| /** | |
| * ็บฏๅ่ฎฎๆณจๅ ChatAIBot.pro ่ดฆๅท | |
| * | |
| * @param {object} account - { email, password, firstName, lastName, fullName } | |
| * @param {object} mailProvider - ้ฎ็ฎฑ provider ๅฎไพ | |
| * @returns {object} { success, account, session, error } | |
| */ | |
| export async function register(account, mailProvider) { | |
| console.log(`\n โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ`); | |
| console.log(` ๆณจๅ: ${account.email}`); | |
| console.log(` โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n`); | |
| try { | |
| // Step 1: ๆณจๅ | |
| await sleep(humanDelay(500)); | |
| const regResult = await stepRegister(account); | |
| // Step 2: ่ทๅ 6 ไฝ้ช่ฏ็ | |
| 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, | |
| }; | |
| } | |
| // Step 3: ๆไบค้ช่ฏ | |
| await sleep(humanDelay(1000)); | |
| const verifyResult = await stepVerify(account.email, token, regResult.cookies); | |
| // Step 4: ็ปๅฝ | |
| 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, | |
| }; | |
| } | |
| } | |
| /** | |
| * ๆขๆต API (ไฟ็ไพ่ฐ่ฏ็จ) | |
| */ | |
| 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; | |
| } | |