Skip to content

Commit ff68add

Browse files
author
Martin
committed
fix cnblogs and csdn
1 parent 9f2143c commit ff68add

2 files changed

Lines changed: 25 additions & 22 deletions

File tree

src/blog/cnblogs.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ function publishArticleToCnBlogFact(title, content, resolve,
9494
"inSiteHome": false,
9595
"siteCategoryId": null,
9696
"blogTeamIds": null,
97-
"isPublished": true,
97+
"isPublished": isPublish,
9898
"displayOnHomePage": true,
9999
"isAllowComments": true,
100100
"includeInMainSyndication": true,
@@ -133,26 +133,29 @@ function publishArticleToCnBlogFact(title, content, resolve,
133133
'cookie': dataStore.getCnBlogCookies(),
134134
'x-xsrf-token': dataStore.GetCnblogsToken()
135135
}
136-
}).then(res => {
137-
if (res.status === 200) {
138-
resolve(res.data.url)
136+
}).then(response => {
137+
// console.log(response)
138+
// console.log("data: " + JSON.stringify(response.data))
139+
// console.log("status: " + response.status)
140+
if (response.status === 200) {
141+
let openUrl = response.data.url;
142+
if (openUrl.indexOf('//') === 0) {
143+
openUrl = "https:" + openUrl
144+
}
145+
resolve(openUrl)
146+
}
147+
}).catch(error => {
148+
// console.log("cookie: " + dataStore.getCnBlogCookies())
149+
// console.log('x-xsrf-token: ' + dataStore.GetCnblogsToken())
150+
if (error.response && error.response.data) {
151+
reject('发布失败!\n' + JSON.stringify(error.response.data))
152+
} else if (error.response) {
153+
reject('发布失败!\n' + JSON.stringify(error.response))
154+
} else {
155+
reject('发布失败!\n' + error.message)
139156
}
140-
// console.log(res)
141-
}).catch(reason => {
142-
reject('发布失败!\n' + JSON.stringify(reason.response.data))
143-
console.log("cookie: " + dataStore.getCnBlogCookies())
144-
console.log('x-xsrf-token: ' + dataStore.GetCnblogsToken())
145-
console.log(reason.response.data)
146157
})
147158

148-
149-
// const dom = new jsdom.JSDOM(str);
150-
// const a = dom.window.document.body.getElementsByTagName('a')[0];
151-
// let url = 'https://i.cnblogs.com' + a.href;
152-
153-
154-
// //发布失败
155-
156159
}
157160

158161
exports.uploadPictureToCnBlogs = uploadPictureToCnBlogs;

src/blog/csdn.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function uploadPictureToCSDN(filePath) {
5252
headers.Referer = "https://editor.csdn.net/";
5353
headers.ContentType = 'multipart/form-data';
5454
headers.Accept = 'application/json';
55-
55+
5656
// post formData to host
5757
fetch(url, {
5858
method: 'POST',
@@ -88,7 +88,8 @@ function publishArticleToCSDN(title, markdowncontent, content, isPublish) {
8888
content: content,
8989
readType: "public",
9090
not_auto_saved: "1",
91-
source: "pc_mdeditor"
91+
source: "pc_mdeditor",
92+
level: 1
9293
};
9394
if (isPublish) {
9495
parms['status'] = 0;
@@ -98,8 +99,7 @@ function publishArticleToCSDN(title, markdowncontent, content, isPublish) {
9899
parms['categories'] = '';
99100
parms['original_link'] = '';
100101
parms['resource_url'] = '';
101-
parms['tags'] = ''
102-
102+
parms['tags'] = '经验分享'
103103
}else {
104104
parms['status'] = 2
105105
}

0 commit comments

Comments
 (0)