basic dion implementation
This commit is contained in:
1 parent
42aa45465a
commit
0643d24aa2
42 files changed
+3449
-63
No files matched your search
@@ -8,6 +8,7 @@ import {
|
||||
SESSION_PARTITION,
|
||||
VK_COOKIE_DOMAINS,
|
||||
YANDEX_COOKIE_DOMAINS,
|
||||
DION_COOKIE_DOMAINS,
|
||||
} from '../constants';
|
||||
import { TunnelMode, Platform, BotSettings } from '../types';
|
||||
|
||||
@@ -97,7 +98,10 @@ export function registerIpcHandlers(tabManager: TabManager): void {
|
||||
ipcMain.handle(IPC.GET_COOKIES, async (_e, domain: string) => {
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
const all = await ses.cookies.get({});
|
||||
const domains = domain === 'yandex' ? YANDEX_COOKIE_DOMAINS : VK_COOKIE_DOMAINS;
|
||||
let domains: string[];
|
||||
if (domain === 'yandex') domains = YANDEX_COOKIE_DOMAINS;
|
||||
else if (domain === 'dion') domains = DION_COOKIE_DOMAINS;
|
||||
else domains = VK_COOKIE_DOMAINS;
|
||||
const filtered = all.filter((cookie) => {
|
||||
return cookie.domain != null && domains.some((d) => cookie.domain!.includes(d));
|
||||
});
|
||||
|
||||
@@ -12,10 +12,13 @@ import {
|
||||
SESSION_PARTITION,
|
||||
VK_COOKIE_DOMAINS,
|
||||
YANDEX_COOKIE_DOMAINS,
|
||||
DION_COOKIE_DOMAINS,
|
||||
VK_LOGIN_URL,
|
||||
YANDEX_LOGIN_URL,
|
||||
DION_LOGIN_URL,
|
||||
VK_AUTH_COOKIE,
|
||||
YANDEX_AUTH_COOKIE,
|
||||
DION_AUTH_COOKIE,
|
||||
LOG_CAPTURE_SNIPPET,
|
||||
} from '../constants';
|
||||
import { BotManager } from '../bot/bot-manager';
|
||||
@@ -42,6 +45,7 @@ export class TabManager {
|
||||
private headlessVKPath: string;
|
||||
private headlessTelemostPath: string;
|
||||
private headlessWBStreamPath: string;
|
||||
private headlessDionPath: string;
|
||||
private hooksDir: string;
|
||||
|
||||
constructor() {
|
||||
@@ -61,6 +65,10 @@ export class TabManager {
|
||||
path.join('headless', 'wbstream', binaryName('headless-wbstream-creator')),
|
||||
binaryName('headless-wbstream-creator'),
|
||||
);
|
||||
this.headlessDionPath = resolveResourcePath(
|
||||
path.join('headless', 'dion', binaryName('headless-dion-creator')),
|
||||
binaryName('headless-dion-creator'),
|
||||
);
|
||||
this.hooksDir = app.isPackaged
|
||||
? path.join(process.resourcesPath!, 'hooks')
|
||||
: path.join(__dirname, '..', '..', '..', 'hooks');
|
||||
@@ -220,6 +228,51 @@ export class TabManager {
|
||||
});
|
||||
}
|
||||
|
||||
private headlessConfig(platform: Platform): {
|
||||
tunnelMode: TunnelMode;
|
||||
authCookie: string;
|
||||
loginUrl: string;
|
||||
cookieDomains: string[];
|
||||
platformName: string;
|
||||
binaryPath: string;
|
||||
getCookies: () => Promise<{ name: string; value: string }[]>;
|
||||
} | null {
|
||||
switch (platform) {
|
||||
case Platform.Telemost:
|
||||
return {
|
||||
tunnelMode: TunnelMode.HeadlessTelemost,
|
||||
authCookie: YANDEX_AUTH_COOKIE,
|
||||
loginUrl: YANDEX_LOGIN_URL,
|
||||
cookieDomains: YANDEX_COOKIE_DOMAINS,
|
||||
platformName: 'Yandex',
|
||||
binaryPath: this.headlessTelemostPath,
|
||||
getCookies: () => this.getYandexCookies(),
|
||||
};
|
||||
case Platform.Dion:
|
||||
return {
|
||||
tunnelMode: TunnelMode.HeadlessDion,
|
||||
authCookie: DION_AUTH_COOKIE,
|
||||
loginUrl: DION_LOGIN_URL,
|
||||
cookieDomains: DION_COOKIE_DOMAINS,
|
||||
platformName: 'DION',
|
||||
binaryPath: this.headlessDionPath,
|
||||
getCookies: () => this.getDionCookies(),
|
||||
};
|
||||
case Platform.VK:
|
||||
return {
|
||||
tunnelMode: TunnelMode.HeadlessVK,
|
||||
authCookie: VK_AUTH_COOKIE,
|
||||
loginUrl: VK_LOGIN_URL,
|
||||
cookieDomains: VK_COOKIE_DOMAINS,
|
||||
platformName: 'VK',
|
||||
binaryPath: this.headlessVKPath,
|
||||
getCookies: () => this.getVKCookies(),
|
||||
};
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async startHeadless(tabId: string, platform: Platform): Promise<void> {
|
||||
const tab = await this.getOrCreateTab(tabId);
|
||||
tab.platform = platform;
|
||||
@@ -238,31 +291,30 @@ export class TabManager {
|
||||
return;
|
||||
}
|
||||
|
||||
const isTelemost = platform === Platform.Telemost;
|
||||
tab.tunnelMode = isTelemost ? TunnelMode.HeadlessTelemost : TunnelMode.HeadlessVK;
|
||||
const authCookie = isTelemost ? YANDEX_AUTH_COOKIE : VK_AUTH_COOKIE;
|
||||
const loginUrl = isTelemost ? YANDEX_LOGIN_URL : VK_LOGIN_URL;
|
||||
const cookieDomains = isTelemost ? YANDEX_COOKIE_DOMAINS : VK_COOKIE_DOMAINS;
|
||||
const platformName = isTelemost ? 'Yandex' : 'VK';
|
||||
let cookies = isTelemost ? await this.getYandexCookies() : await this.getVKCookies();
|
||||
if (!cookies.some((c) => c.name === authCookie)) {
|
||||
this.sendLog(tabId, `No ${platformName} session found, opening login.`);
|
||||
const config = this.headlessConfig(platform);
|
||||
if (!config) {
|
||||
this.sendLog(tabId, `Unsupported headless platform: ${platform}`);
|
||||
return;
|
||||
}
|
||||
tab.tunnelMode = config.tunnelMode;
|
||||
let cookies = await config.getCookies();
|
||||
if (!cookies.some((c) => c.name === config.authCookie)) {
|
||||
this.sendLog(tabId, `No ${config.platformName} session found, opening login.`);
|
||||
if (this._mainWindow && !this._mainWindow.isDestroyed()) {
|
||||
this._mainWindow.webContents.send(IPC.LOGIN_REQUIRED, { tabId, url: loginUrl });
|
||||
this._mainWindow.webContents.send(IPC.LOGIN_REQUIRED, { tabId, url: config.loginUrl });
|
||||
}
|
||||
await this.waitForLogin(cookieDomains, authCookie);
|
||||
await this.waitForLogin(config.cookieDomains, config.authCookie);
|
||||
if (this._mainWindow && !this._mainWindow.isDestroyed()) {
|
||||
this._mainWindow.webContents.send(IPC.LOGIN_DONE, { tabId });
|
||||
}
|
||||
this.sendLog(tabId, `${platformName} login captured.`);
|
||||
cookies = isTelemost ? await this.getYandexCookies() : await this.getVKCookies();
|
||||
this.sendLog(tabId, `${config.platformName} login captured.`);
|
||||
cookies = await config.getCookies();
|
||||
}
|
||||
this.sendLog(tabId, `${platformName} cookies (${cookies.length}): ${cookies.map((c) => c.name).join(', ')}`);
|
||||
this.sendLog(tabId, `${config.platformName} cookies (${cookies.length}): ${cookies.map((c) => c.name).join(', ')}`);
|
||||
this.killRelay(tabId, tab);
|
||||
const cookiesPath = path.join(app.getPath('userData'), `cookies-${platform}.json`);
|
||||
await fs.writeFile(cookiesPath, JSON.stringify(cookies));
|
||||
const binaryPath = isTelemost ? this.headlessTelemostPath : this.headlessVKPath;
|
||||
const proc = spawn(binaryPath, ['--resources', 'default', '--cookies', cookiesPath], {
|
||||
const proc = spawn(config.binaryPath, ['--resources', 'default', '--cookies', cookiesPath], {
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
});
|
||||
tab.relay = proc;
|
||||
@@ -275,8 +327,8 @@ export class TabManager {
|
||||
proc.on('close', async (code) => {
|
||||
this.sendLog(tabId, `Headless exited with code ${code}`);
|
||||
if (sawAuthFailure) {
|
||||
this.sendLog(tabId, `${platformName} session rejected (401), clearing and re-prompting login.`);
|
||||
await this.clearAuthCookies(cookieDomains, authCookie);
|
||||
this.sendLog(tabId, `${config.platformName} session rejected (401), clearing and re-prompting login.`);
|
||||
await this.clearAuthCookies(config.cookieDomains, config.authCookie);
|
||||
if (this.tabs.get(tabId) === tab) {
|
||||
this.startHeadless(tabId, platform);
|
||||
}
|
||||
@@ -339,7 +391,12 @@ export class TabManager {
|
||||
}
|
||||
|
||||
async loadHook(tabId: string, url: string, tab: TabState): Promise<string> {
|
||||
const isDion = url.includes('dion.vc');
|
||||
const isTelemost = url.includes('telemost.yandex');
|
||||
if (isDion) {
|
||||
tab.platform = Platform.Dion;
|
||||
return LOG_CAPTURE_SNIPPET;
|
||||
}
|
||||
tab.platform = isTelemost ? Platform.Telemost : Platform.VK;
|
||||
|
||||
if (isTelemost || tab.tunnelMode === TunnelMode.PionVideo) {
|
||||
@@ -356,7 +413,12 @@ export class TabManager {
|
||||
const tab = await this.getOrCreateTab(tabId);
|
||||
tab.tunnelMode = mode;
|
||||
if (platform) tab.platform = platform;
|
||||
if (mode === TunnelMode.HeadlessVK || mode === TunnelMode.HeadlessTelemost) return;
|
||||
if (
|
||||
mode === TunnelMode.HeadlessVK ||
|
||||
mode === TunnelMode.HeadlessTelemost ||
|
||||
mode === TunnelMode.HeadlessWBStream ||
|
||||
mode === TunnelMode.HeadlessDion
|
||||
) return;
|
||||
this.killRelay(tabId, tab);
|
||||
setTimeout(() => this.startRelay(tabId, tab), RELAY_RESTART_DELAY_MS);
|
||||
}
|
||||
@@ -377,4 +439,12 @@ export class TabManager {
|
||||
.map((c) => ({ name: c.name, value: c.value }));
|
||||
}
|
||||
|
||||
async getDionCookies(): Promise<{ name: string; value: string }[]> {
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
const all = await ses.cookies.get({});
|
||||
return all
|
||||
.filter((c) => c.domain != null && DION_COOKIE_DOMAINS.some((d) => c.domain!.includes(d)))
|
||||
.map((c) => ({ name: c.name, value: c.value }));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user