Skip to content

Commit

Permalink
**Fix Linux and Mac Image path parse failed.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuzhuyule committed Feb 2, 2018
1 parent d7dff45 commit d8d9731
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions views/main/hexo-image.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,27 @@ class ImgManager {
mkdirsSync(dirpath, mode) {
try{
if (!fs.existsSync(dirpath)) {
var pathtmp;
if (dirpath.endsWith(path.sep))
dirpath = dirpath.slice(0, dirpath.length - 1);
var pathtmp = '';
var perPath = '';
dirpath.split(path.sep).forEach(function (dirname) {
perPath = pathtmp;
dirname = (dirname == ''? '/':dirname);
if (pathtmp) {
pathtmp = path.join(pathtmp, dirname);
}
else {
} else {
pathtmp = dirname;
}

if (fs.existsSync(pathtmp)) {
fs.accessSync(pathtmp, fs.constants.R_OK | fs.constants.W_OK);
}else
if (!fs.mkdirSync(pathtmp, mode)) {
if (!fs.existsSync(pathtmp)) {
if(perPath && fs.existsSync(perPath)){
fs.accessSync(perPath, fs.constants.R_OK | fs.constants.W_OK);
if (!fs.mkdirSync(pathtmp, mode)) {
return false;
}
} else {
return false;
}
}
});
}
Expand Down Expand Up @@ -254,8 +261,14 @@ class ImgManager {

uploadLocalSrc() {
let arr = [];
let reg;
if (process.platform == 'win32')
reg = /^file:\/\/\//;
else
reg = /^file:\/\//;

document.querySelector('#right-panel').querySelectorAll('img[localimg="true"]').forEach((item) => {
let filePath = decodeURI(item.src).replace(/^file:\/\/\//, '');
let filePath = decodeURI(item.src).replace(reg, '');
if (fs.existsSync(filePath)) {
arr.push(filePath);
}
Expand Down

0 comments on commit d8d9731

Please sign in to comment.