diff --git a/CHANGELOG.md b/CHANGELOG.md index b3fa421..7131ce8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## [0.3.1] + +- fix: 修改下载图片时的`timeout`为 8 秒 +- style: 调整部分代码 + ## [0.3.0] - 添加功能:工作区如果存在多个文件夹,下载图片时提示可选文件夹 diff --git a/package.json b/package.json index 3dc998c..a993b05 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/src/utils/config.ts b/src/utils/config.ts index 375f424..0592be7 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -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 }, @@ -68,7 +65,6 @@ export default ( code, }) } catch (error: any) { - if (error.message === '') return vscode.window.showErrorMessage(error.message) } }) diff --git a/src/utils/download.ts b/src/utils/download.ts index 6e79de4..6c82eac 100644 --- a/src/utils/download.ts +++ b/src/utils/download.ts @@ -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] @@ -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) } }