@@ -105,8 +105,6 @@ export const saveLocalDraftToCnblogs = async (localDraft: LocalDraft) => {
105
105
successCallback : async savedPost => {
106
106
await refreshPostsList ( ) ;
107
107
await openPostFile ( localDraft ) ;
108
- if ( Settings . automaticallyExtractImagesType )
109
- await extractImages ( localDraft . filePathUri , Settings . automaticallyExtractImagesType ) ;
110
108
111
109
await PostFileMapManager . updateOrCreate ( savedPost . id , localDraft . filePath ) ;
112
110
await openPostFile ( localDraft ) ;
@@ -120,14 +118,18 @@ export const saveLocalDraftToCnblogs = async (localDraft: LocalDraft) => {
120
118
AlertService . warning ( '本地文件已删除, 无法新建博文' ) ;
121
119
return false ;
122
120
}
123
- const content = await localDraft . readAllText ( ) ;
124
- postToSave . postBody = content ;
121
+ if ( Settings . automaticallyExtractImagesType ) {
122
+ await extractImages ( localDraft . filePathUri , Settings . automaticallyExtractImagesType ) . catch (
123
+ console . warn
124
+ ) ;
125
+ }
126
+ postToSave . postBody = await localDraft . readAllText ( ) ;
125
127
return true ;
126
128
} ,
127
129
} ) ;
128
130
} ;
129
131
130
- export const savePostToCnblogs = async ( input : Post | PostTreeItem | PostEditDto | undefined , isNewPost = false ) => {
132
+ export const savePostToCnblogs = async ( input : Post | PostTreeItem | PostEditDto | undefined ) => {
131
133
input = input instanceof PostTreeItem ? input . post : input ;
132
134
const post =
133
135
input instanceof PostEditDto
@@ -139,16 +141,14 @@ export const savePostToCnblogs = async (input: Post | PostTreeItem | PostEditDto
139
141
140
142
const { id : postId } = post ;
141
143
const localFilePath = PostFileMapManager . getFilePath ( postId ) ;
144
+ if ( ! localFilePath ) return AlertService . warning ( '本地无该博文的编辑记录' ) ;
145
+
146
+ if ( Settings . automaticallyExtractImagesType )
147
+ await extractImages ( Uri . file ( localFilePath ) , Settings . automaticallyExtractImagesType ) . catch ( console . warn ) ;
148
+
142
149
await saveFilePendingChanges ( localFilePath ) ;
143
- if ( ! isNewPost ) {
144
- if ( ! localFilePath ) {
145
- AlertService . warning ( '本地无该博文的编辑记录' ) ;
146
- return ;
147
- }
148
- const updatedPostBody = new TextDecoder ( ) . decode ( await workspace . fs . readFile ( Uri . file ( localFilePath ) ) ) ;
149
- post . postBody = updatedPostBody ;
150
- post . title = await PostTitleSanitizer . unSanitize ( post ) ;
151
- }
150
+ post . postBody = ( await workspace . fs . readFile ( Uri . file ( localFilePath ) ) ) . toString ( ) ;
151
+ post . title = await PostTitleSanitizer . unSanitize ( post ) ;
152
152
153
153
if ( ! validatePost ( post ) ) return false ;
154
154
@@ -164,12 +164,9 @@ export const savePostToCnblogs = async (input: Post | PostTreeItem | PostEditDto
164
164
} ) ;
165
165
let hasSaved = false ;
166
166
try {
167
- if ( Settings . automaticallyExtractImagesType && localFilePath )
168
- await extractImages ( Uri . file ( localFilePath ) , Settings . automaticallyExtractImagesType ) ;
169
-
170
167
const { id : postId } = await postService . updatePost ( post ) ;
171
- if ( ! isNewPost ) await openPostInVscode ( postId ) ;
172
- else post . id = postId ;
168
+ await openPostInVscode ( postId ) ;
169
+ post . id = postId ;
173
170
174
171
hasSaved = true ;
175
172
progress . report ( { increment : 100 } ) ;
0 commit comments