@@ -11,6 +11,7 @@ import path from 'path'
11
11
import { promisify } from 'util'
12
12
import { execCmd } from '@/infra/cmd'
13
13
import { WorkspaceCfg } from '@/ctx/cfg/workspace'
14
+ import AdmZip from 'adm-zip'
14
15
15
16
function parseInput ( input : unknown ) : BlogExportRecordTreeItem | null | undefined {
16
17
return input instanceof BlogExportRecordTreeItem ? input : null
@@ -37,8 +38,8 @@ export async function downloadBlogExport(input: unknown) {
37
38
const { optionalInstance : blogExportProvider } = BlogExportProvider
38
39
await setIsDownloading ( true )
39
40
40
- const onError = ( msg ? : string | null ) => {
41
- if ( msg ) void Alert . warn ( msg )
41
+ const onError = ( msg : string ) => {
42
+ void Alert . warn ( msg )
42
43
if ( ! isFileExist ) fs . rmSync ( zipFilePath )
43
44
blogExportProvider ?. refreshItem ( treeItem )
44
45
setIsDownloading ( false ) . then ( undefined , console . warn )
@@ -70,26 +71,19 @@ export async function downloadBlogExport(input: unknown) {
70
71
treeItem . reportDownloadingProgress ( { percentage : 100 , message : '解压中' } )
71
72
blogExportProvider ?. refreshItem ( treeItem )
72
73
73
- import ( 'adm-zip' )
74
- // eslint-disable-next-line @typescript-eslint/naming-convention
75
- . then ( ( { default : AdmZip } ) => {
74
+ void ( async ( ) => {
75
+ try {
76
76
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 {
91
84
setIsDownloading ( false ) . then ( undefined , console . warn )
92
- } )
85
+ }
86
+ } ) ( )
93
87
} )
94
88
)
95
89
} else {
0 commit comments