Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const loader = async (fileValue, option) => {
let imgArr = [];
const { filePath, index } = option;
const temporaryImages = `${(
new Date().getTime() + Math.floor(Math.random() * 10000)
).toString(30)}`;
imgArr = fileValue.match(
/(https?):\/\/[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|](\.png|\.jpg)/g
);
if (imgArr && imgArr.length > 0) {
imgArr = unique(imgArr);
const imgPath = `${filePath}/images`;
let imgObj = [];
const imgrc = `${imgPath}/.imgrc`;
if (fs.existsSync(imgrc)) {
let imgConfig = fs.readFileSync(imgrc, 'utf8');
imgObj = JSON.parse(imgConfig) || [];
}
for (let idx = 0; idx < imgArr.length; idx++) {
if (!fs.existsSync(imgPath)) {
fs.mkdirSync(imgPath);
}
let suffix = imgArr[idx].split('.');
suffix = suffix[suffix.length - 1];
const imgName = `img_${option.moduleData.id}_${index}_${idx}.${suffix}`;
const imgPathItem = `${imgPath}/${imgName}`;
let curImgObj = {};