Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 = {};
for (const item of imgObj) {
if (item.imgUrl === imgArr[idx]) {
curImgObj = item;
}
}
const reg = new RegExp(imgArr[idx], 'g');
if (!curImgObj.imgPath) {
await downloadImg(imgArr[idx], imgPathItem);
let newImgUrl = '';
if (option.config && option.config.uploadUrl !== '') {
const udata = await uploadData(
imgPathItem,
`imgcook-cli/${temporaryImages}/`,
option.config
);
fileValue = fileValue.replace(reg, udata.url);
newImgUrl = udata.url;
} else if (
option.moduleData &&
option.moduleData.dsl === 'react-taobao-standard'
) {
// 如果在 react 标准下引用本地路径图片,使用 require 引用
const regex = new RegExp(`"${imgArr[idx]}"`, 'g');
fileValue = fileValue.replace(
const request = require('request');
const fs = require('fs');
const chalk = require('chalk');
const ora = require('ora');
const childProcess = require('child_process');
const spinner = ora();
const domain = 'https://www.imgcook.com';
const { homedir } = require('@imgcook/cli-utils');
const userhome = homedir();
const imgcookConfigPath = `${userhome}/.imgcook`;
const imgcookRc = `${imgcookConfigPath}/.imgcookrc`;
const imgcookModules = `${imgcookConfigPath}/imgcook_modules`;
const cliConfig = {
path: imgcookConfigPath,
configFile: imgcookRc,
imgcookModules,
module: {
url: `${domain}/api-open/code-acquire`
}
};
// Post request
const ajaxPost = (url, param) => {
return new Promise(resolve => {
request.post(
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 = {};