@iflyrpa/actions 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +103 -6
- package/dist/index.mjs +103 -6
- package/package.json +1 -1
- package/src/actions/toutiaoPublish/index.ts +9 -2
- package/src/actions/toutiaoPublish/mock.ts +116 -7
package/dist/index.cjs
CHANGED
|
@@ -21990,6 +21990,11 @@ const searchToutiaoTopicList = async (task, params) => {
|
|
|
21990
21990
|
}
|
|
21991
21991
|
};
|
|
21992
21992
|
|
|
21993
|
+
const COVER_TYPE = {
|
|
21994
|
+
no: 1,
|
|
21995
|
+
single: 2,
|
|
21996
|
+
multiple: 3
|
|
21997
|
+
};
|
|
21993
21998
|
const errnoMap = {
|
|
21994
21999
|
20004020: "\u56FE\u7247\u4E0A\u4F20\u51FA\u73B0\u95EE\u9898\uFF0C\u8BF7\u91CD\u65B0\u7ED1\u5B9A\u8D26\u53F7\u540E\u518D\u5C1D\u8BD5",
|
|
21995
22000
|
7115: "\u6B63\u6587\u548C\u5C01\u9762\u56FE\u7247\u63A8\u8350\u4F7F\u752820M\u4EE5\u5185\u7684jpg\u548Cpng\u56FE\u7247",
|
|
@@ -22000,11 +22005,13 @@ const errnoMap = {
|
|
|
22000
22005
|
2005: "\u65E0\u58F0\u660E\u539F\u521B\u6743\u9650\uFF0C\u8BF7\u53D6\u6D88\u539F\u521B\u58F0\u660E\u6216\u7533\u8BF7\u539F\u521B\u6743\u9650\u540E\u518D\u5C1D\u8BD5"
|
|
22001
22006
|
};
|
|
22002
22007
|
const mockAction$4 = async (task, params) => {
|
|
22003
|
-
const { toutiaoSingleCover, toutiaoMultCover, toutiaoCoverType } = params.settingInfo;
|
|
22008
|
+
const { toutiaoSingleCover, toutiaoMultCover, toutiaoCoverType, toutiaoOriginal } = params.settingInfo;
|
|
22004
22009
|
const tmpCachePath = task.getTmpPath();
|
|
22005
22010
|
const api = axios$1.create({
|
|
22006
22011
|
headers: {
|
|
22007
|
-
cookie: params.cookies.map((it) => `${it.name}=${it.value}`).join(";")
|
|
22012
|
+
cookie: params.cookies.map((it) => `${it.name}=${it.value}`).join(";"),
|
|
22013
|
+
origin: "https://mp.toutiao.com",
|
|
22014
|
+
referer: "https://mp.toutiao.com/profile_v4/graphic/publish"
|
|
22008
22015
|
}
|
|
22009
22016
|
});
|
|
22010
22017
|
api.interceptors.response.use(
|
|
@@ -22048,7 +22055,7 @@ const mockAction$4 = async (task, params) => {
|
|
|
22048
22055
|
};
|
|
22049
22056
|
const originContentImages = extractImgTag(params.content);
|
|
22050
22057
|
const targetContentImages = await uploadImages(originContentImages);
|
|
22051
|
-
replaceImgSrc(params.content, (dom) => {
|
|
22058
|
+
const content = replaceImgSrc(params.content, (dom) => {
|
|
22052
22059
|
if (dom.attribs.src) {
|
|
22053
22060
|
const idx = originContentImages.findIndex((it) => it === dom.attribs.src);
|
|
22054
22061
|
dom.attribs.src = targetContentImages[idx].image_url;
|
|
@@ -22060,9 +22067,99 @@ const mockAction$4 = async (task, params) => {
|
|
|
22060
22067
|
}
|
|
22061
22068
|
return dom;
|
|
22062
22069
|
});
|
|
22063
|
-
const
|
|
22064
|
-
const
|
|
22065
|
-
|
|
22070
|
+
const coverUrl = toutiaoCoverType === "single" ? [toutiaoSingleCover] : toutiaoCoverType === "multiple" ? toutiaoMultCover : [];
|
|
22071
|
+
const coverRes = await uploadImages(coverUrl);
|
|
22072
|
+
const isSingleTitle = params.settingInfo.toutiaoTitleType === "single";
|
|
22073
|
+
const location = params.settingInfo.toutiaoLocation;
|
|
22074
|
+
const topics = params.settingInfo.toutiaoTopic || [];
|
|
22075
|
+
const multiTitleData = params.settingInfo.subTitles.map((title) => ({
|
|
22076
|
+
id: "0",
|
|
22077
|
+
visibility_level: 0,
|
|
22078
|
+
source: "author",
|
|
22079
|
+
old_source: "author",
|
|
22080
|
+
text: title,
|
|
22081
|
+
version: "author",
|
|
22082
|
+
ai_title: ""
|
|
22083
|
+
}));
|
|
22084
|
+
const topicContent = topics.map(
|
|
22085
|
+
(topic) => `<p><a class="tteditor-forum" data-name="${topic.word}" data-id="${topic.id}" data-concern-id="${topic.id}">#${topic.word}#</a ></p >`
|
|
22086
|
+
).join("");
|
|
22087
|
+
const extraData = {
|
|
22088
|
+
content_word_cnt: params.settingInfo.cntWord,
|
|
22089
|
+
is_multi_title: isSingleTitle ? 0 : 1,
|
|
22090
|
+
sub_titles: isSingleTitle ? [] : multiTitleData,
|
|
22091
|
+
gd_ext: {
|
|
22092
|
+
entrance: "",
|
|
22093
|
+
from_page: "publisher_mp",
|
|
22094
|
+
enter_from: "PC",
|
|
22095
|
+
device_platform: "mp",
|
|
22096
|
+
is_message: 0
|
|
22097
|
+
},
|
|
22098
|
+
tuwen_wtt_trans_flag: "0",
|
|
22099
|
+
info_source: {
|
|
22100
|
+
source_type: 5,
|
|
22101
|
+
source_link: "",
|
|
22102
|
+
time_format: "",
|
|
22103
|
+
position: {}
|
|
22104
|
+
},
|
|
22105
|
+
...location ? { city: location.label, city_code: location.value } : null
|
|
22106
|
+
};
|
|
22107
|
+
const publishData = {
|
|
22108
|
+
article_type: 0,
|
|
22109
|
+
source: 0,
|
|
22110
|
+
search_creation_info: '{"searchTopOne": 0, "abstract": "", "clue_id": ""}',
|
|
22111
|
+
title_id: "",
|
|
22112
|
+
educluecard: "",
|
|
22113
|
+
origin_debut_check_pgc_normal: 1,
|
|
22114
|
+
is_fans_article: 0,
|
|
22115
|
+
govern_forward: 0,
|
|
22116
|
+
praise: 0,
|
|
22117
|
+
disable_praise: 0,
|
|
22118
|
+
tree_plan_article: 0,
|
|
22119
|
+
star_order_id: "",
|
|
22120
|
+
star_order_name: "",
|
|
22121
|
+
customer_nick_name: "",
|
|
22122
|
+
activity_tag: 0,
|
|
22123
|
+
trends_writing_tag: 0,
|
|
22124
|
+
is_refute_rumor: 0,
|
|
22125
|
+
save: params.saveType === "publish" ? 1 : 0,
|
|
22126
|
+
timer_status: 0,
|
|
22127
|
+
timer_time: "",
|
|
22128
|
+
title: params.title,
|
|
22129
|
+
content: content + topicContent,
|
|
22130
|
+
extra: JSON.stringify(extraData),
|
|
22131
|
+
mp_editor_stat: toutiaoCoverType === "no" ? "{}" : '{"image": %d}',
|
|
22132
|
+
draft_form_data: JSON.stringify({
|
|
22133
|
+
coverType: COVER_TYPE[toutiaoCoverType]
|
|
22134
|
+
}),
|
|
22135
|
+
pgc_feed_covers: JSON.stringify(
|
|
22136
|
+
coverRes.map((item) => ({
|
|
22137
|
+
id: "",
|
|
22138
|
+
url: item.image_url,
|
|
22139
|
+
uri: item.image_uri,
|
|
22140
|
+
ic_uri: "",
|
|
22141
|
+
thumb_widt: item.image_width,
|
|
22142
|
+
thumb_heigh: item.image_height,
|
|
22143
|
+
extra: {
|
|
22144
|
+
from_content_uri: "",
|
|
22145
|
+
from_content: "0"
|
|
22146
|
+
}
|
|
22147
|
+
}))
|
|
22148
|
+
),
|
|
22149
|
+
article_ad_type: params.settingInfo.toutiaoAd === "yes" ? 3 : 2,
|
|
22150
|
+
claim_origin: toutiaoOriginal.includes("original") ? 1 : 0,
|
|
22151
|
+
claim_exclusive: toutiaoOriginal.includes("exclusive") ? 1 : 0
|
|
22152
|
+
};
|
|
22153
|
+
const publishResult = await api({
|
|
22154
|
+
method: "post",
|
|
22155
|
+
url: "https://mp.toutiao.com/mp/agw/article/publish?source=mp&type=article&aid=1",
|
|
22156
|
+
data: publishData,
|
|
22157
|
+
headers: {
|
|
22158
|
+
"content-type": "application/x-www-form-urlencoded"
|
|
22159
|
+
},
|
|
22160
|
+
defaultErrorMsg: "\u6587\u7AE0\u53D1\u5E03\u51FA\u73B0\u95EE\u9898\uFF0C\u8BF7\u8054\u7CFB\u5BA2\u670D"
|
|
22161
|
+
});
|
|
22162
|
+
return publishResult.data.data.pgc_id;
|
|
22066
22163
|
};
|
|
22067
22164
|
|
|
22068
22165
|
const toutiaoPublish = async (task, params) => {
|
package/dist/index.mjs
CHANGED
|
@@ -21971,6 +21971,11 @@ const searchToutiaoTopicList = async (task, params) => {
|
|
|
21971
21971
|
}
|
|
21972
21972
|
};
|
|
21973
21973
|
|
|
21974
|
+
const COVER_TYPE = {
|
|
21975
|
+
no: 1,
|
|
21976
|
+
single: 2,
|
|
21977
|
+
multiple: 3
|
|
21978
|
+
};
|
|
21974
21979
|
const errnoMap = {
|
|
21975
21980
|
20004020: "\u56FE\u7247\u4E0A\u4F20\u51FA\u73B0\u95EE\u9898\uFF0C\u8BF7\u91CD\u65B0\u7ED1\u5B9A\u8D26\u53F7\u540E\u518D\u5C1D\u8BD5",
|
|
21976
21981
|
7115: "\u6B63\u6587\u548C\u5C01\u9762\u56FE\u7247\u63A8\u8350\u4F7F\u752820M\u4EE5\u5185\u7684jpg\u548Cpng\u56FE\u7247",
|
|
@@ -21981,11 +21986,13 @@ const errnoMap = {
|
|
|
21981
21986
|
2005: "\u65E0\u58F0\u660E\u539F\u521B\u6743\u9650\uFF0C\u8BF7\u53D6\u6D88\u539F\u521B\u58F0\u660E\u6216\u7533\u8BF7\u539F\u521B\u6743\u9650\u540E\u518D\u5C1D\u8BD5"
|
|
21982
21987
|
};
|
|
21983
21988
|
const mockAction$4 = async (task, params) => {
|
|
21984
|
-
const { toutiaoSingleCover, toutiaoMultCover, toutiaoCoverType } = params.settingInfo;
|
|
21989
|
+
const { toutiaoSingleCover, toutiaoMultCover, toutiaoCoverType, toutiaoOriginal } = params.settingInfo;
|
|
21985
21990
|
const tmpCachePath = task.getTmpPath();
|
|
21986
21991
|
const api = axios$1.create({
|
|
21987
21992
|
headers: {
|
|
21988
|
-
cookie: params.cookies.map((it) => `${it.name}=${it.value}`).join(";")
|
|
21993
|
+
cookie: params.cookies.map((it) => `${it.name}=${it.value}`).join(";"),
|
|
21994
|
+
origin: "https://mp.toutiao.com",
|
|
21995
|
+
referer: "https://mp.toutiao.com/profile_v4/graphic/publish"
|
|
21989
21996
|
}
|
|
21990
21997
|
});
|
|
21991
21998
|
api.interceptors.response.use(
|
|
@@ -22029,7 +22036,7 @@ const mockAction$4 = async (task, params) => {
|
|
|
22029
22036
|
};
|
|
22030
22037
|
const originContentImages = extractImgTag(params.content);
|
|
22031
22038
|
const targetContentImages = await uploadImages(originContentImages);
|
|
22032
|
-
replaceImgSrc(params.content, (dom) => {
|
|
22039
|
+
const content = replaceImgSrc(params.content, (dom) => {
|
|
22033
22040
|
if (dom.attribs.src) {
|
|
22034
22041
|
const idx = originContentImages.findIndex((it) => it === dom.attribs.src);
|
|
22035
22042
|
dom.attribs.src = targetContentImages[idx].image_url;
|
|
@@ -22041,9 +22048,99 @@ const mockAction$4 = async (task, params) => {
|
|
|
22041
22048
|
}
|
|
22042
22049
|
return dom;
|
|
22043
22050
|
});
|
|
22044
|
-
const
|
|
22045
|
-
const
|
|
22046
|
-
|
|
22051
|
+
const coverUrl = toutiaoCoverType === "single" ? [toutiaoSingleCover] : toutiaoCoverType === "multiple" ? toutiaoMultCover : [];
|
|
22052
|
+
const coverRes = await uploadImages(coverUrl);
|
|
22053
|
+
const isSingleTitle = params.settingInfo.toutiaoTitleType === "single";
|
|
22054
|
+
const location = params.settingInfo.toutiaoLocation;
|
|
22055
|
+
const topics = params.settingInfo.toutiaoTopic || [];
|
|
22056
|
+
const multiTitleData = params.settingInfo.subTitles.map((title) => ({
|
|
22057
|
+
id: "0",
|
|
22058
|
+
visibility_level: 0,
|
|
22059
|
+
source: "author",
|
|
22060
|
+
old_source: "author",
|
|
22061
|
+
text: title,
|
|
22062
|
+
version: "author",
|
|
22063
|
+
ai_title: ""
|
|
22064
|
+
}));
|
|
22065
|
+
const topicContent = topics.map(
|
|
22066
|
+
(topic) => `<p><a class="tteditor-forum" data-name="${topic.word}" data-id="${topic.id}" data-concern-id="${topic.id}">#${topic.word}#</a ></p >`
|
|
22067
|
+
).join("");
|
|
22068
|
+
const extraData = {
|
|
22069
|
+
content_word_cnt: params.settingInfo.cntWord,
|
|
22070
|
+
is_multi_title: isSingleTitle ? 0 : 1,
|
|
22071
|
+
sub_titles: isSingleTitle ? [] : multiTitleData,
|
|
22072
|
+
gd_ext: {
|
|
22073
|
+
entrance: "",
|
|
22074
|
+
from_page: "publisher_mp",
|
|
22075
|
+
enter_from: "PC",
|
|
22076
|
+
device_platform: "mp",
|
|
22077
|
+
is_message: 0
|
|
22078
|
+
},
|
|
22079
|
+
tuwen_wtt_trans_flag: "0",
|
|
22080
|
+
info_source: {
|
|
22081
|
+
source_type: 5,
|
|
22082
|
+
source_link: "",
|
|
22083
|
+
time_format: "",
|
|
22084
|
+
position: {}
|
|
22085
|
+
},
|
|
22086
|
+
...location ? { city: location.label, city_code: location.value } : null
|
|
22087
|
+
};
|
|
22088
|
+
const publishData = {
|
|
22089
|
+
article_type: 0,
|
|
22090
|
+
source: 0,
|
|
22091
|
+
search_creation_info: '{"searchTopOne": 0, "abstract": "", "clue_id": ""}',
|
|
22092
|
+
title_id: "",
|
|
22093
|
+
educluecard: "",
|
|
22094
|
+
origin_debut_check_pgc_normal: 1,
|
|
22095
|
+
is_fans_article: 0,
|
|
22096
|
+
govern_forward: 0,
|
|
22097
|
+
praise: 0,
|
|
22098
|
+
disable_praise: 0,
|
|
22099
|
+
tree_plan_article: 0,
|
|
22100
|
+
star_order_id: "",
|
|
22101
|
+
star_order_name: "",
|
|
22102
|
+
customer_nick_name: "",
|
|
22103
|
+
activity_tag: 0,
|
|
22104
|
+
trends_writing_tag: 0,
|
|
22105
|
+
is_refute_rumor: 0,
|
|
22106
|
+
save: params.saveType === "publish" ? 1 : 0,
|
|
22107
|
+
timer_status: 0,
|
|
22108
|
+
timer_time: "",
|
|
22109
|
+
title: params.title,
|
|
22110
|
+
content: content + topicContent,
|
|
22111
|
+
extra: JSON.stringify(extraData),
|
|
22112
|
+
mp_editor_stat: toutiaoCoverType === "no" ? "{}" : '{"image": %d}',
|
|
22113
|
+
draft_form_data: JSON.stringify({
|
|
22114
|
+
coverType: COVER_TYPE[toutiaoCoverType]
|
|
22115
|
+
}),
|
|
22116
|
+
pgc_feed_covers: JSON.stringify(
|
|
22117
|
+
coverRes.map((item) => ({
|
|
22118
|
+
id: "",
|
|
22119
|
+
url: item.image_url,
|
|
22120
|
+
uri: item.image_uri,
|
|
22121
|
+
ic_uri: "",
|
|
22122
|
+
thumb_widt: item.image_width,
|
|
22123
|
+
thumb_heigh: item.image_height,
|
|
22124
|
+
extra: {
|
|
22125
|
+
from_content_uri: "",
|
|
22126
|
+
from_content: "0"
|
|
22127
|
+
}
|
|
22128
|
+
}))
|
|
22129
|
+
),
|
|
22130
|
+
article_ad_type: params.settingInfo.toutiaoAd === "yes" ? 3 : 2,
|
|
22131
|
+
claim_origin: toutiaoOriginal.includes("original") ? 1 : 0,
|
|
22132
|
+
claim_exclusive: toutiaoOriginal.includes("exclusive") ? 1 : 0
|
|
22133
|
+
};
|
|
22134
|
+
const publishResult = await api({
|
|
22135
|
+
method: "post",
|
|
22136
|
+
url: "https://mp.toutiao.com/mp/agw/article/publish?source=mp&type=article&aid=1",
|
|
22137
|
+
data: publishData,
|
|
22138
|
+
headers: {
|
|
22139
|
+
"content-type": "application/x-www-form-urlencoded"
|
|
22140
|
+
},
|
|
22141
|
+
defaultErrorMsg: "\u6587\u7AE0\u53D1\u5E03\u51FA\u73B0\u95EE\u9898\uFF0C\u8BF7\u8054\u7CFB\u5BA2\u670D"
|
|
22142
|
+
});
|
|
22143
|
+
return publishResult.data.data.pgc_id;
|
|
22047
22144
|
};
|
|
22048
22145
|
|
|
22049
22146
|
const toutiaoPublish = async (task, params) => {
|
package/package.json
CHANGED
|
@@ -3,18 +3,25 @@ import type { ActiomCommonParams } from "../../types";
|
|
|
3
3
|
import { mockAction } from "./mock";
|
|
4
4
|
|
|
5
5
|
export interface ToutiaoPublishParams extends Omit<ActiomCommonParams, "cookies"> {
|
|
6
|
+
saveType: "draft" | "publish"; // 保存成草稿 / 发布
|
|
6
7
|
cookies: Partial<CookiesSetDetails>[];
|
|
7
8
|
title: string;
|
|
8
9
|
content: string;
|
|
9
10
|
settingInfo: {
|
|
10
|
-
toutiaoCoverType: "single" | "multiple";
|
|
11
|
+
toutiaoCoverType: "single" | "multiple" | "no";
|
|
11
12
|
toutiaoTitleType: "single" | "multiple";
|
|
12
13
|
toutiaoSingleCover: string;
|
|
13
14
|
toutiaoMultCover: string[];
|
|
15
|
+
toutiaoAd: string; // 广告配置 - 投放广告/不投放广告
|
|
16
|
+
toutiaoOriginal: string; // 作品声明
|
|
17
|
+
toutiaoLocation?: { label: string; value: string }; // 位置
|
|
18
|
+
toutiaoTopic: { id: string; word: string }[]; // 话题
|
|
19
|
+
cntWord: number;
|
|
20
|
+
subTitles: string[]; // 多标题
|
|
14
21
|
};
|
|
15
22
|
}
|
|
16
23
|
|
|
17
|
-
export type PublishAction = CommonAction<ToutiaoPublishParams>;
|
|
24
|
+
export type PublishAction = CommonAction<ToutiaoPublishParams, string>;
|
|
18
25
|
|
|
19
26
|
export const toutiaoPublish: PublishAction = async (task, params) => {
|
|
20
27
|
task.logger.info("开始头条发布");
|
|
@@ -4,7 +4,7 @@ import { downloadImage, getFilenameFromUrl } from "@iflyrpa/share";
|
|
|
4
4
|
import axios, { type AxiosResponse } from "axios";
|
|
5
5
|
import FormData from "form-data";
|
|
6
6
|
|
|
7
|
-
import type { PublishAction } from ".";
|
|
7
|
+
import type { PublishAction, ToutiaoPublishParams } from ".";
|
|
8
8
|
import type { Toutiao } from "../../types";
|
|
9
9
|
import { extractImgTag, replaceImgSrc } from "../../utils";
|
|
10
10
|
|
|
@@ -14,6 +14,12 @@ interface CommonResponse<T = unknown> {
|
|
|
14
14
|
message: string;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
const COVER_TYPE: Record<ToutiaoPublishParams["settingInfo"]["toutiaoCoverType"], number> = {
|
|
18
|
+
no: 1,
|
|
19
|
+
single: 2,
|
|
20
|
+
multiple: 3,
|
|
21
|
+
};
|
|
22
|
+
|
|
17
23
|
const errnoMap: Record<number, string> = {
|
|
18
24
|
20004020: "图片上传出现问题,请重新绑定账号后再尝试",
|
|
19
25
|
7115: "正文和封面图片推荐使用20M以内的jpg和png图片",
|
|
@@ -25,12 +31,14 @@ const errnoMap: Record<number, string> = {
|
|
|
25
31
|
};
|
|
26
32
|
|
|
27
33
|
export const mockAction: PublishAction = async (task, params) => {
|
|
28
|
-
const { toutiaoSingleCover, toutiaoMultCover, toutiaoCoverType } = params.settingInfo;
|
|
34
|
+
const { toutiaoSingleCover, toutiaoMultCover, toutiaoCoverType, toutiaoOriginal } = params.settingInfo;
|
|
29
35
|
const tmpCachePath = task.getTmpPath();
|
|
30
36
|
|
|
31
37
|
const api = axios.create({
|
|
32
38
|
headers: {
|
|
33
39
|
cookie: params.cookies.map((it) => `${it.name}=${it.value}`).join(";"),
|
|
40
|
+
origin: "https://mp.toutiao.com",
|
|
41
|
+
referer: "https://mp.toutiao.com/profile_v4/graphic/publish",
|
|
34
42
|
},
|
|
35
43
|
});
|
|
36
44
|
|
|
@@ -91,7 +99,7 @@ export const mockAction: PublishAction = async (task, params) => {
|
|
|
91
99
|
// 1. 提取并上传正文中的图片
|
|
92
100
|
const originContentImages = extractImgTag(params.content);
|
|
93
101
|
const targetContentImages = await uploadImages(originContentImages);
|
|
94
|
-
// 替换正文中的图片
|
|
102
|
+
// 2. 替换正文中的图片
|
|
95
103
|
const content = replaceImgSrc(params.content, (dom) => {
|
|
96
104
|
if (dom.attribs.src) {
|
|
97
105
|
const idx = originContentImages.findIndex((it) => it === dom.attribs.src);
|
|
@@ -105,9 +113,110 @@ export const mockAction: PublishAction = async (task, params) => {
|
|
|
105
113
|
return dom;
|
|
106
114
|
});
|
|
107
115
|
|
|
108
|
-
//
|
|
109
|
-
const
|
|
110
|
-
|
|
116
|
+
// 3. 上传横版封面
|
|
117
|
+
const coverUrl =
|
|
118
|
+
toutiaoCoverType === "single" ? [toutiaoSingleCover] : toutiaoCoverType === "multiple" ? toutiaoMultCover : [];
|
|
119
|
+
const coverRes = await uploadImages(coverUrl);
|
|
120
|
+
|
|
121
|
+
// 4. 构造发布数据
|
|
122
|
+
const isSingleTitle = params.settingInfo.toutiaoTitleType === "single";
|
|
123
|
+
const location = params.settingInfo.toutiaoLocation;
|
|
124
|
+
const topics = params.settingInfo.toutiaoTopic || [];
|
|
125
|
+
|
|
126
|
+
const multiTitleData = params.settingInfo.subTitles.map((title) => ({
|
|
127
|
+
id: "0",
|
|
128
|
+
visibility_level: 0,
|
|
129
|
+
source: "author",
|
|
130
|
+
old_source: "author",
|
|
131
|
+
text: title,
|
|
132
|
+
version: "author",
|
|
133
|
+
ai_title: "",
|
|
134
|
+
}));
|
|
135
|
+
|
|
136
|
+
const topicContent = topics
|
|
137
|
+
.map(
|
|
138
|
+
(topic) =>
|
|
139
|
+
`<p><a class="tteditor-forum" data-name="${topic.word}" data-id="${topic.id}" data-concern-id="${topic.id}">#${topic.word}#</a ></p >`,
|
|
140
|
+
)
|
|
141
|
+
.join("");
|
|
142
|
+
|
|
143
|
+
const extraData = {
|
|
144
|
+
content_word_cnt: params.settingInfo.cntWord,
|
|
145
|
+
is_multi_title: isSingleTitle ? 0 : 1,
|
|
146
|
+
sub_titles: isSingleTitle ? [] : multiTitleData,
|
|
147
|
+
gd_ext: {
|
|
148
|
+
entrance: "",
|
|
149
|
+
from_page: "publisher_mp",
|
|
150
|
+
enter_from: "PC",
|
|
151
|
+
device_platform: "mp",
|
|
152
|
+
is_message: 0,
|
|
153
|
+
},
|
|
154
|
+
tuwen_wtt_trans_flag: "0",
|
|
155
|
+
info_source: {
|
|
156
|
+
source_type: 5,
|
|
157
|
+
source_link: "",
|
|
158
|
+
time_format: "",
|
|
159
|
+
position: {},
|
|
160
|
+
},
|
|
161
|
+
...(location ? { city: location.label, city_code: location.value } : null),
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const publishData = {
|
|
165
|
+
article_type: 0,
|
|
166
|
+
source: 0,
|
|
167
|
+
search_creation_info: '{"searchTopOne": 0, "abstract": "", "clue_id": ""}',
|
|
168
|
+
title_id: "",
|
|
169
|
+
educluecard: "",
|
|
170
|
+
origin_debut_check_pgc_normal: 1,
|
|
171
|
+
is_fans_article: 0,
|
|
172
|
+
govern_forward: 0,
|
|
173
|
+
praise: 0,
|
|
174
|
+
disable_praise: 0,
|
|
175
|
+
tree_plan_article: 0,
|
|
176
|
+
star_order_id: "",
|
|
177
|
+
star_order_name: "",
|
|
178
|
+
customer_nick_name: "",
|
|
179
|
+
activity_tag: 0,
|
|
180
|
+
trends_writing_tag: 0,
|
|
181
|
+
is_refute_rumor: 0,
|
|
182
|
+
save: params.saveType === "publish" ? 1 : 0,
|
|
183
|
+
timer_status: 0,
|
|
184
|
+
timer_time: "",
|
|
185
|
+
title: params.title,
|
|
186
|
+
content: content + topicContent,
|
|
187
|
+
extra: JSON.stringify(extraData),
|
|
188
|
+
mp_editor_stat: toutiaoCoverType === "no" ? "{}" : '{"image": %d}',
|
|
189
|
+
draft_form_data: JSON.stringify({
|
|
190
|
+
coverType: COVER_TYPE[toutiaoCoverType],
|
|
191
|
+
}),
|
|
192
|
+
pgc_feed_covers: JSON.stringify(
|
|
193
|
+
coverRes.map((item) => ({
|
|
194
|
+
id: "",
|
|
195
|
+
url: item.image_url,
|
|
196
|
+
uri: item.image_uri,
|
|
197
|
+
ic_uri: "",
|
|
198
|
+
thumb_widt: item.image_width,
|
|
199
|
+
thumb_heigh: item.image_height,
|
|
200
|
+
extra: {
|
|
201
|
+
from_content_uri: "",
|
|
202
|
+
from_content: "0",
|
|
203
|
+
},
|
|
204
|
+
})),
|
|
205
|
+
),
|
|
206
|
+
article_ad_type: params.settingInfo.toutiaoAd === "yes" ? 3 : 2,
|
|
207
|
+
claim_origin: toutiaoOriginal.includes("original") ? 1 : 0,
|
|
208
|
+
claim_exclusive: toutiaoOriginal.includes("exclusive") ? 1 : 0,
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
const publishResult = await api<{ data: { pgc_id: string } }>({
|
|
212
|
+
method: "post",
|
|
213
|
+
url: "https://mp.toutiao.com/mp/agw/article/publish?source=mp&type=article&aid=1",
|
|
214
|
+
data: publishData,
|
|
215
|
+
headers: {
|
|
216
|
+
"content-type": "application/x-www-form-urlencoded",
|
|
217
|
+
},
|
|
218
|
+
defaultErrorMsg: "文章发布出现问题,请联系客服",
|
|
219
|
+
});
|
|
111
220
|
|
|
112
|
-
|
|
221
|
+
return publishResult.data.data.pgc_id;
|
|
113
222
|
};
|