Skip to content

Commit

Permalink
refactor: 0.3.1 增加响应延迟时间,调整部分代码
Browse files Browse the repository at this point in the history
  • Loading branch information
whosydd committed Nov 9, 2021
1 parent 3499203 commit 74b9a42
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## [0.3.1]

- fix: 修改下载图片时的`timeout`为 8 秒
- style: 调整部分代码

## [0.3.0]

- 添加功能:工作区如果存在多个文件夹,下载图片时提示可选文件夹
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "carbon",
"displayName": "Carbon",
"description": "Create and share beautiful images of your source code",
"version": "0.3.0",
"version": "0.3.1",
"engines": {
"vscode": "^1.61.0"
},
Expand Down
12 changes: 4 additions & 8 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,15 @@ export default (
return new Promise(async (resolve, reject) => {
try {
// 获取文件名
const filename = file.toString().split('/').pop()
const filename = file.toString().split('/').pop()!

// 获取配置项
const config = vscode.workspace.getConfiguration('carbon')
const domain: string | undefined = config.get('domain')
const theme: ThemeConfig | undefined = config.get('theme')

if (!filename || !domain || !theme) throw new Error('')
const domain: string = config.get('domain')!
const theme: ThemeConfig = config.get('theme')!

// 获取选中代码块
const editor = vscode.window.activeTextEditor
if (!editor) throw new Error('hello world!')
const editor = vscode.window.activeTextEditor!
const {
document: { lineAt, getText },
selection: { start, end, active },
Expand All @@ -68,7 +65,6 @@ export default (
code,
})
} catch (error: any) {
if (error.message === '') return
vscode.window.showErrorMessage(error.message)
}
})
Expand Down
5 changes: 2 additions & 3 deletions src/utils/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default async (file: vscode.FileType) => {
// 如果工作区中存在的多个文件夹,显示选择框
if (workspace.length > 1) {
const pick = await vscode.window.showWorkspaceFolderPick()
if (!pick) throw new Error('')
if (!pick) return
rootPath = pick.uri.fsPath
} else {
const pick = workspace[0]
Expand All @@ -37,14 +37,13 @@ export default async (file: vscode.FileType) => {
)
const res = await axios.post(`https://${domain}/api/cook`, params, {
responseType: 'arraybuffer',
timeout: 5000,
timeout: 8 * 1000,
})
if (!fs.existsSync(rootPath + '/carbon')) fs.mkdirSync(rootPath + '/carbon')
fs.createWriteStream(imgPath).write(res.data)
vscode.window.showInformationMessage('Done')
vscode.env.openExternal(vscode.Uri.file(imgPath))
} catch (error: any) {
if (error.message === '') return
vscode.window.showErrorMessage(error.message)
}
}

0 comments on commit 74b9a42

Please sign in to comment.