@@ -3,10 +3,8 @@ import { Alert } from '@/infra/alert'
3
3
import { PostFileMapManager } from '@/service/post/post-file-map'
4
4
import { basename } from 'path'
5
5
import { ProgressLocation , Uri , window , workspace } from 'vscode'
6
- import { buildLocalPostFileUri } from '@/cmd/post-list/open-post-in-vscode'
7
6
import { UserService } from '@/service/user.service'
8
7
import { fsUtil } from '@/infra/fs/fsUtil'
9
- import { WorkspaceCfg } from '@/ctx/cfg/workspace'
10
8
11
9
enum ConflictStrategy {
12
10
ask ,
@@ -65,22 +63,22 @@ export async function postPullAll() {
65
63
66
64
p . report ( { message : `${ post . title } ` } )
67
65
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
+ }
69
71
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 ) ) ) {
77
73
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 } '` )
80
77
continue
81
78
}
82
79
83
- const fileName = basename ( path )
80
+ const fsPath = fileUri . fsPath
81
+ const fileName = basename ( fsPath )
84
82
85
83
// 存在冲突
86
84
if ( strategy === ConflictStrategy . ask ) {
@@ -90,17 +88,17 @@ export async function postPullAll() {
90
88
)
91
89
92
90
if ( answer === '覆盖' ) {
93
- await overwriteFile ( path , post . postBody )
91
+ await overwriteFile ( fsPath , post . postBody )
94
92
} else if ( answer === '退出' ) {
95
93
break
96
94
} else if ( answer === '跳过所有冲突' ) {
97
95
strategy = ConflictStrategy . skip
98
96
} else if ( answer === '覆盖全部' ) {
99
97
strategy = ConflictStrategy . overwrite
100
- await overwriteFile ( path , post . postBody )
98
+ await overwriteFile ( fsPath , post . postBody )
101
99
} // answer eq undefined or '跳过', do nothing.
102
100
} else if ( strategy === ConflictStrategy . overwrite ) {
103
- await overwriteFile ( path , post . postBody )
101
+ await overwriteFile ( fsPath , post . postBody )
104
102
} // strategy eq ConflictStrategy.skip, do nothing.
105
103
}
106
104
0 commit comments