Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
entry.should.have.property('imageurl');
entry.should.have.property('slug');
entry.should.not.have.property('localimage');
// TODO: deal with urls that do not parse
const imageUrl = url.parse(entry.imageurl);
const imageFilename = imageUrl.pathname.split('/').pop();
// TODO: figure out if this is the safest way to construct local image paths
// Construct the local image path
const localPath = `${hexo.config.source_dir}/images/${entry.slug}_${imageFilename}`;
const relativeUrl = `/images/${entry.slug}_${imageFilename}`;
// stat each image as a jpg, then as png, see if it exists
try {
fs.statSync(localPath);
// if exists, add localimage to entry
entry['localimage'] = relativeUrl;
} catch (error) {
// Do nothing! Pass the entry through
}
});
resolve(entries);
file.stat((err, fileStats) => {
if (err) return callback(err);
fileStats.should.eql(fs.statSync(file.source));
callback();
});
});
return new Promise((resolve, reject) => {
cos.putObject({
Bucket: config.bucket,
Region: config.region,
Key: file,
Body: fs.createReadStream(filePath),
ContentLength: fs.statSync(filePath).size,
onProgress: function (progressData) {
//console.log(JSON.stringify(progressData));
},
}, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
})
})
}
files.forEach(function (filePath) {
var absPath = pathFn.join(dir, filePath),
stat = fs.statSync(absPath);
if (stat.isDirectory()) {
traverseFiles(absPath, handle);
} else {
handle(absPath);
}
});
}
function loadYAMLFile(file) {
if (!file) return loadsh.extend({}, defConfig);
file = file.toString().replace(/\\+/g, '\\\\');
if (!fs.existsSync(file)) return {};
var configPath = file;
if (fs.statSync(file).isDirectory()) {
configPath = (path.join(file, '_config.yml'));
}
var baseDir = path.dirname(configPath);
var config = fs.existsSync(configPath) ? YAML.parse(fs.readFileSync(configPath).toString()) : {};
defConfig.__basedir = baseDir;
var themeConfig = {};
if (config.theme) {
defConfig.__themedir = path.join( baseDir,'themes',config.theme);
configPath = path.join( defConfig.__themedir,'_config.yml');
themeConfig = fs.existsSync(configPath) ? YAML.parse(fs.readFileSync(configPath).toString()) : {};
}
return loadsh.extend({}, defConfig, config, themeConfig);
}
return new Promise(function (resolve) {
if (fs.existsSync(baseDir) && fs.statSync(baseDir).isFile()) {
fs.unlinkSync(baseDir);
}
if (!fs.existsSync(baseDir)) {
log.info('检测到这是您第一次使用feflow,即将进行cli client初始化');
fs.ensurePathSync(baseDir);
}
log.debug('.feflow 目录已经创建');
resolve(ctx);
});
}
File.prototype.statSync = function(options) {
return statSync(this.source);
};
module.exports = function listFiles (dirPath) {
const lsDir = fs.readdirSync(dirPath);
const filesArr = [];
for (const fileName of lsDir) {
const pathName = path.join(dirPath, fileName);
if (fs.statSync(pathName).isDirectory()) {
filesArr.push(...listFiles(pathName));
} else {
filesArr.push(pathName);
}
}
return filesArr;
};