Update v1.1.1-beta1
This commit is contained in:
@@ -3,49 +3,65 @@ const chokidar = require('chokidar');
|
||||
const fs = require('fs');
|
||||
const { logger, ErrorLogger, logRequestInfo } = require('../config/logs');
|
||||
|
||||
// Define file paths
|
||||
const userFilePath = path.resolve(__dirname, '../data/user.json');
|
||||
const setupFilePath = path.resolve(__dirname, '../data/setup.json');
|
||||
const collaborationFilePath = path.resolve(__dirname, '../data/collaboration.json');
|
||||
|
||||
let userData, setupData;
|
||||
// Initialize data objects
|
||||
let userData, setupData, collaborationData;
|
||||
|
||||
// Load initial user data
|
||||
try {
|
||||
userData = JSON.parse(fs.readFileSync(userFilePath, 'utf-8'));
|
||||
} catch (error) {
|
||||
ErrorLogger.error(`Error parsing user.json: ${error}`);
|
||||
}
|
||||
|
||||
// Load initial setup data
|
||||
try {
|
||||
setupData = JSON.parse(fs.readFileSync(setupFilePath, 'utf-8'));
|
||||
} catch (error) {
|
||||
ErrorLogger.error(`Error parsing setup.json: ${error}`);
|
||||
}
|
||||
|
||||
const watcher = chokidar.watch([userFilePath, setupFilePath], {
|
||||
// Load initial collaboration data
|
||||
try {
|
||||
collaborationData = JSON.parse(fs.readFileSync(collaborationFilePath, 'utf-8'));
|
||||
} catch (error) {
|
||||
ErrorLogger.error(`Error parsing collaboration.json: ${error}`);
|
||||
}
|
||||
|
||||
// Set up file watcher
|
||||
const watcher = chokidar.watch([userFilePath, setupFilePath, collaborationFilePath], {
|
||||
persistent: true
|
||||
});
|
||||
|
||||
// Handle file changes
|
||||
watcher.on('change', (filePath) => {
|
||||
let modifiedFile;
|
||||
if (filePath === userFilePath) {
|
||||
try {
|
||||
|
||||
try {
|
||||
if (filePath === userFilePath) {
|
||||
userData = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
||||
modifiedFile = 'user.json';
|
||||
} catch (error) {
|
||||
logger.error(`Error parsing user.json: ${error}`);
|
||||
}
|
||||
} else if (filePath === setupFilePath) {
|
||||
try {
|
||||
} else if (filePath === setupFilePath) {
|
||||
setupData = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
||||
modifiedFile = 'setup.json';
|
||||
} catch (error) {
|
||||
logger.error(`Error parsing setup.json: ${error}`);
|
||||
} else if (filePath === collaborationFilePath) {
|
||||
collaborationData = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
||||
modifiedFile = 'collaboration.json';
|
||||
}
|
||||
|
||||
logger.info(`File ${modifiedFile} has been modified`);
|
||||
} catch (error) {
|
||||
ErrorLogger.error(`Error parsing ${modifiedFile}: ${error}`);
|
||||
}
|
||||
|
||||
logger.info(`File ${modifiedFile} has been modified`);
|
||||
});
|
||||
|
||||
// Export data access functions
|
||||
module.exports = {
|
||||
getUserData: () => Promise.resolve(userData),
|
||||
getSetupData: () => Promise.resolve(setupData)
|
||||
getSetupData: () => Promise.resolve(setupData),
|
||||
getCollaborationData: () => Promise.resolve(collaborationData)
|
||||
};
|
||||
Reference in New Issue
Block a user