Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
throw new Error('Only a webview can have its storage wiped');
}
logger.log(`Deleting session data for account "${accountId}"...`);
await clearStorage(webviewWebcontent.session);
logger.log(`Deleted session data for account "${accountId}".`);
} catch (error) {
logger.error(`Failed to delete session data for account "${accountId}", reason: "${error.message}".`);
}
// Delete the webview partition
// Note: The first account always uses the default session,
// therefore partitionId is optional
// ToDo: Move the first account to a partition
if (partitionId) {
try {
if (!ValidationUtil.isUUIDv4(partitionId)) {
throw new Error('Partition is not an UUID');
}
const partitionDir = path.join(USER_DATA_DIR, 'Partitions', partitionId);
await fs.remove(partitionDir);
logger.log(`Deleted partition "${partitionId}" for account "${accountId}".`);
} catch (error) {
logger.log(`Unable to delete partition "${partitionId}" for account "${accountId}", reason: "${error.message}".`);
}
}
// Delete logs for this account
try {
if (!ValidationUtil.isUUIDv4(accountId)) {
throw new Error('Account is not an UUID');
}
const sessionFolder = path.join(LOG_DIR, accountId);
if (partitionId) {
try {
if (!ValidationUtil.isUUIDv4(partitionId)) {
throw new Error('Partition is not an UUID');
}
const partitionDir = path.join(USER_DATA_DIR, 'Partitions', partitionId);
await fs.remove(partitionDir);
logger.log(`Deleted partition "${partitionId}" for account "${accountId}".`);
} catch (error) {
logger.log(`Unable to delete partition "${partitionId}" for account "${accountId}", reason: "${error.message}".`);
}
}
// Delete logs for this account
try {
if (!ValidationUtil.isUUIDv4(accountId)) {
throw new Error('Account is not an UUID');
}
const sessionFolder = path.join(LOG_DIR, accountId);
await fs.remove(sessionFolder);
logger.log(`Deleted logs folder for account "${accountId}".`);
} catch (error) {
logger.error(`Failed to delete logs folder for account "${accountId}", reason: "${error.message}".`);
}
}
const getWebViewId = (contents: WebContents): string | undefined => {
try {
const currentLocation = new URL(contents.getURL());
const webViewId = currentLocation.searchParams.get('id');
return webViewId && ValidationUtil.isUUIDv4(webViewId) ? webViewId : undefined;
} catch (error) {
return undefined;
}
};