Skip to content

Commit

Permalink
Support multiple languages in obfuscator
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewtelnov committed Nov 16, 2024
1 parent f4e6ef4 commit 28fe81a
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions utils/json_obfuscator.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
const Survey = require("../build/survey-core/survey.core");

// eslint-disable-next-line no-undef
const fs = require("fs");
// eslint-disable-next-line no-undef
const path = require("path");

const Survey = require("../build/survey-core/survey.core");
// eslint-disable-next-line no-undef
let args = process.argv;
if(!Array.isArray(args)) return;
Expand Down Expand Up @@ -45,7 +46,7 @@ function obfuscateJSON(data) {
const propsToObs = ["title", "description", "requiredErrorText"];
containers.forEach(container => obfuscatePropsText(container, propsToObs));

let questions = model.getAllQuestions();
let questions = model.getAllQuestions(false, true, false);
questions.forEach( q => {
if(q.getType() === "html") {
q.delete();
Expand All @@ -56,7 +57,7 @@ function obfuscateJSON(data) {
obfuscateArrayText(q[name]);
});
});
questions = model.getAllQuestions();
questions = model.getAllQuestions(false, true, false);
const qNames = [];
index = 0;
questions.forEach(q => {
Expand All @@ -76,19 +77,34 @@ function obfuscateJSON(data) {
function obfuscatePropsText(el, props) {
props.forEach(
prop => {
if(!!el[prop]) el[prop] = obfuscateText(el[prop]);
let isDone = false;
const loc = el["loc" + prop[0].toUpperCase() + prop.substring(1)];
if(!!loc && !loc.isEmpty) {
data = loc.getJson();
if(!!data && typeof data === "object") {
for(let key in data) {
data[key] = obfuscateText(data[key]);
}
loc.setJson(data);
isDone = true;
}
}
if(!isDone && !!el[prop]) el[prop] = obfuscateText(el[prop]);
}
);
}
function obfuscateArrayText(items) {
if(Array.isArray(items)) {
items.forEach(item => {
obfuscatePropsText(item, ["text", "title"]);
/*
if(item.text) {
item.text = obfuscateText(item.text);
}
if(item.title) {
item.title = obfuscateText(item.title);
}
*/
});
}
}
Expand Down

0 comments on commit 28fe81a

Please sign in to comment.