diff --git a/README.md b/README.md index a84b062..a0cac65 100644 --- a/README.md +++ b/README.md @@ -32,8 +32,17 @@ ext install paste-image-to-qiniu // 七牛图床域名 "pasteImageToQiniu.domain": "http://xxxxx.xxxx.com", + // http或者https + "pasteImageToQiniu.schema": "http", + + // 存储区域对应 HTTPS 地址,参考七牛官方文档:https://support.qiniu.com/hc/kb/article/210702。当schema为https时需要定义此选项 + "pasteImageToQiniu.upHttpsHost": "", + + // 是否存储粘贴板图片到本地,值为true的时候请不要定义localPath + "pasteImageToQiniu.saveImageToLocal": true, + // 本地储存位置 - "pasteImageToQiniu.localPath":"./img" + "pasteImageToQiniu.localPath":"" } ``` @@ -41,4 +50,4 @@ ext install paste-image-to-qiniu 将[vscode-paste-image](https://github.com/mushanshitiancai/vscode-paste-image)和[vscode-qiniu-upload-image](https://github.com/yscoder/vscode-qiniu-upload-image)综合改成了现在这个插件。 -如果用的开心给个star也不错! \ No newline at end of file +如果用的开心给个star也不错! diff --git a/extension.js b/extension.js index a8d1a8d..87edbd0 100644 --- a/extension.js +++ b/extension.js @@ -46,7 +46,6 @@ function start() { let imagePath = getImagePath(filePath, selectText, localPath); const mdFilePath = editor.document.fileName; const mdFileName = path.basename(mdFilePath, path.extname(mdFilePath)); - createImageDirWithImagePath(imagePath).then(imagePath => { saveClipboardImageToFileAndGetPath(imagePath, (imagePath) => { if (!imagePath) return; @@ -60,12 +59,20 @@ function start() { editor.edit(textEditorEdit => { textEditorEdit.insert(editor.selection.active, img) }); + // 是否删除本地文件 + if (!config.saveImageToLocal) { + fs.unlink(imagePath, function(err) { + if (err) { + vscode.window.showErrorMessage('Delete tmpfile error. ' + err.toString()); + } + }) + } }).catch((err) => { - vscode.window.showErrorMessage('Upload error.'); + vscode.window.showErrorMessage('Upload error. ' + err.toString()); }); }); }).catch(err => { - vscode.window.showErrorMessage('Failed make folder.'); + vscode.window.showErrorMessage('Failed make folder. ' + err.toString()); return; }); } @@ -163,4 +170,4 @@ function saveClipboardImageToFileAndGetPath(imagePath, cb) { cb(result); }); } -} \ No newline at end of file +} diff --git a/jsconfig.json b/jsconfig.json index b7caa7d..6e5822e 100644 --- a/jsconfig.json +++ b/jsconfig.json @@ -1,12 +1,8 @@ { - "compilerOptions": { - "module": "commonjs", - "target": "es6", - "lib": [ - "es6" - ] - }, - "exclude": [ - "node_modules" - ] -} \ No newline at end of file + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "lib": ["es6"] + }, + "exclude": ["node_modules"] +} diff --git a/lib/upload.js b/lib/upload.js index 0e8c27d..6662acb 100644 --- a/lib/upload.js +++ b/lib/upload.js @@ -46,6 +46,8 @@ module.exports = (config, file, mdFile) => { qiniu.conf.ACCESS_KEY = access_key qiniu.conf.SECRET_KEY = secret_key + qiniu.conf.SCHEME = config.scheme; + qiniu.conf.UP_HTTPS_HOST = config.upHttpsHost; let localFile = file if (/^".+"$/.test(localFile)) { diff --git a/package.json b/package.json index 18f6afd..9d07934 100644 --- a/package.json +++ b/package.json @@ -68,12 +68,27 @@ "pasteImageToQiniu.domain": { "type": "string", "default": "", - "description": "七牛图床域名。" + "description": "七牛图床域名,需要添加http[s]前缀。" + }, + "pasteImageToQiniu.schema": { + "type": "string", + "default": "https", + "description": "http或者https。" + }, + "pasteImageToQiniu.upHttpsHost": { + "type": "string", + "default": "https://up-z2.qbox.me", + "description": "存储区域对应 HTTPS 地址,参考七牛官方文档:https://support.qiniu.com/hc/kb/article/210702。" + }, + "pasteImageToQiniu.saveImageToLocal": { + "type": "boolean", + "default": false, + "description": "是否需要存储粘贴板图片到本地,值为true时请不要设置localPath。" }, "pasteImageToQiniu.localPath": { "type": "string", - "default": "./img", - "description": "图片本地保存位置" + "default": "", + "description": "图片本地保存位置。" } } } diff --git a/test/extension.test.js b/test/extension.test.js index c3c1517..83ba925 100644 --- a/test/extension.test.js +++ b/test/extension.test.js @@ -21,4 +21,4 @@ suite("Extension Tests", function() { assert.equal(-1, [1, 2, 3].indexOf(5)); assert.equal(-1, [1, 2, 3].indexOf(0)); }); -}); \ No newline at end of file +});