@@ -3,10 +3,8 @@ import { Alert } from '@/infra/alert'
33import { PostFileMapManager } from '@/service/post/post-file-map'
44import { basename } from 'path'
55import { ProgressLocation , Uri , window , workspace } from 'vscode'
6- import { buildLocalPostFileUri } from '@/cmd/post-list/open-post-in-vscode'
76import { UserService } from '@/service/user.service'
87import { fsUtil } from '@/infra/fs/fsUtil'
9- import { WorkspaceCfg } from '@/ctx/cfg/workspace'
108
119enum ConflictStrategy {
1210 ask ,
@@ -65,22 +63,22 @@ export async function postPullAll() {
6563
6664 p . report ( { message : `${ post . title } ` } )
6765
68- const path = PostFileMapManager . getFilePath ( post . id )
66+ const fileUri = PostFileMapManager . ensurePostFileUri ( post )
67+ if ( fileUri == null ) {
68+ console . warn ( 'fileUri is null' )
69+ return
70+ }
6971
70- // 本地没有博文或关联到的文件不存在
71- if (
72- path === undefined ||
73- ! ( await fsUtil . exists ( path ) ) ||
74- path . indexOf ( WorkspaceCfg . getWorkspaceUri ( ) . fsPath ) < 0
75- ) {
76- const uri = buildLocalPostFileUri ( post )
72+ if ( ! ( await fsUtil . exists ( fileUri . fsPath ) ) ) {
7773 const buf = Buffer . from ( post . postBody )
78- await workspace . fs . writeFile ( uri , buf )
79- await PostFileMapManager . updateOrCreate ( post . id , uri . path )
74+ await workspace . fs . writeFile ( fileUri , buf )
75+ await PostFileMapManager . updateOrCreate ( post . id , fileUri . path )
76+ console . info ( `Writing post ${ post . id } to file '${ fileUri . fsPath } '` )
8077 continue
8178 }
8279
83- const fileName = basename ( path )
80+ const fsPath = fileUri . fsPath
81+ const fileName = basename ( fsPath )
8482
8583 // 存在冲突
8684 if ( strategy === ConflictStrategy . ask ) {
@@ -90,17 +88,17 @@ export async function postPullAll() {
9088 )
9189
9290 if ( answer === '覆盖' ) {
93- await overwriteFile ( path , post . postBody )
91+ await overwriteFile ( fsPath , post . postBody )
9492 } else if ( answer === '退出' ) {
9593 break
9694 } else if ( answer === '跳过所有冲突' ) {
9795 strategy = ConflictStrategy . skip
9896 } else if ( answer === '覆盖全部' ) {
9997 strategy = ConflictStrategy . overwrite
100- await overwriteFile ( path , post . postBody )
98+ await overwriteFile ( fsPath , post . postBody )
10199 } // answer eq undefined or '跳过', do nothing.
102100 } else if ( strategy === ConflictStrategy . overwrite ) {
103- await overwriteFile ( path , post . postBody )
101+ await overwriteFile ( fsPath , post . postBody )
104102 } // strategy eq ConflictStrategy.skip, do nothing.
105103 }
106104
0 commit comments