Skip to content

Commit ca5f55b

Browse files
authored
Merge pull request #214 from cnblogs/improve-empty-post-body-check
refactor: improve empty post body check
2 parents 38fba17 + 29c84fa commit ca5f55b

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/cmd/post-list/upload-post.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export async function saveLocalPost(localPost: LocalPost) {
7878
const extracted = await extractImg(text, fileDir, autoExtractImgSrc)
7979
if (extracted !== undefined) {
8080
postToSave.postBody = extracted
81+
if (isEmptyBody(text, '(发生于提取图片后')) return false
8182

8283
if (MarkdownCfg.getApplyAutoExtractImgToLocal()) {
8384
const doc = window.visibleTextEditors.find(x => x.document.uri.fsPath === localPost.filePath)
@@ -97,9 +98,9 @@ export async function saveLocalPost(localPost: LocalPost) {
9798
})
9899
}
99100

100-
function isEmptyBody(body: string) {
101+
function isEmptyBody(body: string, tip: string = '') {
101102
if (body === '') {
102-
void Alert.warn('博文内容不能为空')
103+
void Alert.warn('博文内容不能为空' + tip)
103104
return true
104105
}
105106

src/service/post/post.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ export namespace PostService {
123123

124124
export async function update(post: Post) {
125125
if (MarkdownCfg.isIgnoreYfmWhenUploadPost()) post.postBody = rmYfm(post.postBody)
126+
127+
if (post.postBody === '') void Alert.warn('博文内容不能为空(发生于 http post 请求之前)')
128+
126129
const body = JSON.stringify(post)
127130
const req = await getAuthedPostReq()
128131
const resp = await req.update(body)

0 commit comments

Comments
 (0)