Preserve accumulated client implementation since v0.1.4, including local identities, multi-server state, chat, administration, audio and streaming controls. Refine official-source layout, original artwork, responsive composer overflow, settings navigation and chat scroll anchoring. Current verification: Node suite passes; isolated packaged chat and responsive control smokes pass without device capture. Native core is reused, not rebuilt in this pass. Strict whole-screen visual parity remains incomplete; no 1:1 or cross-platform acceptance claim. Local checkpoint only; no release or push.
89 lines
4.1 KiB
JavaScript
89 lines
4.1 KiB
JavaScript
'use strict';
|
|
|
|
const path = require('node:path');
|
|
const fs = require('node:fs');
|
|
|
|
/**
|
|
* Local recording, main side: the output folder is chosen only through the native folder dialog (official
|
|
* "Select Recording Folder") and kept in the main-owned pref `recordingFolder`. The renderer can never set
|
|
* that pref or name another folder: `recording_start` is accepted only for exactly the approved folder
|
|
* (see `approvedRecordingDirectory`, used by ipc-validate).
|
|
*
|
|
* Offscreen tests never open a dialog: with TEAMSPEACH_TEST_OFFSCREEN the folder comes from
|
|
* TEAMSPEACH_TEST_RECORDING_DIR, which must lie inside the disposable test profile.
|
|
*/
|
|
|
|
const MAX_TITLE = 200;
|
|
|
|
function within(child, parent) {
|
|
const rel = path.relative(parent, child);
|
|
return rel !== '' && !rel.startsWith('..') && !path.isAbsolute(rel);
|
|
}
|
|
|
|
function validFolder(value) {
|
|
return typeof value === 'string' && value.length >= 1 && value.length <= 1024 && path.isAbsolute(value) && !/[\u0000-\u001f\u007f]/.test(value);
|
|
}
|
|
|
|
/** The folder `recording_start` may write to, or null. */
|
|
function approvedRecordingDirectory(prefs) {
|
|
const dir = prefs.get().recordingFolder;
|
|
return validFolder(dir) ? dir : null;
|
|
}
|
|
|
|
/**
|
|
* @param {object} o
|
|
* @param {Electron.IpcMain} o.ipcMain
|
|
* @param {(event) => boolean} o.trustedSender
|
|
* @param {Electron.Dialog} o.dialog
|
|
* @param {() => Electron.BrowserWindow | null} o.getWindow
|
|
* @param {boolean} o.testOffscreen
|
|
* @param {string | null} o.testProfileDir absolute disposable profile dir in offscreen tests
|
|
* @param {{ get(): object, set(partial: object): object }} o.prefs
|
|
*/
|
|
function registerRecordingIpc({ ipcMain, trustedSender, dialog, getWindow, testOffscreen, testProfileDir, prefs }) {
|
|
ipcMain.handle('recording:pick-folder', async (event, title) => {
|
|
if (!trustedSender(event)) return { ok: false, error: { code: 'forbidden', message: 'forbidden' } };
|
|
let picked = null;
|
|
if (testOffscreen) {
|
|
const fixture = process.env.TEAMSPEACH_TEST_RECORDING_DIR;
|
|
if (!validFolder(fixture) || !testProfileDir || !within(path.resolve(fixture), path.resolve(testProfileDir))) {
|
|
return { ok: false, error: { code: 'unavailable', message: 'Folder dialogs are disabled in offscreen tests' } };
|
|
}
|
|
picked = path.resolve(fixture);
|
|
try {
|
|
const profile = await fs.promises.realpath(testProfileDir);
|
|
let current = path.resolve(testProfileDir);
|
|
for (const component of path.relative(current, picked).split(path.sep)) {
|
|
current = path.join(current, component);
|
|
let stat;
|
|
try { stat = await fs.promises.lstat(current); }
|
|
catch (error) { if (error.code !== 'ENOENT') throw error; await fs.promises.mkdir(current); stat = await fs.promises.lstat(current); }
|
|
if (stat.isSymbolicLink() || !stat.isDirectory() || !within(await fs.promises.realpath(current), profile)) throw new Error('unsafe fixture path');
|
|
}
|
|
} catch {
|
|
return { ok: false, error: { code: 'unavailable', message: 'Recording fixture must stay inside the disposable profile' } };
|
|
}
|
|
} else {
|
|
const options = {
|
|
title: typeof title === 'string' && title.length <= MAX_TITLE && !/[\u0000-\u001f]/.test(title) ? title : undefined,
|
|
properties: ['openDirectory', 'createDirectory', 'dontAddToRecent'],
|
|
};
|
|
const current = approvedRecordingDirectory(prefs);
|
|
if (current) options.defaultPath = current;
|
|
const win = getWindow();
|
|
const result = win ? await dialog.showOpenDialog(win, options) : await dialog.showOpenDialog(options);
|
|
if (result.canceled || !result.filePaths?.length) return { ok: true, path: null };
|
|
picked = path.resolve(result.filePaths[0]);
|
|
}
|
|
if (!validFolder(picked)) return { ok: false, error: { code: 'bad_request', message: 'Folder path is not usable' } };
|
|
try {
|
|
prefs.set({ recordingFolder: picked });
|
|
} catch (err) {
|
|
return { ok: false, error: { code: 'io', message: String(err?.message ?? err) } };
|
|
}
|
|
return { ok: true, path: picked };
|
|
});
|
|
}
|
|
|
|
module.exports = { registerRecordingIpc, approvedRecordingDirectory, validFolder };
|