@@ -11,6 +11,7 @@ import path from 'path'
1111import { promisify } from 'util'
1212import { execCmd } from '@/infra/cmd'
1313import { WorkspaceCfg } from '@/ctx/cfg/workspace'
14+ import AdmZip from 'adm-zip'
1415
1516function parseInput ( input : unknown ) : BlogExportRecordTreeItem | null | undefined {
1617 return input instanceof BlogExportRecordTreeItem ? input : null
@@ -37,8 +38,8 @@ export async function downloadBlogExport(input: unknown) {
3738 const { optionalInstance : blogExportProvider } = BlogExportProvider
3839 await setIsDownloading ( true )
3940
40- const onError = ( msg ? : string | null ) => {
41- if ( msg ) void Alert . warn ( msg )
41+ const onError = ( msg : string ) => {
42+ void Alert . warn ( msg )
4243 if ( ! isFileExist ) fs . rmSync ( zipFilePath )
4344 blogExportProvider ?. refreshItem ( treeItem )
4445 setIsDownloading ( false ) . then ( undefined , console . warn )
@@ -70,26 +71,19 @@ export async function downloadBlogExport(input: unknown) {
7071 treeItem . reportDownloadingProgress ( { percentage : 100 , message : '解压中' } )
7172 blogExportProvider ?. refreshItem ( treeItem )
7273
73- import ( 'adm-zip' )
74- // eslint-disable-next-line @typescript-eslint/naming-convention
75- . then ( ( { default : AdmZip } ) => {
74+ void ( async ( ) => {
75+ try {
7676 const entry = new AdmZip ( zipFilePath )
77- return promisify ( entry . extractAllToAsync . bind ( entry ) ) (
78- targetDir ,
79- true ,
80- undefined
81- ) . then ( ( ) => promisify ( fs . rm ) ( zipFilePath ) )
82- } )
83- . then ( ( ) => {
84- DownloadedExportStore . add ( nonZipFilePath , exportId )
85- . then ( ( ) => treeItem . reportDownloadingProgress ( null ) )
86- . then ( ( ) => blogExportProvider ?. refreshItem ( treeItem ) )
87- . then ( ( ) => blogExportProvider ?. refreshDownloadedExports ( ) )
88- . catch ( console . warn )
89- } , console . warn )
90- . finally ( ( ) => {
77+ await promisify ( entry . extractAllToAsync . bind ( entry ) ) ( targetDir , true , undefined )
78+ await promisify ( fs . rm ) ( zipFilePath )
79+ await DownloadedExportStore . add ( nonZipFilePath , exportId )
80+ treeItem . reportDownloadingProgress ( null )
81+ blogExportProvider ?. refreshItem ( treeItem )
82+ await blogExportProvider ?. refreshDownloadedExports ( )
83+ } finally {
9184 setIsDownloading ( false ) . then ( undefined , console . warn )
92- } )
85+ }
86+ } ) ( )
9387 } )
9488 )
9589 } else {
0 commit comments