This repository was archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathextension.js
77 lines (61 loc) · 2.55 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const vscode = require('vscode');
const path = require('path')
const COSUpload = require('./lib/upload')
const upload = (config, fsPath) => {
if (!fsPath) return
console.log(fsPath)
const editor = vscode.window.activeTextEditor
const mdFilePath = editor.document.uri.fsPath
return COSUpload(config, fsPath, mdFilePath).then(({name, url}) => {
console.log('Succeed to upload image.')
const img = ``
editor.edit(textEditorEdit => {
textEditorEdit.insert(editor.selection.active, img)
})
}).catch(error => {
// console.log(error)
vscode.window.showErrorMessage("Failed to upload image. Error:" + error)
})
}
const error = err => vscode.window.showErrorMessage(err)
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
function activate(context) {
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log('vscode-upload-tencentcos is now active!');
const config = vscode.workspace.getConfiguration('tencentCOS')
console.log(config)
// if (!config.enable) return
// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
let inputUpload = vscode.commands.registerCommand('extension.tencentCOS.upload', () => {
if (!vscode.window.activeTextEditor) {
vscode.window.showErrorMessage("No editable window is open.")
return
}
vscode.window.showInputBox({
placeHolder: 'Please input the image path'
})
.then(fsPath => upload(config, fsPath), error)
})
let selectUpload = vscode.commands.registerCommand('extension.tencentCOS.select', () => {
vscode.window.showOpenDialog({
filters: {'Images': ['png', 'jpg', 'gif', 'bmp', 'jpeg', 'svg', 'webp']}
}).then(result => {
console.log(result)
if (result) {
const {fsPath} = result[0]
return upload(config, fsPath)
}
}, error)
})
context.subscriptions.push(inputUpload);
context.subscriptions.push(selectUpload);
}
exports.activate = activate;
// this method is called when your extension is deactivated
function deactivate() {
}
exports.deactivate = deactivate;