added email verification
This commit is contained in:
+33
-83
@@ -1,3 +1,7 @@
|
||||
let backupDirId = '';
|
||||
let shareDirId = '';
|
||||
let departmentDirId = '';
|
||||
|
||||
document.addEventListener('DOMContentLoaded', async function () {
|
||||
setInterval(loadReceivedFiles, 3000); // Call loadReceivedFiles every 3000 ms (3 seconds)
|
||||
|
||||
@@ -47,16 +51,15 @@ async function initialSetup(){
|
||||
}
|
||||
|
||||
async function restoreBackup() {
|
||||
const backupDirectory = await window.electronAPI.readApplicationInfo('backupDirectory');
|
||||
const backupDirectory = await window.databaseAPI.isBackupSet();
|
||||
|
||||
if (backupDirectory && backupDirectory.path) {
|
||||
// If backup directory is already set, display an alert
|
||||
await window.electronAPI.showAlert('You have already set a backup directory. You cannot restore again.');
|
||||
if (backupDirectory) {
|
||||
await window.uiAPI.showAlert('You have already set a backup directory. You cannot restore again.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Prompt the user to choose the destination for the restored backup
|
||||
const destinationPath = await window.electronAPI.selectDirectory();
|
||||
const destinationPath = await window.uiAPI.selectDirectory();
|
||||
if (!destinationPath) {
|
||||
return; // User canceled the directory selection
|
||||
}
|
||||
@@ -69,26 +72,31 @@ async function restoreBackup() {
|
||||
}
|
||||
|
||||
async function checkAndSetAllDirectories() {
|
||||
await attachNotificationButton('backupDirectory', 'Set your backup directory!', 'backup_alert', 'alert');
|
||||
await attachNotificationButton('shareDirectory', 'Set your share directory!', 'share_alert', 'alert');
|
||||
await attachNotificationButton('departmentDirectory', 'Set your department directory!', 'department_alert', 'alert');
|
||||
const directorySchemes = await window.databaseAPI.getLocalResources();
|
||||
|
||||
backupDirId = directorySchemes.backup.id;
|
||||
shareDirId = directorySchemes.shared.id;
|
||||
departmentDirId = directorySchemes.department.id;
|
||||
|
||||
await attachNotificationButton(backupDirId, 'Set your backup directory!', 'backup_alert', 'alert');
|
||||
await attachNotificationButton(shareDirId, 'Set your share directory!', 'share_alert', 'alert');
|
||||
await attachNotificationButton(departmentDirId, 'Set your department directory!', 'department_alert', 'alert');
|
||||
}
|
||||
|
||||
async function checkPathExistence(pathKey) {
|
||||
return await window.electronAPI.readApplicationInfo(pathKey);
|
||||
async function checkPathExistence(id) {
|
||||
const dirInfo = await window.databaseAPI.getDirectoryInfo(id);
|
||||
return dirInfo.path !== ''
|
||||
}
|
||||
|
||||
async function setPath(pathKey) {
|
||||
const path = await window.electronAPI.selectDirectory();
|
||||
if (path === undefined) return;
|
||||
async function setPath(id){
|
||||
const path = await window.uiAPI.selectDirectory();
|
||||
if (path === undefined) return false;
|
||||
|
||||
const id = await window.electronAPI.createMemoryEntry()
|
||||
console.log({id, path})
|
||||
await window.electronAPI.writeApplicationInfo(pathKey, {id, path});
|
||||
return await window.databaseAPI.writeDirectoryPath(id, path);
|
||||
}
|
||||
|
||||
async function attachNotificationButton(pathKey, buttonText, buttonId, buttonName) {
|
||||
const path = await checkPathExistence(pathKey);
|
||||
async function attachNotificationButton(entryId, buttonText, buttonId, buttonName) {
|
||||
const path = await checkPathExistence(entryId);
|
||||
if (!path) {
|
||||
const notificationsDiv = document.getElementById('notifications');
|
||||
const button = document.createElement('button');
|
||||
@@ -97,8 +105,7 @@ async function attachNotificationButton(pathKey, buttonText, buttonId, buttonNam
|
||||
button.name = buttonName;
|
||||
button.textContent = buttonText;
|
||||
button.addEventListener('click', async function () {
|
||||
await setPath(pathKey);
|
||||
button.remove(); // Remove button after setting the path
|
||||
if(await setPath(entryId)) button.remove();
|
||||
});
|
||||
notificationsDiv.appendChild(button);
|
||||
}
|
||||
@@ -108,7 +115,7 @@ async function fetchUserInfo() {
|
||||
const usernameField = document.getElementById('username-field');
|
||||
|
||||
// Read the user credentials from the userConfig
|
||||
let userInfo = await window.electronAPI.readUserConfig('user_info');
|
||||
let userInfo = await window.databaseAPI.getUserInfo();
|
||||
if (userInfo && userInfo.name) {
|
||||
usernameField.textContent = userInfo.name;
|
||||
return;
|
||||
@@ -116,7 +123,7 @@ async function fetchUserInfo() {
|
||||
|
||||
// Update the greeting with the fetched user's name
|
||||
if (usernameField) {
|
||||
usernameField.textContent = userInfo.name; // Update the h1 with the user's name
|
||||
usernameField.textContent = userInfo.name;
|
||||
} else {
|
||||
console.error("Username field is not available in the DOM.");
|
||||
}
|
||||
@@ -124,29 +131,14 @@ async function fetchUserInfo() {
|
||||
|
||||
async function loadReceivedFiles() {
|
||||
// Read the shareDirectory from applicationInfo
|
||||
const shareDirectoryData = await window.electronAPI.readApplicationInfo('shareDirectory');
|
||||
|
||||
if (!shareDirectoryData || !shareDirectoryData.id) {
|
||||
console.log('No received files or directory ID found.');
|
||||
return;
|
||||
}
|
||||
|
||||
const directoryId = shareDirectoryData.id;
|
||||
|
||||
// Fetch the directory structure (JSON objects with user names and file paths)
|
||||
const directoryStructure = await window.electronAPI.readMemoryEntry(directoryId);
|
||||
|
||||
if (!directoryStructure || !directoryStructure.structure) {
|
||||
console.log('No received files found in the directory structure.');
|
||||
return;
|
||||
}
|
||||
const shareDirData = await window.databaseAPI.getDirectoryInfo(shareDirId);
|
||||
|
||||
const notificationsDiv = document.getElementById('notifications');
|
||||
const existingButtons = Array.from(notificationsDiv.children).map(button => button.getAttribute('data-filepath'));
|
||||
|
||||
// Iterate over each user and their files in the structure
|
||||
Object.keys(directoryStructure.structure).forEach(userName => {
|
||||
const userFiles = directoryStructure.structure[userName];
|
||||
Object.keys(shareDirData.structure).forEach(userName => {
|
||||
const userFiles = shareDirData.structure[userName];
|
||||
|
||||
// Iterate over each file of the user
|
||||
Object.keys(userFiles).forEach(fileName => {
|
||||
@@ -166,56 +158,14 @@ async function loadReceivedFiles() {
|
||||
});
|
||||
}
|
||||
|
||||
async function removeReceivedFile(filePath) {
|
||||
// Read the shareDirectory from applicationInfo
|
||||
const shareDirectoryData = await window.electronAPI.readApplicationInfo('shareDirectory');
|
||||
|
||||
if (!shareDirectoryData || !shareDirectoryData.id) {
|
||||
console.log('No directory ID found to update.');
|
||||
return;
|
||||
}
|
||||
|
||||
const directoryId = shareDirectoryData.id;
|
||||
|
||||
// Fetch the directory structure
|
||||
let directoryStructure = await window.electronAPI.readMemoryEntry(directoryId);
|
||||
|
||||
if (directoryStructure && directoryStructure.structure) {
|
||||
// Iterate over each user and their files
|
||||
for (let userName in directoryStructure.structure) {
|
||||
let userFiles = directoryStructure.structure[userName];
|
||||
|
||||
// Check if the file exists and remove it
|
||||
if (userFiles[filePath]) {
|
||||
delete userFiles[filePath];
|
||||
|
||||
// Remove the user if no more files are left
|
||||
if (Object.keys(userFiles).length === 0) {
|
||||
delete directoryStructure.structure[userName];
|
||||
}
|
||||
|
||||
// Update the directory structure in memory
|
||||
await window.electronAPI.updateMemoryEntry(directoryId, directoryStructure);
|
||||
console.log(`File ${filePath} removed from memory.`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
console.log('No directory structure found in memory to update.');
|
||||
}
|
||||
}
|
||||
|
||||
async function handleFileReceivedButtonPressed(filePath, button) {
|
||||
console.log('Notification button clicked!');
|
||||
|
||||
// Open the file in the file explorer
|
||||
await window.electronAPI.showFileInExplorer(filePath)
|
||||
await window.uiAPI.showFileInExplorer(filePath)
|
||||
.then(() => console.log('File explorer opened for: ' + filePath))
|
||||
.catch(error => console.error('Error opening file explorer:', error));
|
||||
|
||||
// Remove the button after opening the file
|
||||
button.remove();
|
||||
|
||||
// Remove the file from memory
|
||||
await removeReceivedFile(filePath);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user