revert wbstream refresh logic
This commit is contained in:
1 parent
98312a5965
commit
ad8635fd91
11 files changed
+52
-291
No files matched your search
@@ -24,11 +24,12 @@ export const VK_LOGIN_URL = 'https://vk.ru/';
|
||||
export const YANDEX_LOGIN_URL = 'https://passport.yandex.ru/auth?retpath=https%3A%2F%2Ftelemost.yandex.ru%2F';
|
||||
export const DION_LOGIN_URL = 'https://dion.vc/login';
|
||||
export const WBSTREAM_LOGIN_URL = 'https://stream.wb.ru/login';
|
||||
export const WBSTREAM_API_ORIGIN = 'https://stream.wb.ru';
|
||||
export const BITRIX_LOGIN_URL = 'https://www.bitrix24.ru/';
|
||||
export const VK_AUTH_COOKIE = 'remixsid';
|
||||
export const YANDEX_AUTH_COOKIE = 'Session_id';
|
||||
export const DION_AUTH_COOKIE = 'vc-refresh-token';
|
||||
export const WBSTREAM_AUTH_COOKIE = 'x_wbaas_token';
|
||||
export const WBSTREAM_ACCESS_TOKEN_COOKIE = 'wb_access_token';
|
||||
export const BITRIX_SESSION_COOKIE = 'BITRIX_SM_UIDH';
|
||||
export const BITRIX_AUTH_NET_HOST = 'https://auth2.bitrix24.net';
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import {
|
||||
YANDEX_COOKIE_DOMAINS,
|
||||
DION_COOKIE_DOMAINS,
|
||||
WBSTREAM_COOKIE_DOMAINS,
|
||||
WBSTREAM_API_ORIGIN,
|
||||
WBSTREAM_ACCESS_TOKEN_COOKIE,
|
||||
BITRIX_COOKIE_DOMAINS,
|
||||
BITRIX_SESSION_COOKIE,
|
||||
BITRIX_AUTH_NET_HOST,
|
||||
@@ -242,25 +244,28 @@ export class CookieStore {
|
||||
return buildStoredZip(entries);
|
||||
}
|
||||
|
||||
async setWBStreamDeviceId(id: string): Promise<void> {
|
||||
if (!id) return;
|
||||
async setWBStreamAccessToken(token: string): Promise<void> {
|
||||
if (!token) return;
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
const existing = await ses.cookies.get({ url: 'https://stream.wb.ru/', name: '__wb_device_id' });
|
||||
if (existing.length > 0 && existing[0].value === id) return;
|
||||
const existing = await ses.cookies.get({
|
||||
url: `${WBSTREAM_API_ORIGIN}/`,
|
||||
name: WBSTREAM_ACCESS_TOKEN_COOKIE,
|
||||
});
|
||||
if (existing.length > 0 && existing[0].value === token) return;
|
||||
try {
|
||||
await ses.cookies.set({
|
||||
url: 'https://stream.wb.ru/',
|
||||
name: '__wb_device_id',
|
||||
value: id,
|
||||
url: `${WBSTREAM_API_ORIGIN}/`,
|
||||
name: WBSTREAM_ACCESS_TOKEN_COOKIE,
|
||||
value: token,
|
||||
domain: 'stream.wb.ru',
|
||||
path: '/',
|
||||
secure: true,
|
||||
httpOnly: false,
|
||||
expirationDate: Math.floor(Date.now() / 1000) + 60 * 60 * 24 * 365 * 5,
|
||||
});
|
||||
console.log(`[wb-device-id] persisted ${id}`);
|
||||
console.log(`[wb-access-token] persisted len=${token.length}`);
|
||||
} catch (err) {
|
||||
console.log(`[wb-device-id] failed to persist:`, err);
|
||||
console.log(`[wb-access-token] failed to persist:`, err);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,10 +157,10 @@ export class HeadlessLauncher {
|
||||
const dionCookieFile = platform === Platform.Dion ? new DionCookieFile(cookiesPath) : null;
|
||||
const fileHasSession =
|
||||
platform === Platform.WBStream
|
||||
? await cookieFileHasCookie(cookiesPath, config.refreshCookie)
|
||||
? await cookieFileHasCookie(cookiesPath, config.authCookie)
|
||||
: dionCookieFile != null && (await dionCookieFile.hasSession());
|
||||
let cookies = await this.cookies.getCookiesForDomains(config.cookieDomains);
|
||||
const needsLogin = !fileHasSession && !cookies.some((c) => c.name === config.refreshCookie);
|
||||
const needsLogin = !fileHasSession && !cookies.some((c) => c.name === config.authCookie);
|
||||
if (needsLogin) {
|
||||
if (tab.isBot) {
|
||||
const reply = `Please log into ${config.platformName} in the creator app first, then try again.`;
|
||||
@@ -219,7 +219,6 @@ export class HeadlessLauncher {
|
||||
if (dionCookieFile) await dionCookieFile.clearTokens();
|
||||
if (platform === Platform.WBStream) await fs.unlink(cookiesPath).catch(() => {});
|
||||
await this.cookies.clearAuthCookies(config.cookieDomains, config.authCookie);
|
||||
await this.cookies.clearAuthCookies(config.cookieDomains, config.refreshCookie);
|
||||
if (this.host.getTab(tabId) === tab) this.startHeadless(tabId, platform, args);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -11,13 +11,12 @@ import {
|
||||
VK_AUTH_COOKIE,
|
||||
YANDEX_AUTH_COOKIE,
|
||||
DION_AUTH_COOKIE,
|
||||
WBSTREAM_AUTH_COOKIE,
|
||||
WBSTREAM_ACCESS_TOKEN_COOKIE,
|
||||
} from '../constants';
|
||||
|
||||
export interface PlatformConfig {
|
||||
tunnelMode: TunnelMode;
|
||||
authCookie: string;
|
||||
refreshCookie: string;
|
||||
loginUrl: string;
|
||||
cookieDomains: string[];
|
||||
platformName: string;
|
||||
@@ -31,7 +30,6 @@ export const PLATFORM_CONFIG: Partial<Record<Platform, PlatformConfig>> = {
|
||||
[Platform.VK]: {
|
||||
tunnelMode: TunnelMode.HeadlessVK,
|
||||
authCookie: VK_AUTH_COOKIE,
|
||||
refreshCookie: VK_AUTH_COOKIE,
|
||||
loginUrl: VK_LOGIN_URL,
|
||||
cookieDomains: VK_COOKIE_DOMAINS,
|
||||
platformName: 'VK',
|
||||
@@ -43,7 +41,6 @@ export const PLATFORM_CONFIG: Partial<Record<Platform, PlatformConfig>> = {
|
||||
[Platform.Telemost]: {
|
||||
tunnelMode: TunnelMode.HeadlessTelemost,
|
||||
authCookie: YANDEX_AUTH_COOKIE,
|
||||
refreshCookie: YANDEX_AUTH_COOKIE,
|
||||
loginUrl: YANDEX_LOGIN_URL,
|
||||
cookieDomains: YANDEX_COOKIE_DOMAINS,
|
||||
platformName: 'Yandex',
|
||||
@@ -55,7 +52,6 @@ export const PLATFORM_CONFIG: Partial<Record<Platform, PlatformConfig>> = {
|
||||
[Platform.Dion]: {
|
||||
tunnelMode: TunnelMode.HeadlessDion,
|
||||
authCookie: DION_AUTH_COOKIE,
|
||||
refreshCookie: DION_AUTH_COOKIE,
|
||||
loginUrl: DION_LOGIN_URL,
|
||||
cookieDomains: DION_COOKIE_DOMAINS,
|
||||
platformName: 'DION',
|
||||
@@ -66,14 +62,13 @@ export const PLATFORM_CONFIG: Partial<Record<Platform, PlatformConfig>> = {
|
||||
},
|
||||
[Platform.WBStream]: {
|
||||
tunnelMode: TunnelMode.HeadlessWBStream,
|
||||
authCookie: WBSTREAM_AUTH_COOKIE,
|
||||
refreshCookie: 'wbx-refresh',
|
||||
authCookie: WBSTREAM_ACCESS_TOKEN_COOKIE,
|
||||
loginUrl: WBSTREAM_LOGIN_URL,
|
||||
cookieDomains: WBSTREAM_COOKIE_DOMAINS,
|
||||
platformName: 'WB Stream',
|
||||
binarySubdir: 'wbstream',
|
||||
binaryBase: 'headless-wbstream-creator',
|
||||
joinFlag: '--room',
|
||||
loginWaitCookies: ['x_wbaas_token', 'wbx-refresh', 'wbx-validation-key'],
|
||||
loginWaitCookies: [WBSTREAM_ACCESS_TOKEN_COOKIE],
|
||||
},
|
||||
};
|
||||
@@ -239,7 +239,7 @@ export class TabManager {
|
||||
return this.cookies.buildCookiesZip();
|
||||
}
|
||||
|
||||
setWBStreamDeviceId(id: string): Promise<void> {
|
||||
return this.cookies.setWBStreamDeviceId(id);
|
||||
setWBStreamAccessToken(token: string): Promise<void> {
|
||||
return this.cookies.setWBStreamAccessToken(token);
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,3 @@ export function extractTaggedCallLink(msg: string, platform: Platform): { tabId:
|
||||
if (!match) return null;
|
||||
return { tabId: match[1].trim(), link: match[2].trim() };
|
||||
}
|
||||
|
||||
export function parseWBDeviceId(msg: string): string | null {
|
||||
const match = msg.match(/\[WB_DEVICE_ID\]\s+(\S+)/);
|
||||
return match ? match[1] : null;
|
||||
}
|
||||
@@ -3,9 +3,15 @@ import * as path from 'path';
|
||||
import { TabManager } from './tab-manager';
|
||||
import { VkAutoclick } from '../autoclick/vk';
|
||||
import { TelemostAutoclick } from '../autoclick/telemost';
|
||||
import { SESSION_PARTITION, USER_AGENT, WINDOW_WIDTH, WINDOW_HEIGHT } from '../constants';
|
||||
import {
|
||||
SESSION_PARTITION,
|
||||
USER_AGENT,
|
||||
WINDOW_WIDTH,
|
||||
WINDOW_HEIGHT,
|
||||
WBSTREAM_API_ORIGIN,
|
||||
} from '../constants';
|
||||
import { Platform } from '../types';
|
||||
import { parseCallStatus, extractTaggedCallLink, parseWBDeviceId } from './util/log-tags';
|
||||
import { parseCallStatus, extractTaggedCallLink } from './util/log-tags';
|
||||
|
||||
function stripCSP(ses: Session): void {
|
||||
ses.webRequest.onHeadersReceived((details, callback) => {
|
||||
@@ -25,6 +31,14 @@ export function createWindow(tabManager: TabManager): BrowserWindow {
|
||||
ses.setPermissionCheckHandler(() => true);
|
||||
ses.setUserAgent(USER_AGENT);
|
||||
|
||||
ses.webRequest.onBeforeSendHeaders({ urls: [`${WBSTREAM_API_ORIGIN}/*`] }, (details, callback) => {
|
||||
const authorization = details.requestHeaders['Authorization'] ?? details.requestHeaders['authorization'];
|
||||
if (typeof authorization === 'string' && authorization.startsWith('Bearer ')) {
|
||||
tabManager.setWBStreamAccessToken(authorization.slice('Bearer '.length)).catch(() => {});
|
||||
}
|
||||
callback({ requestHeaders: details.requestHeaders });
|
||||
});
|
||||
|
||||
app.on('session-created', stripCSP);
|
||||
|
||||
const win = new BrowserWindow({
|
||||
@@ -46,19 +60,6 @@ export function createWindow(tabManager: TabManager): BrowserWindow {
|
||||
|
||||
const autoclickers = new Map<number, { telemost: TelemostAutoclick; vk: VkAutoclick }>();
|
||||
|
||||
const wbDeviceIdHook = `(function(){
|
||||
try {
|
||||
var key = 'wb_auth_api_device_id';
|
||||
var existing = localStorage.getItem(key);
|
||||
if (existing) console.log('[WB_DEVICE_ID]', existing);
|
||||
var orig = Storage.prototype.setItem;
|
||||
Storage.prototype.setItem = function(k, v) {
|
||||
if (k === key) console.log('[WB_DEVICE_ID]', v);
|
||||
return orig.apply(this, arguments);
|
||||
};
|
||||
} catch (e) {}
|
||||
})();`;
|
||||
|
||||
win.webContents.on('did-attach-webview', (_e, wvContents) => {
|
||||
wvContents.on('before-input-event', (_e, input) => {
|
||||
if (input.key === 'F12') wvContents.openDevTools();
|
||||
@@ -72,13 +73,6 @@ export function createWindow(tabManager: TabManager): BrowserWindow {
|
||||
return { action: 'allow' };
|
||||
});
|
||||
|
||||
wvContents.on('dom-ready', () => {
|
||||
const url = wvContents.getURL();
|
||||
if (url.includes('stream.wb.ru')) {
|
||||
wvContents.executeJavaScript(wbDeviceIdHook, true).catch(() => {});
|
||||
}
|
||||
});
|
||||
|
||||
wvContents.on('did-navigate', (_e, url) => {
|
||||
const wcId = wvContents.id;
|
||||
if (!autoclickers.has(wcId)) {
|
||||
@@ -109,11 +103,6 @@ export function createWindow(tabManager: TabManager): BrowserWindow {
|
||||
handleBotCallLink(tabManager, msg, Platform.VK);
|
||||
handleBotCallLink(tabManager, msg, Platform.Telemost);
|
||||
|
||||
const deviceId = parseWBDeviceId(msg);
|
||||
if (deviceId) {
|
||||
tabManager.setWBStreamDeviceId(deviceId).catch(() => {});
|
||||
}
|
||||
|
||||
const callStatus = parseCallStatus(msg);
|
||||
if (callStatus) {
|
||||
console.log('[MAIN] Cached status for', callStatus.tabId, ':', callStatus.status);
|
||||
|
||||
Reference in new issue
Block a user