crypto error solve : RV

This commit is contained in:
venkateswaran ubuntu 2023-12-08 16:17:03 +05:30
parent 87a9e1eb42
commit 59b93e5c5c
3 changed files with 184 additions and 117 deletions

View File

@ -463,36 +463,97 @@ color: #1d3557 !important;
//Preview edit button //Preview edit button
document.getElementById("editlink").href = "addform.html?filename=" + xmlFileName; document.getElementById("editlink").href = "addform.html?filename=" + xmlFileName;
// Function to load XML from a file //XmlPath get from .env
function loadXML(xmlFileName) {
// const decode = require('./decode');
//XmlPath get from .env // Function to load XML from a file
const xmlPathenv=configObject.XML_FILE_PATH.trim(); function loadXML(xmlFileName) {
// const xmlPathenv=process.env.XML_FILE_PATH; const xmlPathenv=configObject.XML_FILE_PATH.trim();
const xmlPath =path.join(__dirname,xmlPathenv); const xmlPath =path.join(__dirname,xmlPathenv);
// console.log(xmlFileName)
return new Promise((resolve, reject) => { // console.log('xmlFileName', xmlFileName);
fs.readFile(`${xmlPath}`+xmlFileName, 'utf8', (error, data) => {
if (error) { var decodeData ="";
reject(error); var encodedXmlFilePath = `${xmlPath}${xmlFileName}`;
} else {
if (isEncrypted === 'YES') { var jsonDecodeData = "";
var decodeData = decode(data); var jsonFileName = xmlFileName.split('.xml');
resolve(decodeData); var encodedJsonFilePath = `${xmlPath}${jsonFileName[0]}_answer.json`;
xml2json(decodeData);
} else { // console.log('encodedJsonFilePath', encodedJsonFilePath);
resolve(data);
xml2json(data); var filelist = findFile(encodedJsonFilePath);
} const decode = require('./decode');
MathJax.typeset(); if(filelist !== false)
} {
}); //JSON File Read Function
}); fs.readFile(encodedJsonFilePath, 'utf8', (error, data) => {
} if (error) {
console.error('Error reading file:', error);
} else {
if (isEncrypted === 'YES') {
jsonDecodeData = decode(encodedJsonFilePath);
localStorage.setItem('json_Decode_Data_For_Mcq_Crt_Ans', jsonDecodeData);
} else{
jsonDecodeData = data;
localStorage.setItem('json_Decode_Data_For_Mcq_Crt_Ans', jsonDecodeData);
console.log('jsonDecodeData', jsonDecodeData);
}
}
});
}
setTimeout(function() {
fs.readFile(`${xmlPath}${xmlFileName}`, 'utf8', (error, data) => {
if (error) {
console.error('Error reading file:', error);
} else {
if (isEncrypted === 'YES') {
// decrypt function call go to decode.js
decodeData = decode(encodedXmlFilePath);
} else{
decodeData = data;
}
console.log('jsonDecodeData : ', jsonDecodeData);
xml2json(decodeData);
}
});
}, 1000);
}
console.log()
// Function for Finding the JSON File in the folder
function findFile(filePath) {
try {
const stats = fs.statSync(filePath);
if (stats.isFile()) {
// File exists
// console.log(`File found at: ${filePath}`);
return true;
} else {
// console.error(`Path is not a file: ${filePath}`);
return false;
}
} catch (err) {
// console.error(`File not found: ${filePath}`);
return false;
}
}

View File

@ -1284,41 +1284,43 @@ $('#workarea_math').click(function(){
console.log('called'); console.log('called');
$('#workarea_math').css('margin-bottom', '240px'); $('#workarea_math').css('margin-bottom', '240px');
localStorage.setItem('workAreaMath', true); localStorage.setItem('workAreaMath', true);
}); });
$(document).on("click", function (event) { $(document).on("click", function (event) {
// console.log('Clicked element id:', event.target.id); // console.log('Clicked element id:', event.target.id);
// console.log('Clicked element:', event.target); // console.log('Clicked element:', event.target);
const targetElement = event.target; const targetElement = event.target;
var tragetedId = event.target.id.startsWith("ML"); var tragetedId = event.target.id.startsWith("ML");
const classList = Array.from(event.target.classList); const classList = Array.from(event.target.classList);
const hasMLKClass = classList.some(className => className.startsWith("MLK") || className.startsWith("row") || className.startsWith("left") || className.startsWith("ML") || className.startsWith("action")); const hasMLKClass = classList.some(className => className.startsWith("MLK") || className.startsWith("row") || className.startsWith("left") || className.startsWith("ML") || className.startsWith("action"));
const isSvgElement = targetElement.closest('svg') || targetElement.closest('i'); const isSvgElement = targetElement.closest('svg') || targetElement.closest('i');
// console.log('svg',isSvgElement); // console.log('svg',isSvgElement);
// console.log(hasMLKClass); // console.log(hasMLKClass);
if (event.target.id !== 'workarea_math' && tragetedId == false && hasMLKClass == false && isSvgElement == null) { if (event.target.id !== 'workarea_math' && tragetedId == false && hasMLKClass == false && isSvgElement == null) {
// console.log('Inside if'); // console.log('Inside if');
var value = localStorage.getItem('workAreaMath'); var value = localStorage.getItem('workAreaMath');
if (value === 'true') { if (value === 'true') {
// console.log('Value:', value); // console.log('Value:', value);
$('#workarea_math').css('margin-bottom', '0px'); $('#workarea_math').css('margin-bottom', '0px');
localStorage.removeItem('workAreaMath'); localStorage.removeItem('workAreaMath');
} else { } else {
// $('#workarea_math').css('margin-bottom', '190px'); // $('#workarea_math').css('margin-bottom', '190px');
// console.log('Value is not true'); // console.log('Value is not true');
}
} }
}
}); });
var ids = document.getElementById('workarea_math'); var ids = document.getElementById('workarea_math');
//clear the string from the workarea and a fileds
function clearMessage() { function clearMessage() {
var val = document.getElementById('messages') ; var val = document.getElementById('messages') ;
if(val !== null){ if(val !== null){
@ -1437,69 +1439,73 @@ document.addEventListener('DOMContentLoaded', function () {
//EditPreview and Create Preview //EditPreview and Create Preview
var previewbutton = document.getElementById("editPreview"); var previewbutton = document.getElementById("editPreview");
previewbutton.addEventListener("click", async () => { previewbutton.addEventListener("click", async () => {
if (FileName) { if (FileName)
const saveButton = document.getElementById('SaveButton'); {
if (saveButton) { const saveButton = document.getElementById('SaveButton');
saveButton.click(); if (saveButton) {
setTimeout(function() { saveButton.click();
var popupInput = document.getElementById("swal2-input"); setTimeout(function() {
var submitButton = document.querySelector(".swal2-confirm.swal2-styled"); var popupInput = document.getElementById("swal2-input");
submitButton.addEventListener("click", function() { var submitButton = document.querySelector(".swal2-confirm.swal2-styled");
FileName = popupInput.value; submitButton.addEventListener("click", function() {
FileName += ".xml" FileName = popupInput.value;
if(FileName){ FileName += ".xml"
var anchorElement = document.getElementById("editPreview"); if(FileName){
if (anchorElement) { var anchorElement = document.getElementById("editPreview");
anchorElement.click(); if (anchorElement) {
} anchorElement.click();
} }
}); }
}, 3000); });
} }, 3000);
previewbutton.href = "QuestionPreview.html?filename=" + FileName; }
} else { previewbutton.href = "QuestionPreview.html?filename=" + FileName;
}
else
{
const saveButton = document.getElementById('SaveButton');
if (saveButton) {
saveButton.click();
setTimeout(function() {
var popupInput = document.getElementById("swal2-input");
var submitButton = document.querySelector(".swal2-confirm.swal2-styled");
submitButton.addEventListener("click", function() {
FileName = popupInput.value;
FileName += ".xml"
if(FileName){
var anchorElement = document.getElementById("editPreview");
if (anchorElement) {
anchorElement.click();
}
}
});
}, 1000);
}
}
})
const saveButton = document.getElementById('SaveButton');
if (saveButton) {
saveButton.click();
setTimeout(function() {
var popupInput = document.getElementById("swal2-input");
var submitButton = document.querySelector(".swal2-confirm.swal2-styled");
submitButton.addEventListener("click", function() {
FileName = popupInput.value;
FileName += ".xml"
if(FileName){
var anchorElement = document.getElementById("editPreview");
if (anchorElement) {
anchorElement.click();
}
}
});
}, 1000);
}
}
})
// Function for Finding the JSON File in the folder // Function for Finding the JSON File in the folder
function findFile(filePath) { function findFile(filePath) {
try { try {
const stats = fs.statSync(filePath); const stats = fs.statSync(filePath);
if (stats.isFile()) { if (stats.isFile()) {
// File exists // File exists
// console.log(`File found at: ${filePath}`); // console.log(`File found at: ${filePath}`);
return true; return true;
} else { } else {
// console.error(`Path is not a file: ${filePath}`); // console.error(`Path is not a file: ${filePath}`);
return false; return false;
} }
} catch (err) { } catch (err) {
// console.error(`File not found: ${filePath}`); // console.error(`File not found: ${filePath}`);
return false; return false;
} }
} }
@ -1521,7 +1527,7 @@ function loadXML(xmlFileName) {
// console.log('encodedJsonFilePath', encodedJsonFilePath); // console.log('encodedJsonFilePath', encodedJsonFilePath);
var filelist = findFile(encodedJsonFilePath); var filelist = findFile(encodedJsonFilePath);
const decode = require('./decode');
if(filelist !== false) if(filelist !== false)
{ {
//JSON File Read Function //JSON File Read Function

View File

@ -432,9 +432,9 @@ function validateFile(input) {
const allowedExtensions = ["xml"]; const allowedExtensions = ["xml"];
const fileExtension = file.name.split(".").pop().toLowerCase(); const fileExtension = file.name.split(".").pop().toLowerCase();
if (!allowedExtensions.includes(fileExtension)) { if (!allowedExtensions.includes(fileExtension)) {
alert('Invalid file type. Only xml files are allowed.') alert('Invalid file type. Only xml files are allowed.')
input.value = ""; input.value = "";
return; return;
} }
} }
@ -460,19 +460,19 @@ function validateFile(input) {
function downloadFile(filename) { function downloadFile(filename) {
console.log(xmlPath); // console.log(xmlPath);
const xmlFilePath = `${xmlPath}${filename}`; const xmlFilePath = `${xmlPath}${filename}`;
console.log(xmlFilePath) // console.log(xmlFilePath)
const xmlFileNameParts = filename.split('.xml'); const xmlFileNameParts = filename.split('.xml');
const xmlBaseName = xmlFileNameParts[0]; const xmlBaseName = xmlFileNameParts[0];
const jsonFileName = `${xmlBaseName}_answer.json`; const jsonFileName = `${xmlBaseName}_answer.json`;
const jsonFilePath = `${xmlPath}${jsonFileName}`; const jsonFilePath = `${xmlPath}${jsonFileName}`;
console.log(jsonFilePath); // console.log(jsonFilePath);
var fileList = findFile(jsonFilePath); var fileList = findFile(jsonFilePath);
console.log(fileList) // console.log(fileList)
// const downloadsPath = process.env.DOWNLOAD_XML_FILE_PATH; // const downloadsPath = process.env.DOWNLOAD_XML_FILE_PATH;
@ -480,18 +480,18 @@ console.log(fileList)
// const isEncrypted = process.env.ENCRYPTED; // const isEncrypted = process.env.ENCRYPTED;
const downloadsPath = configObject.DOWNLOAD_XML_FILE_PATH.trim(); const downloadsPath = configObject.DOWNLOAD_XML_FILE_PATH.trim();
console.log(downloadsPath,'downloadpath'); // console.log(downloadsPath,'downloadpath');
const isEncrypted = configObject.ENCRYPTED.trim(); const isEncrypted = configObject.ENCRYPTED.trim();
const filePathToSave = path.join(downloadsPath, filename); const filePathToSave = path.join(downloadsPath, filename);
const jsonFilePathToSave = path.join(downloadsPath, jsonFileName); const jsonFilePathToSave = path.join(downloadsPath, jsonFileName);
console.log(filePathToSave); // console.log(filePathToSave);
console.log(jsonFilePathToSave); // console.log(jsonFilePathToSave);
if(isEncrypted == 'YES'){ if(isEncrypted == 'YES'){
console.log('isEncrypted'); // console.log('isEncrypted');
// XML File // XML File
@ -510,7 +510,7 @@ if(fileList !== false)
} }
else{ else{
console.log('isEncrypted NOT'); // console.log('isEncrypted NOT');
// //Download XML FIle // //Download XML FIle
// console.log(xmlFilePath); // console.log(xmlFilePath);