diff --git a/app/moe-l10n.js b/app/moe-l10n.js index 55a42cd..3e9c920 100644 --- a/app/moe-l10n.js +++ b/app/moe-l10n.js @@ -80,11 +80,15 @@ class MoeditorLocale { get(str) { let res; - if (typeof strings[this.locale] === 'undefined' || typeof strings[this.locale][str] === 'undefined') { - res = strings['en'][str] || str; - console.log('Localization of "' + str + '" in "' + this.locale + '" failed, falling back to English.'); + if (typeof strings[this.locale] == 'undefined' || typeof strings[this.locale][str] == 'undefined') { + res = strings['en'][str]; + if (!res || res == undefined ) + res = str; + // console.log('Localization of "' + str + '" in "' + this.locale + '" failed, falling back to English.'); } else { res = strings[this.locale][str]; + if (!res || res == undefined ) + res = str; } return res; } @@ -234,6 +238,7 @@ const strings = { "UploadToCOS": "Upload To COS", "UploadToSMMS": "Upload To SM.MS", "UploadToQiNiu": "Upload To QiNiu", + "UndoUpload": "Undo Uploaded", "Quick Open":"Quick Open", "OpenPathPost":"Open Post Path", "OpenPathPostSrc":"Open Post Src Path", @@ -408,6 +413,7 @@ const strings = { "UploadToCOS": "上传 腾讯云", "UploadToSMMS": "上传 SM.MS", "UploadToQiNiu": "上传 七牛", + "UndoUpload": "撤销上传", "Quick Open":"快速打开", "OpenPathPost":"本文所在路径", "OpenPathPostSrc":"本文图片路径", diff --git a/app/tool/hexo-cos.js b/app/tool/hexo-cos.js index 8c952cf..d1f72a4 100644 --- a/app/tool/hexo-cos.js +++ b/app/tool/hexo-cos.js @@ -42,7 +42,7 @@ var cosServer = (function () { * @param bucket * @param region */ - update(acessKey, secretKey, bucket, region,protocol) { + update(acessKey, secretKey, bucket, region, protocol) { this.cos.options.SecretId = acessKey || config.SecretId || ''; this.cos.options.SecretKey = secretKey || config.SecretKey || ''; config.SecretId = acessKey || config.SecretId || ''; @@ -55,14 +55,14 @@ var cosServer = (function () { getService(cb) { this.cos.getService(function (err, data) { - if(!err && !err && [200,204].includes(data.statusCode) ) { + if (!err && !err && [200, 204].includes(data.statusCode)) { log.info(data) data.statusCode = 200; - } else { + } else { log.error(err.error.message); } if (typeof cb === 'function') - cb(err||data ); + cb(err || data); }); } @@ -74,14 +74,14 @@ var cosServer = (function () { Expires: 60, Sign: true, }, function (err, data) { - if(!err && [200,204].includes(data.statusCode) ) { + if (!err && [200, 204].includes(data.statusCode)) { log.info(data) data.statusCode = 200; - } else { + } else { log.error(err.error.message); } if (typeof cb === 'function') - cb(err||data ); + cb(err || data); }); return url; } @@ -91,14 +91,14 @@ var cosServer = (function () { Bucket: config.Bucket, // Bucket 格式:test-1250000000 Region: config.Region }, function (err, data) { - if(!err && [200,204].includes(data.statusCode) ) { + if (!err && [200, 204].includes(data.statusCode)) { log.info(data) data.statusCode = 200; - } else { + } else { log.error(err.error.message); } if (typeof cb === 'function') - cb(err||data ); + cb(err || data); }); } @@ -107,14 +107,14 @@ var cosServer = (function () { Bucket: config.Bucket, // Bucket 格式:test-1250000000 Region: config.Region }, function (err, data) { - if(!err && [200,204].includes(data.statusCode) ) { + if (!err && [200, 204].includes(data.statusCode)) { log.info(data) data.statusCode = 200; - } else { + } else { log.error(err.error.message); } if (typeof cb === 'function') - cb(err||data ); + cb(err || data); }); } @@ -125,14 +125,14 @@ var cosServer = (function () { Key: filename, CopySource: config.Bucket + '.cos.' + config.Region + '.myqcloud.com/' + filename }, function (err, data) { - if(!err && [200,204].includes(data.statusCode) ) { + if (!err && [200, 204].includes(data.statusCode)) { log.info(data) data.statusCode = 200; - } else { + } else { log.error(err.error.message); } if (typeof cb === 'function') - cb(err||data ); + cb(err || data); }); } @@ -148,14 +148,14 @@ var cosServer = (function () { } }, function (err, data) { if (typeof cb === 'function') - if(!err && [200,204].includes(data.statusCode) ) { + if (!err && [200, 204].includes(data.statusCode)) { log.info(data) data.statusCode = 200; - } else { + } else { log.error(err.error.message); } if (typeof cb === 'function') - cb(err||data ); + cb(err || data); }); } @@ -165,14 +165,14 @@ var cosServer = (function () { Region: config.Region, Key: fileanme }, function (err, data) { - if(!err && [200,204].includes(data.statusCode) ) { - log.info(fileanme,' was deleted!') + if (!err && [200, 204].includes(data.statusCode)) { + log.info(`[${fileanme}]: was deleted!`) data.statusCode = 200; - } else { - log.error(err.error.message); + } else { + log.error(`[${fileanme}]:` + err.error.message) } if (typeof cb === 'function') - cb(err||data ); + cb(err || data); }); } @@ -185,14 +185,14 @@ var cosServer = (function () { // {Key: '3mb.zip'}, // ] }, function (err, data) { - if(!err && [200,204].includes(data.statusCode) ) { + if (!err && [200, 204].includes(data.statusCode)) { log.info(data) data.statusCode = 200; - } else { + } else { log.error(err.error.message); } if (typeof cb === 'function') - cb(err||data ); + cb(err || data); }); } @@ -223,27 +223,27 @@ var cosServer = (function () { }*/ if (typeof cb === "function") { - let result = {type: 100,id: localFile}; - if (err){ + let result = {type: 100, id: localFile}; + if (err) { result.type = 100; result.statusCode = err.statusCode; result.msg = err.error.message; - } else{ + } else { result.type = 200; result.statusCode = data.statusCode; result.data = { localname: path.basename(localFile), storename: path.basename(serverFile), path: serverFile, - url: config.Protocol + data.Location.replace(/https?:\/\//,''), + url: config.Protocol + data.Location.replace(/https?:\/\//, ''), } } cb(result) } else { - if (err){ + if (err) { log.error(err.error.message); - } else{ - log.info(config.Protocol + data.Location.replace(/https?:\/\//,'')) + } else { + log.info(config.Protocol + data.Location.replace(/https?:\/\//, '')) } } }); @@ -275,28 +275,30 @@ var cosServer = (function () { * statusCode: 200, * headers: {} }*/ - if(!err && [200,204].includes(data.statusCode) ) { - log.info(data) - data.statusCode = 200; - } else { - log.error(err.error.message); - } + if (typeof cb === "function") { - let result = {type: 100,id: localFile}; - if (err){ + let result = {type: 100, id: localFile}; + if (err) { result.statusCode = err.statusCode; result.msg = err.error.message; - } else{ + } else { result.type = 200; result.statusCode = data.statusCode; result.data = { localname: path.basename(localFile), storename: path.basename(serverFile), path: data.Key, - url: config.Protocol + data.Location, + url: config.Protocol + data.Location } } cb(result) + } else { + if (!err && [200, 204].includes(data.statusCode)) { + log.info(config.Protocol + data.Location) + data.statusCode = 200; + } else { + log.error(err.error.message); + } } }); } @@ -316,6 +318,7 @@ var cosServer = (function () { console.log('restart'); } } + return CosServer; })(); diff --git a/app/tool/hexo-smms.js b/app/tool/hexo-smms.js index 6051865..aea77eb 100644 --- a/app/tool/hexo-smms.js +++ b/app/tool/hexo-smms.js @@ -35,10 +35,11 @@ var smms = (function () { var content = body; if (content) { content = content.match(/
]*>([^<]*)[${result.data.url}]`); }else{ - log.warn('failed:' + result.statusCode,result.id, result.msg); + log.warn(`failed:[${result.statusCode}][${+result.id}]-->[${result.msg}]`); } if (typeServer == 'smms' && typeBack > 2) { //是否需要备份 @@ -262,7 +262,7 @@ module.exports = (function () { } finishedCallback(info, successList, errorList); isUploading = false; - log.info(`---End upload---[S: ${successList.length}| F: ${errorList.length}][time:${ new Date() - startDate}]`); + log.info(`---End upload---[S:${successList.length}| F:${errorList.length}][time:${ new Date() - startDate}]`); } } @@ -332,7 +332,7 @@ module.exports = (function () { return; if (!(pathArray instanceof Array)) return; - log.info(`---begin upload---[${pathArray.length}]`); + log.info(`---Begin upload---[${pathArray.length}]`); startDate = new Date(); isUploading = true; baseDir = srcDir; diff --git a/views/main/hexo-image.js b/views/main/hexo-image.js index 1cf5577..26844f9 100644 --- a/views/main/hexo-image.js +++ b/views/main/hexo-image.js @@ -22,6 +22,10 @@ class ImgManager { this.updateBase(); } + hasUploadFile(){ + return (uploadList.length > 0) + } + updateBase() { let rootPaht = ''; if (moeApp.config.get('image-source-center')) { @@ -220,7 +224,7 @@ class ImgManager { break; } } - + uploadList = []; } uploadDelAll() { @@ -276,6 +280,7 @@ class ImgManager { let maxIndex = errorList.length - 1; if (maxIndex >= 0) { errorList.forEach((response, index) => { + log.warn(`Failed File:[${response.id}]==>[${__(response.msg)}]`); errMsg += response.id + ':' + __(response.msg) + '
'; if (maxIndex == index) { window.popMessageShell(null, { @@ -298,6 +303,7 @@ class ImgManager { function updateSrc(successList) { let content = editor.getValue(); let maxIndex = successList.length - 1; + log.info(`Begin update Src[${maxIndex}]`); successList.forEach((response, index) => { uploadList.push(response); content = content.replace(new RegExp(imgManager.imgPathToMarkURL[response.id], 'g'), response.data.url); @@ -308,6 +314,7 @@ class ImgManager { editor.setValue(content); hexoWindow.content = content; hexoWindow.changed = true; + log.info(`End update Src[${maxIndex}]`); } }); } diff --git a/views/main/moe-contextmenu.js b/views/main/moe-contextmenu.js index a45309a..3b56215 100644 --- a/views/main/moe-contextmenu.js +++ b/views/main/moe-contextmenu.js @@ -137,7 +137,14 @@ document.addEventListener('DOMContentLoaded', () => { label: imageMenuLable, enabled: imageMenuEnable, click(item, w) { - !imgManager.uploadLocalSrc(); + imgManager.uploadLocalSrc(); + } + }, + { + label: __('UndoUpload'), + visible: imgManager.hasUploadFile(), + click(item, w) { + imgManager.abortUploading(); } }, {