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,38 +463,99 @@ 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
function loadXML(xmlFileName) {
//XmlPath get from .env //XmlPath get from .env
const xmlPathenv=configObject.XML_FILE_PATH.trim();
// const xmlPathenv=process.env.XML_FILE_PATH; // const decode = require('./decode');
// Function to load XML from a file
function loadXML(xmlFileName) {
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) => {
var decodeData ="";
var encodedXmlFilePath = `${xmlPath}${xmlFileName}`;
var jsonDecodeData = "";
var jsonFileName = xmlFileName.split('.xml');
var encodedJsonFilePath = `${xmlPath}${jsonFileName[0]}_answer.json`;
// console.log('encodedJsonFilePath', encodedJsonFilePath);
var filelist = findFile(encodedJsonFilePath);
const decode = require('./decode');
if(filelist !== false)
{
//JSON File Read Function
fs.readFile(encodedJsonFilePath, 'utf8', (error, data) => {
if (error) { if (error) {
reject(error); console.error('Error reading file:', error);
} else { } else {
if (isEncrypted === 'YES') { if (isEncrypted === 'YES') {
var decodeData = decode(data);
resolve(decodeData); jsonDecodeData = decode(encodedJsonFilePath);
xml2json(decodeData); 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 { } else {
resolve(data); if (isEncrypted === 'YES') {
xml2json(data); // decrypt function call go to decode.js
decodeData = decode(encodedXmlFilePath);
} else{
decodeData = data;
} }
MathJax.typeset(); 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;
}
}
</script> </script>

View File

@ -1284,23 +1284,23 @@ $('#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');
@ -1312,13 +1312,15 @@ if (event.target.id !== 'workarea_math' && tragetedId == false && hasMLKClass ==
// $('#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,10 +1439,11 @@ 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'); {
const saveButton = document.getElementById('SaveButton');
if (saveButton) { if (saveButton) {
saveButton.click(); saveButton.click();
setTimeout(function() { setTimeout(function() {
@ -1458,10 +1461,11 @@ document.addEventListener('DOMContentLoaded', function () {
}); });
}, 3000); }, 3000);
} }
previewbutton.href = "QuestionPreview.html?filename=" + FileName; previewbutton.href = "QuestionPreview.html?filename=" + FileName;
} else { }
else
const saveButton = document.getElementById('SaveButton'); {
const saveButton = document.getElementById('SaveButton');
if (saveButton) { if (saveButton) {
saveButton.click(); saveButton.click();
setTimeout(function() { setTimeout(function() {
@ -1479,12 +1483,14 @@ document.addEventListener('DOMContentLoaded', function () {
}); });
}, 1000); }, 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()) {
@ -1496,10 +1502,10 @@ function findFile(filePath) {
// 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

@ -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);