From 0348e83ffe91c52b79ad651a0952c7e82414b58b Mon Sep 17 00:00:00 2001 From: Sandro642 Date: Sun, 27 Oct 2024 10:45:45 +0100 Subject: [PATCH] Refactor Athena's Shield configuration handling --- app/assets/athshield/variables.athshield | 5 --- .../athshield.js => extraverif/extraverif.js} | 40 ++++++------------- .../parserExtraverif.js} | 13 ++---- app/assets/extraverif/variables.json | 5 +++ 4 files changed, 21 insertions(+), 42 deletions(-) delete mode 100644 app/assets/athshield/variables.athshield rename app/assets/{athshield/athshield.js => extraverif/extraverif.js} (51%) rename app/assets/{athshield/parserAthShield.js => extraverif/parserExtraverif.js} (53%) create mode 100644 app/assets/extraverif/variables.json diff --git a/app/assets/athshield/variables.athshield b/app/assets/athshield/variables.athshield deleted file mode 100644 index b7c29b1a..00000000 --- a/app/assets/athshield/variables.athshield +++ /dev/null @@ -1,5 +0,0 @@ -{ - "athenaShieldActivated": false, - "menuVisibility": "visible", - "debug": "false" -} \ No newline at end of file diff --git a/app/assets/athshield/athshield.js b/app/assets/extraverif/extraverif.js similarity index 51% rename from app/assets/athshield/athshield.js rename to app/assets/extraverif/extraverif.js index 15b7764c..5f285b3b 100644 --- a/app/assets/athshield/athshield.js +++ b/app/assets/extraverif/extraverif.js @@ -2,75 +2,62 @@ const fs = require('fs') const readline = require('readline') const path = require('path') -// Path to the configuration file -const configPath = path.join(__dirname, 'variables.athshield') +const configPath = path.join(__dirname, 'variables.json') -// Load the variables from the file function loadConfig() { const rawData = fs.readFileSync(configPath) - return JSON.parse(rawData.toString()) // Convert Buffer to string + return JSON.parse(rawData.toString()) } -// Save the variables to the file function saveConfig(config) { const data = JSON.stringify(config, null, 2) fs.writeFileSync(configPath, data) } -// Create the readline interface const rl = readline.createInterface({ input: process.stdin, output: process.stdout }) -// Function to ask questions to the user function startCLI() { const config = loadConfig() - rl.question('Would you like to activate Athena\'s Shield? (yes/no): ', (answer) => { - if (answer.trim().startsWith('//')) { - console.log('This is a comment; the line is ignored.') + rl.question('Would you like to activate extra file verification? (yes/no): ', (answer) => { rl.close() return - } if (answer.toLowerCase() === 'yes') { - config.athenaShieldActivated = true + config.extraFileVerifActivated = true rl.question('Would you like to activate debug mode? (yes/no): ', (debugAnswer) => { - config.debug = debugAnswer.toLowerCase() === 'yes' // Set debug to true or false + config.debug = debugAnswer.toLowerCase() === 'yes' rl.question('Would you like to hide or block the menu? (hide/block): ', (menuAnswer) => { - if (menuAnswer.trim().startsWith('//')) { - console.log('This is a comment; the line is ignored.') rl.close() return - } if (menuAnswer.toLowerCase() === 'hide') { - config.menuVisibility = 'hidden' // Set to 'hidden' - console.log('Athena\'s Shield activated. Menu hidden.') + config.menuVisibility = 'hidden' + console.log('Extra file verification is activated. Menu hidden.') } else if (menuAnswer.toLowerCase() === 'block') { - config.menuVisibility = 'blocked' // Set to 'blocked' - console.log('Athena\'s Shield activated. Menu blocked.') + config.menuVisibility = 'blocked' + console.log('Extra file verification is activated. Menu blocked.') } else { console.log('Invalid option for the menu.') rl.close() return } - // Save the modified configuration saveConfig(config) rl.close() }) }) } else if (answer.toLowerCase() === 'no') { - console.log('Athena\'s Shield not activated. Closing the CLI.') - config.athenaShieldActivated = false - config.menuVisibility = 'visible' // Reset to default - config.debug = 'false' + console.log('Extra file verification is not activated. Closing the CLI.') + config.extraFileVerifActivated = false + config.menuVisibility = 'visible' + config.debug = false - // Save the modified configuration saveConfig(config) rl.close() } else { @@ -80,5 +67,4 @@ function startCLI() { }) } -// Launch the CLI startCLI() diff --git a/app/assets/athshield/parserAthShield.js b/app/assets/extraverif/parserExtraverif.js similarity index 53% rename from app/assets/athshield/parserAthShield.js rename to app/assets/extraverif/parserExtraverif.js index 336e0d4f..43921da3 100644 --- a/app/assets/athshield/parserAthShield.js +++ b/app/assets/extraverif/parserExtraverif.js @@ -1,37 +1,30 @@ const fs = require('fs') const path = require('path') -// Chemin vers le fichier de configuration -const configPath = path.join(__dirname, 'variables.athshield') +const configPath = path.join(__dirname, 'variables.json') -// Classe pour gérer Athena's Shield -class AthenaShield { +class ExtraFileVerification { constructor() { this.config = this.loadConfig() } - // Charger les variables depuis le fichier loadConfig() { const rawData = fs.readFileSync(configPath) return JSON.parse(rawData.toString()) } - // Récupérer le statut d'Athena's Shield get status() { - return this.config.athenaShieldActivated + return this.config.extraFileVerifActivated } - // Récupérer la visibilité du menu get type() { return this.config.menuVisibility } - // Récupérer le mode debug get debug() { return this.config.debug } } -// Exporter une instance de la classe const athenaShieldInstance = new AthenaShield() module.exports = athenaShieldInstance diff --git a/app/assets/extraverif/variables.json b/app/assets/extraverif/variables.json new file mode 100644 index 00000000..42cd8264 --- /dev/null +++ b/app/assets/extraverif/variables.json @@ -0,0 +1,5 @@ +{ + "extraFileVerifActivated": false, + "menuVisibility": "visible", + "debug": "false" +}