@@ -12,22 +12,34 @@ import { fsUtil } from '@/infra/fs/fsUtil'
1212
1313export async function postPull ( input : Post | PostTreeItem | Uri | undefined | null , showConfirm = true , mute = false ) {
1414 const ctxList : CmdCtx [ ] = [ ]
15+ let isFreshPull = false
1516 input = input instanceof PostTreeItem ? input . post : input
1617 if ( parsePostInput ( input ) && input . id > 0 ) {
17- await handlePostInput ( input , ctxList )
18+ const post = input
19+ const path = PostFileMapManager . getFilePath ( post . id )
20+ if ( path === undefined || ! ( await fsUtil . exists ( path ) ) ) {
21+ isFreshPull = true
22+ const uri = await buildLocalPostFileUri ( post , false )
23+ await workspace . fs . writeFile ( uri , Buffer . from ( post . postBody ) )
24+ await PostFileMapManager . updateOrCreate ( post . id , uri . path )
25+ await handlePostInput ( input , ctxList , uri . path )
26+ } else {
27+ isFreshPull = ! ( await fsUtil . exists ( path ) )
28+ await handlePostInput ( input , ctxList , path )
29+ }
1830 } else {
1931 const uri = parseUriInput ( input )
2032 if ( uri !== undefined ) handleUriInput ( uri , ctxList )
2133 }
2234
2335 const fileName = resolveFileNames ( ctxList )
2436
25- if ( showConfirm && MarkdownCfg . isShowConfirmMsgWhenPullPost ( ) ) {
37+ if ( showConfirm && ! isFreshPull && MarkdownCfg . isShowConfirmMsgWhenPullPost ( ) ) {
2638 const answer = await Alert . warn (
2739 '确认要拉取远程博文吗?' ,
2840 {
2941 modal : true ,
30- detail : `本地文件 ${ fileName } 将被覆盖(可通过设置关闭对话框)` ,
42+ detail : `本地文件「 ${ fileName } 」 将被覆盖(可通过设置关闭对话框)` ,
3143 } ,
3244 '确认'
3345 )
@@ -38,7 +50,10 @@ export async function postPull(input: Post | PostTreeItem | Uri | undefined | nu
3850
3951 await update ( ctxList )
4052
41- if ( ! mute ) void Alert . info ( `本地文件 ${ resolveFileNames ( ctxList ) } 已更新` )
53+ if ( ! mute ) {
54+ if ( isFreshPull ) await Alert . info ( `博文已下载至本地:${ resolveFileNames ( ctxList ) } ` )
55+ else await Alert . info ( `本地文件已更新: ${ resolveFileNames ( ctxList ) } ` )
56+ }
4257}
4358
4459type InputType = Post | Uri | undefined | null
@@ -49,16 +64,7 @@ type CmdCtx = {
4964
5065const parsePostInput = ( input : InputType ) : input is Post => input instanceof Post
5166
52- async function handlePostInput ( post : Post , contexts : CmdCtx [ ] ) {
53- const path = PostFileMapManager . getFilePath ( post . id )
54- // 本地没有博文或关联到的文件不存在
55- if ( path === undefined || ! ( await fsUtil . exists ( path ) ) ) {
56- const uri = await buildLocalPostFileUri ( post , false )
57- await workspace . fs . writeFile ( uri , Buffer . from ( post . postBody ) )
58- await PostFileMapManager . updateOrCreate ( post . id , uri . path )
59- return
60- }
61-
67+ async function handlePostInput ( post : Post , contexts : CmdCtx [ ] , path : string ) {
6268 await revealPostListItem ( post )
6369 contexts . push ( { postId : post . id , fileUri : Uri . file ( path ) } )
6470}
@@ -91,5 +97,5 @@ async function update(contexts: CmdCtx[]) {
9197
9298function resolveFileNames ( ctxList : CmdCtx [ ] ) {
9399 const arr = ctxList . map ( x => path . basename ( x . fileUri . fsPath ) )
94- return `" ${ arr . join ( '" , ' ) } `
100+ return `${ arr . join ( ', ' ) } `
95101}
0 commit comments