dion: add email/password to fix cookie expiration

This commit is contained in:
kulikov0 committed 2026-07-26 11:21:17 +02:00
1 parent a7b7fba0a6
commit 6c732f34e3
12 files changed
+388 -63

No files matched your search

+2
View File
@@ -61,6 +61,8 @@ export enum IPC {
SET_UPSTREAM_PROXY = 'set-upstream-proxy',
SET_DEBUG_LOGGING = 'set-debug-logging',
CLEAR_COOKIES = 'clear-cookies',
GET_DION_CREDENTIALS = 'get-dion-credentials',
SET_DION_CREDENTIALS = 'set-dion-credentials',
EXPORT_COOKIES_ZIP = 'export-cookies-zip',
RELAY_LOG = 'relay-log',
CREATE_BOT_TAB = 'create-bot-tab',
+63
View File
@@ -0,0 +1,63 @@
import * as fs from 'fs/promises';
import { CookieFileContent, DionCredentials } from '../types';
import { DION_AUTH_COOKIE } from '../constants';
export class DionCookieFile {
private filePath: string;
constructor(filePath: string) {
this.filePath = filePath;
}
async hasSession(): Promise<boolean> {
const content = await this.readContent();
if (!content) return false;
if (content.email && content.password) return true;
return content.cookies.some((cookie) => cookie.name === DION_AUTH_COOKIE && !!cookie.value);
}
async readCredentials(): Promise<DionCredentials> {
const content = await this.readContent();
return { email: content?.email || '', password: content?.password || '' };
}
async writeCredentials(email: string, password: string): Promise<void> {
const content = await this.readContent();
const updated: CookieFileContent = {
email: email || undefined,
password: password || undefined,
cookies: content?.cookies || [],
};
await fs.writeFile(this.filePath, JSON.stringify(updated));
}
async clearTokens(): Promise<void> {
const content = await this.readContent();
if (!content) return;
if (!content.email || !content.password) {
await fs.unlink(this.filePath).catch(() => {});
return;
}
const credentialsOnly: CookieFileContent = {
email: content.email,
password: content.password,
cookies: [],
};
await fs.writeFile(this.filePath, JSON.stringify(credentialsOnly));
}
async readContent(): Promise<CookieFileContent | null> {
try {
const raw = await fs.readFile(this.filePath, 'utf8');
const parsed = JSON.parse(raw);
if (Array.isArray(parsed)) return { cookies: parsed };
return {
email: typeof parsed.email === 'string' ? parsed.email : undefined,
password: typeof parsed.password === 'string' ? parsed.password : undefined,
cookies: Array.isArray(parsed.cookies) ? parsed.cookies : [],
};
} catch {
return null;
}
}
}
+8
View File
@@ -98,6 +98,14 @@ export function registerIpcHandlers(tabManager: TabManager): void {
return tabManager.clearPlatformCookies(platform as Platform);
});
ipcMain.handle(IPC.GET_DION_CREDENTIALS, () => {
return tabManager.getDionCredentials();
});
ipcMain.handle(IPC.SET_DION_CREDENTIALS, (_e, email: string, password: string) => {
return tabManager.setDionCredentials(email, password);
});
ipcMain.handle(IPC.SEND_BOT_CALL_LINK, (_e, tabId: string, link: string) => {
tabManager.sendBotCallLink(tabId, link);
});
+45 -15
View File
@@ -15,6 +15,7 @@ import {
HeadlessStartArgs,
HeadlessMode,
UpstreamProxy,
DionCredentials,
} from '../types';
import {
INITIAL_PORT_BASE,
@@ -36,6 +37,7 @@ import {
LOG_CAPTURE_SNIPPET,
} from '../constants';
import { BotManager } from '../bot/bot-manager';
import { DionCookieFile } from './dion-cookie-file';
import { buildStoredZip } from './util/zip';
import { resolveResourcePath, binaryName } from './util/paths';
@@ -336,9 +338,12 @@ export class TabManager {
return;
}
tab.tunnelMode = config.tunnelMode;
let cookies = await this.getCookiesForDomains(config.cookieDomains);
const cookiesPath = this.cookieFilePath(platform);
const refreshCookie = platform === Platform.WBStream ? 'wbx-refresh' : config.authCookie;
const needsLogin = !cookies.some((c) => c.name === refreshCookie);
const dionCookieFile = platform === Platform.Dion ? new DionCookieFile(cookiesPath) : null;
const fileHasSession = dionCookieFile != null && await dionCookieFile.hasSession();
let cookies = await this.getCookiesForDomains(config.cookieDomains);
const needsLogin = !fileHasSession && !cookies.some((c) => c.name === refreshCookie);
if (needsLogin) {
if (tab.isBot) {
const reply = `Please log into ${config.platformName} in the creator app first, then try again.`;
@@ -367,9 +372,12 @@ export class TabManager {
this.sendLog(tabId, `${config.platformName} login captured.`);
cookies = await this.getCookiesForDomains(config.cookieDomains);
}
this.sendLog(tabId, `${config.platformName} cookies (${cookies.length}): ${cookies.map((c) => c.name).join(', ')}`);
const cookiesPath = path.join(app.getPath('userData'), `cookies-${platform}.json`);
await fs.writeFile(cookiesPath, JSON.stringify(cookies));
if (fileHasSession) {
this.sendLog(tabId, `${config.platformName} session file is still active, keeping it as is.`);
} else {
this.sendLog(tabId, `${config.platformName} cookies (${cookies.length}): ${cookies.map((c) => c.name).join(', ')}`);
await fs.writeFile(cookiesPath, JSON.stringify(cookies));
}
const spawnArgs = ['--resources', 'default', '--cookies', cookiesPath];
this.killRelay(tabId, tab);
if (joinTarget) {
@@ -383,7 +391,11 @@ export class TabManager {
});
tab.relay = proc;
let sawAuthFailure = false;
let sawInvalidCredentials = false;
this.attachProcessOutput(proc, tabId, (msg) => {
if (dionCookieFile && (msg.includes('"code":1086') || msg.includes('Invalid credentials'))) {
sawInvalidCredentials = true;
}
if (
msg.includes('status 401') ||
msg.includes('"UnauthorizedError"') ||
@@ -395,7 +407,12 @@ export class TabManager {
});
proc.on('close', async (code) => {
this.sendLog(tabId, `Headless exited with code ${code}`);
if (sawInvalidCredentials) {
this.sendLog(tabId, `${config.platformName} rejected the email and password stored in ${cookiesPath}, fix them or clear cookies to log in through the browser.`);
return;
}
if (sawAuthFailure) {
if (dionCookieFile) await dionCookieFile.clearTokens();
await this.clearAuthCookies(config.cookieDomains, config.authCookie);
if (this.tabs.get(tabId) === tab) this.startHeadless(tabId, platform, args);
}
@@ -417,6 +434,18 @@ export class TabManager {
}
}
private cookieFilePath(platform: Platform): string {
return path.join(app.getPath('userData'), `cookies-${platform}.json`);
}
async getDionCredentials(): Promise<DionCredentials> {
return new DionCookieFile(this.cookieFilePath(Platform.Dion)).readCredentials();
}
async setDionCredentials(email: string, password: string): Promise<void> {
await new DionCookieFile(this.cookieFilePath(Platform.Dion)).writeCredentials(email, password);
}
async clearPlatformCookies(platform: Platform): Promise<number> {
const config = this.headlessConfig(platform);
if (!config) return 0;
@@ -434,7 +463,7 @@ export class TabManager {
console.log(`[COOKIES] failed to remove ${cookie.name} on ${url}:`, err);
}
}
await fs.unlink(path.join(app.getPath('userData'), `cookies-${platform}.json`)).catch(() => {});
await fs.unlink(this.cookieFilePath(platform)).catch(() => {});
console.log(`[COOKIES] cleared ${removed} cookies for ${platform}`);
return removed;
}
@@ -549,17 +578,18 @@ export class TabManager {
}
async buildCookiesZip(): Promise<Buffer> {
const platforms: { filename: string; domains: string[] }[] = [
{ filename: 'cookies-vk.json', domains: VK_COOKIE_DOMAINS },
{ filename: 'cookies-yandex.json', domains: YANDEX_COOKIE_DOMAINS },
{ filename: 'cookies-dion.json', domains: DION_COOKIE_DOMAINS },
{ filename: 'cookies-wbstream.json', domains: WBSTREAM_COOKIE_DOMAINS },
const platforms: { filename: string; domains: string[]; platform: Platform }[] = [
{ filename: 'cookies-vk.json', domains: VK_COOKIE_DOMAINS, platform: Platform.VK },
{ filename: 'cookies-yandex.json', domains: YANDEX_COOKIE_DOMAINS, platform: Platform.Telemost },
{ filename: 'cookies-dion.json', domains: DION_COOKIE_DOMAINS, platform: Platform.Dion },
{ filename: 'cookies-wbstream.json', domains: WBSTREAM_COOKIE_DOMAINS, platform: Platform.WBStream },
];
const cookies = await Promise.all(platforms.map((p) => this.getCookiesForDomains(p.domains)));
const entries = platforms.map((p, i) => ({
name: p.filename,
data: Buffer.from(JSON.stringify(cookies[i], null, 2), 'utf8'),
}));
const dionContent = await new DionCookieFile(this.cookieFilePath(Platform.Dion)).readContent();
const entries = platforms.map((p, i) => {
const content = p.platform === Platform.Dion && dionContent ? dionContent : cookies[i];
return { name: p.filename, data: Buffer.from(JSON.stringify(content, null, 2), 'utf8') };
});
return buildStoredZip(entries);
}
+6
View File
@@ -32,6 +32,12 @@ import { IPC } from '../constants';
clearCookies(platform: string) {
return ipcRenderer.invoke(IPC.CLEAR_COOKIES, platform);
},
getDionCredentials() {
return ipcRenderer.invoke(IPC.GET_DION_CREDENTIALS);
},
setDionCredentials(email: string, password: string) {
return ipcRenderer.invoke(IPC.SET_DION_CREDENTIALS, email, password);
},
onCreateBotTab(cb: (data: any) => void) {
ipcRenderer.on(IPC.CREATE_BOT_TAB, (_e, data) => cb(data));
},
+2
View File
@@ -68,6 +68,8 @@ export function renderContent(tm: RendererTabManager): void {
targetInput.value = activeTab.headlessStartTarget || '';
targetInput.classList.remove('invalid');
errorEl.textContent = '';
const dionAccountCard = document.getElementById('headlessDionAccountCard')!;
dionAccountCard.style.display = activeTab.platform === Platform.Dion ? '' : 'none';
if (activeTab.platform === Platform.WBStream) {
targetLabel.textContent = 'Paste a room id or stream.wb.ru/room/<id> link.';
targetInput.placeholder = 'https://stream.wb.ru/room/<id>';
+36
View File
@@ -108,6 +108,41 @@ function bindSettingsEvents(): void {
});
}
function bindDionAccountEvents(): void {
document.getElementById('btnDionAccount')!.addEventListener('click', openDionAccount);
document.getElementById('dionAccountPopup')!.addEventListener('click', closeDionAccount);
document.querySelector('#dionAccountPopup .popup')!.addEventListener('click', (event) => event.stopPropagation());
document.getElementById('btnDionAccountCancel')!.addEventListener('click', closeDionAccount);
document.getElementById('btnDionAccountSave')!.addEventListener('click', async () => {
const email = (document.getElementById('dionEmail') as HTMLInputElement).value.trim();
const password = (document.getElementById('dionPassword') as HTMLInputElement).value;
const status = document.getElementById('dionAccountStatus')!;
try {
await window.bridge.setDionCredentials(email, password);
closeDionAccount();
} catch {
status.textContent = 'Failed to save the credentials.';
}
});
}
async function openDionAccount(): Promise<void> {
const status = document.getElementById('dionAccountStatus')!;
status.textContent = '';
document.getElementById('dionAccountPopup')!.classList.add('visible');
try {
const credentials = await window.bridge.getDionCredentials();
(document.getElementById('dionEmail') as HTMLInputElement).value = credentials.email;
(document.getElementById('dionPassword') as HTMLInputElement).value = credentials.password;
} catch {
status.textContent = 'Failed to read the session file.';
}
}
function closeDionAccount(): void {
document.getElementById('dionAccountPopup')!.classList.remove('visible');
}
function bindErrorPopup(): void {
document.getElementById('errorPopup')!.addEventListener('click', closeError);
document.querySelector('#errorPopup .popup')!.addEventListener('click', (event) => event.stopPropagation());
@@ -189,6 +224,7 @@ function init(): void {
bindToolbarEvents();
bindActionBarEvents();
bindSettingsEvents();
bindDionAccountEvents();
bindErrorPopup();
bindLogEvents();
bindHeadlessEvents();
+18
View File
@@ -71,6 +71,22 @@ export interface UpstreamProxy {
pass: string;
}
export interface CookieEntry {
name: string;
value: string;
}
export interface CookieFileContent {
email?: string;
password?: string;
cookies: CookieEntry[];
}
export interface DionCredentials {
email: string;
password: string;
}
export interface TabConfig {
mode: TunnelMode;
peerId: number;
@@ -153,6 +169,8 @@ export interface Bridge {
setUpstreamProxy(proxy: UpstreamProxy): Promise<void>;
setDebugLogging(enabled: boolean): Promise<void>;
clearCookies(platform: string): Promise<number>;
getDionCredentials(): Promise<DionCredentials>;
setDionCredentials(email: string, password: string): Promise<void>;
onCreateBotTab(cb: (data: BotTabData) => void): void;
getCallCreatorCode(scriptFile: string): Promise<string>;
onBotError(cb: (msg: string) => void): void;