Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,22 @@ 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":""
}
```

一直使用vscode来开发、写笔记文章、但是用了几款vscode的图床插件都不是很符合我的需求。今天本来想看看书写点笔记、但是发现截图了去处理图片太过于麻烦、于是有了这个插件、仅仅是想体验一下vscode插件的开发流程、也可以方便自己的写体验。

将[vscode-paste-image](https://github.com/mushanshitiancai/vscode-paste-image)和[vscode-qiniu-upload-image](https://github.com/yscoder/vscode-qiniu-upload-image)综合改成了现在这个插件。

如果用的开心给个star也不错!
如果用的开心给个star也不错!
15 changes: 11 additions & 4 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
});
}
Expand Down Expand Up @@ -163,4 +170,4 @@ function saveClipboardImageToFileAndGetPath(imagePath, cb) {
cb(result);
});
}
}
}
18 changes: 7 additions & 11 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"lib": [
"es6"
]
},
"exclude": [
"node_modules"
]
}
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"lib": ["es6"]
},
"exclude": ["node_modules"]
}
2 changes: 2 additions & 0 deletions lib/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
21 changes: 18 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "图片本地保存位置"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/extension.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ suite("Extension Tests", function() {
assert.equal(-1, [1, 2, 3].indexOf(5));
assert.equal(-1, [1, 2, 3].indexOf(0));
});
});
});