This repository has been 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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6560f01
Showing
16 changed files
with
3,381 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"env": { | ||
"browser": false, | ||
"commonjs": true, | ||
"es6": true, | ||
"node": true | ||
}, | ||
"parserOptions": { | ||
"ecmaFeatures": { | ||
"jsx": true | ||
}, | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"no-const-assign": "warn", | ||
"no-this-before-super": "warn", | ||
"no-undef": "warn", | ||
"no-unreachable": "warn", | ||
"no-unused-vars": "warn", | ||
"constructor-super": "warn", | ||
"valid-typeof": "warn" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Set default behavior to automatically normalize line endings. | ||
* text=auto | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
.vscode-test/ | ||
*.vsix | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
// See http://go.microsoft.com/fwlink/?LinkId=827846 | ||
// for the documentation about the extensions.json format | ||
"recommendations": [ | ||
"dbaeumer.vscode-eslint" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// A launch configuration that launches the extension inside a new window | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Extension", | ||
"type": "extensionHost", | ||
"request": "launch", | ||
"runtimeExecutable": "${execPath}", | ||
"args": [ | ||
"--extensionDevelopmentPath=${workspaceFolder}" | ||
] | ||
}, | ||
{ | ||
"name": "Extension Tests", | ||
"type": "extensionHost", | ||
"request": "launch", | ||
"runtimeExecutable": "${execPath}", | ||
"args": [ | ||
"--extensionDevelopmentPath=${workspaceFolder}", | ||
"--extensionTestsPath=${workspaceFolder}/test" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place your settings in this file to overwrite default and user settings. | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.vscode/** | ||
.vscode-test/** | ||
test/** | ||
.gitignore | ||
jsconfig.json | ||
vsc-extension-quickstart.md | ||
.eslintrc.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Change Log | ||
All notable changes to the "vscode-upload-tencentcos" extension will be documented in this file. | ||
|
||
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. | ||
|
||
## [Unreleased] | ||
- Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# vscode-upload-tencentcos | ||
|
||
vscode extension to upload image into tencent COS for markdown | ||
|
||
|
||
# Reference | ||
1. [vscode-qiniu-upload-image](https://github.com/yscoder/vscode-qiniu-upload-image.git) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// The module 'vscode' contains the VS Code extensibility API | ||
// Import the module and reference it with the alias vscode in your code below | ||
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.fileName | ||
const mdFileName = path.win32.basename(mdFilePath, path.extname(mdFilePath)) | ||
|
||
return COSUpload(config, fsPath, mdFileName).then(({ name, url}) => { | ||
console.log('Upload success') | ||
|
||
const img = `![${name}](${url})` | ||
|
||
editor.edit(textEditorEdit => { | ||
textEditorEdit.insert(editor.selection.active, img) | ||
}) | ||
}) | ||
} | ||
|
||
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("没有打开编辑窗口") | ||
return | ||
} | ||
|
||
vscode.window.showInputBox({ | ||
placeHolder: '请输入一个图片地址' | ||
}) | ||
.then(fsPath => upload(config, fsPath), error) | ||
}) | ||
|
||
let selectUpload = vscode.commands.registerCommand('extension.tencentCOS.select', () => { | ||
vscode.window.showOpenDialog({ | ||
filters: {'Images': ['png', 'jpg', 'gif', 'bmp']} | ||
}).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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es6", | ||
"checkJs": true, /* Typecheck .js files. */ | ||
"lib": [ | ||
"es6" | ||
] | ||
}, | ||
"exclude": [ | ||
"node_modules" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const COS = require('cos-nodejs-sdk-v5') | ||
const path = require('path') | ||
const url = require('url') | ||
const request = require('request') | ||
const fs = require('fs') | ||
|
||
const formatParam = file => { | ||
return { | ||
dirname: path.dirname(file), | ||
filename: path.basename(file), | ||
ext: path.extname(file) | ||
} | ||
} | ||
|
||
module.exports = ({ | ||
secret_id, | ||
secret_key, | ||
bucket, | ||
region | ||
}, file, mdfile) => { | ||
var cos = new COS({ | ||
SecretId: secret_id, | ||
SecretKey: secret_key | ||
}); | ||
let domain = url.format({ | ||
protocol: "https:", | ||
host: bucket+".cos."+region+".myqcloud.com" | ||
}) | ||
|
||
const param = formatParam(file) | ||
console.log(domain) | ||
console.log(cos) | ||
// let filename = "avatar_001.jpg" | ||
// console.log(filename) | ||
cos.putObject({ | ||
Bucket: bucket, | ||
Region: region, | ||
Key: file, | ||
Body: fs.readFileSync(path.resolve(__dirname, file)) | ||
|
||
}, function (err, data) { | ||
console.log(err || data); | ||
|
||
}) | ||
|
||
// console.log("succeed") | ||
return new Promise((resolve, reject) => { | ||
resolve({ | ||
name: param.filename, | ||
url: url.resolve(domain, param.filename) | ||
}) | ||
}) | ||
} |
Oops, something went wrong.