返回 AiToEarn
publish.ts
根目录 / project / aitoearn-electron / src / icp / publish.ts
1 /*
2 * @Author: nevin
3 * @Date: 2025-01-23 15:48:14
4 * @LastEditTime: 2025-02-17 21:32:38
5 * @LastEditors: nevin
6 * @Description: publish 发布
7 */
8
9 import { CorrectQuery, CorrectResponse } from '@/global/table';
10 import { PubRecordModel } from '@/views/publish/comment';
11 import { VideoPul } from '@/views/publish/children/videoPage/comment';
12 import { PlatType } from '../../commont/AccountEnum';
13 import { PubStatus, PubType } from '../../commont/publish/PublishEnum';
14 import {
15 type IGetLocationDataParams,
16 IGetLocationResponse,
17 IGetMixListResponse,
18 IGetTopicsResponse,
19 type IGetUsersParams,
20 IGetUsersResponse,
21 } from '../../electron/main/plat/plat.type';
22 import { AccountInfo, AccountPlatInfoMap } from '@/views/account/comment';
23 import { AccountModel } from '../../electron/db/models/account';
24 import {
25 DouyinActivityDetailResponse,
26 DouyinActivityListResponse,
27 DouyinActivityTagsResponse,
28 DouyinAllHotDataResponse,
29 DouyinHotDataResponse,
30 } from '../../electron/plat/douyin/douyin.type';
31 import { IRequestNetResult } from '../../electron/plat/requestNet';
32 import { WeChatVideoApiResponse } from '../../electron/plat/shipinhao/wxShp.type';
33 import { parseTopicString } from '../utils';
34 import { PublishVideoResult } from '../../electron/main/plat/module';
35 import { ImgTextModel } from '../../electron/db/models/imgText';
36 import type { pubRecordListQuery } from '../../electron/global/table';
37
38 export const PubStatusCnMap = {
39 [PubStatus.UNPUBLISH]: '未发布',
40 [PubStatus.RELEASED]: '已发布',
41 [PubStatus.FAIL]: '发布失败',
42 [PubStatus.PartSuccess]: '部分成功',
43 [PubStatus.Audit]: '审核中',
44 };
45
46 // 创建发布记录
47 export async function icpCreatePubRecord(pubRecord: Partial<PubRecordModel>) {
48 console.log('创建发布记录:', pubRecord);
49 const res: PubRecordModel = await window.ipcRenderer.invoke(
50 'ICP_PUBLISH_CREATE_PUB_RECORD',
51 {
52 ...pubRecord,
53 id: undefined,
54 status: PubStatus.UNPUBLISH,
55 },
56 );
57 return res;
58 }
59
60 // 创建图文发布记录
61 export async function icpCreateImgTextPubRecord(
62 pubRecord: Partial<ImgTextModel>,
63 ) {
64 const platInfo = AccountPlatInfoMap.get(pubRecord.type!)!;
65 const { topics, cleanedString } = parseTopicString(pubRecord.desc || '');
66 pubRecord.topics = [...new Set(pubRecord.topics?.concat(topics))];
67 pubRecord.desc = cleanedString;
68 pubRecord.imagesPath = [...pubRecord.imagesPath!].splice(
69 0,
70 platInfo.commonPubParamsConfig.imgTextConfig?.imagesMax,
71 );
72 console.log('创建图文发布记录:', pubRecord);
73 const res: ImgTextModel = await window.ipcRenderer.invoke(
74 'ICP_PUBLISH_CREATE_IMG_TEXT_PUL',
75 {
76 ...pubRecord,
77 id: undefined,
78 },
79 );
80 return res;
81 }
82
83 /**
84 * 创建视频发布记录
85 * 这个函数中做了一些处理
86 * 1. 将描述中的标题取出,并且放到话题字段,再去重
87 * @param pubRecord
88 */
89 export async function icpCreateVideoPubRecord(pubRecord: Partial<VideoPul>) {
90 const { topics, cleanedString } = parseTopicString(pubRecord.desc || '');
91 pubRecord.topics = [...new Set(pubRecord.topics?.concat(topics))];
92 pubRecord.desc = cleanedString;
93 console.log('创建视频发布记录:', pubRecord);
94 const res: VideoPul = await window.ipcRenderer.invoke(
95 'ICP_PUBLISH_CREATE_VIDEO_PUL',
96 {
97 ...pubRecord,
98 id: undefined,
99 },
100 );
101 return res;
102 }
103
104 // 获取图文发布记录
105 export async function icpGetImgTextList(pubRecordId: number) {
106 const res: ImgTextModel[] = await window.ipcRenderer.invoke(
107 'ICP_PUBLISH_GET_IMG_TEXT_LIST',
108 pubRecordId,
109 );
110 return res;
111 }
112
113 // 获取视频发布记录
114 export async function icpGetPubVideoRecord(pubRecordId: number) {
115 const res: VideoPul[] = await window.ipcRenderer.invoke(
116 'ICP_PUB_GET_VIDEO_RECORD',
117 pubRecordId,
118 );
119 return res;
120 }
121
122 // 发布视频
123 export async function icpPubVideo(pubRecordId: number) {
124 const res: PublishVideoResult[] = await window.ipcRenderer.invoke(
125 'ICP_PUB_VIDEO',
126 pubRecordId,
127 );
128 return res;
129 }
130
131 // 发布图文
132 export async function icpPubImgText(pubRecordId: number) {
133 const res: PublishVideoResult[] = await window.ipcRenderer.invoke(
134 'ICP_PUBLISH_IMG_TEXT',
135 pubRecordId,
136 );
137 return res;
138 }
139
140 // 获取发布记录列表
141 export async function icpGetPubRecordList(
142 page: CorrectQuery,
143 query?: pubRecordListQuery,
144 ) {
145 const res: CorrectResponse<PubRecordModel> = await window.ipcRenderer.invoke(
146 'ICP_PUBLISH_GET_PUB_RECORD_LIST',
147 page,
148 query,
149 );
150 return res;
151 }
152
153 // 获取草稿列表
154 export async function icpGetPubRecordDraftsList(
155 page: CorrectQuery,
156 query?: any,
157 ) {
158 const res: CorrectResponse<PubRecordModel> = await window.ipcRenderer.invoke(
159 'ICP_PUBLISH_GET_PUB_RECORD_DRAFTS_LIST',
160 page,
161 query,
162 );
163 return res;
164 }
165
166 // 获取发布记录信息
167 export async function icpGetPubRecordInfo(id: number) {
168 const res: PubRecordModel = await window.ipcRenderer.invoke(
169 'ICP_PUBLISH_GET_PUB_RECORD_INFO',
170 id,
171 );
172 return res;
173 }
174
175 // 获取发布记录信息
176 export async function icpGetPubRecordItemList(page: CorrectQuery, id: number) {
177 const res: CorrectResponse<VideoPul | never> =
178 await window.ipcRenderer.invoke(
179 'ICP_PUBLISH_GET_PUB_RECORD_ITEM_LIST',
180 page,
181 id,
182 );
183 return res;
184 }
185
186 /**
187 * 获取视频发布列表
188 * @returns
189 * @param page
190 * @param query
191 */
192 export async function icpGetVideoPulList(
193 page: CorrectQuery,
194 query: { type?: PlatType; time?: [string, string]; title?: string },
195 ) {
196 const res: CorrectResponse<VideoPul> = await window.ipcRenderer.invoke(
197 'ICP_PUBLISH_GET_VIDEO_PUL_LIST',
198 page,
199 query,
200 );
201 return res;
202 }
203
204 // 获取发布的视频信息
205 export async function icpGetVideoPulInfo(id: number) {
206 const res: VideoPul = await window.ipcRenderer.invoke(
207 'ICP_PUBLISH_GET_VIDEO_PUL_INFO',
208 id,
209 );
210 return res;
211 }
212
213 // 获取不同类型的视频发布的总数
214 export async function icpGetVideoPulTypeCount(type?: PlatType) {
215 const res: number = await window.ipcRenderer.invoke(
216 'ICP_PUBLISH_GET_VIDEO_PUL_TYPE_COUNT',
217 type,
218 );
219 return res;
220 }
221
222 // 删除发布草稿
223 export async function icpPublishDelPubRecordById(id: number) {
224 const res: boolean = await window.ipcRenderer.invoke(
225 'ICP_PUBLISH_DEL_PUB_RECORD_BY_ID',
226 id,
227 );
228 return res;
229 }
230
231 // 删除草稿中的项目
232 const delItemIpcMap = new Map([
233 [PubType.VIDEO, 'ICP_PUBLISH_DEL_PUB_RECORD_ITEM_VIDEO'],
234 ]);
235 export async function icpPublishDelPubRecordItem(
236 id: number,
237 type: PubType,
238 accountId: number,
239 ) {
240 const ipcStr = delItemIpcMap.get(type);
241 if (!ipcStr) return false;
242
243 const res: boolean = await window.ipcRenderer.invoke(ipcStr, id, accountId);
244 return res;
245 }
246
247 // 获取各个平台话题
248 export async function icpGetTopic(account: AccountInfo, keyword: string) {
249 const res: IGetTopicsResponse = await window.ipcRenderer.invoke(
250 'ICP_PUBLISH_GET_TOPIC',
251 account,
252 keyword,
253 );
254 return res;
255 }
256
257 // 获取合集数据
258 export async function icpGetMixList(account: AccountInfo) {
259 const res: IGetMixListResponse = await window.ipcRenderer.invoke(
260 'ICP_PUBLISH_GET_MIX_LIST',
261 account,
262 );
263 return res;
264 }
265
266 // 获取各个平台位置数据
267 export async function icpGetLocationData(params: IGetLocationDataParams) {
268 const res: IGetLocationResponse = await window.ipcRenderer.invoke(
269 'ICP_PUBLISH_GET_LOCATION',
270 params,
271 );
272 return res;
273 }
274
275 // 获取抖音热点数据
276 export async function icpGetDoytinHot(account: AccountModel, query: string) {
277 const res: DouyinHotDataResponse = await window.ipcRenderer.invoke(
278 'ICP_PUBLISH_GET_DOYTIN_HOT',
279 account,
280 query,
281 );
282 return res;
283 }
284
285 // 获取抖音所有热点数据
286 export async function icpGetDoytinHotAll() {
287 const res: DouyinAllHotDataResponse = await window.ipcRenderer.invoke(
288 'ICP_PUBLISH_GET_ALL_DOYTIN_HOT',
289 );
290 return res;
291 }
292
293 // 获取抖音的活动列表
294 export async function icpGetDouyinActivity(account: AccountModel) {
295 const res: DouyinActivityListResponse = await window.ipcRenderer.invoke(
296 'ICP_PUBLISH_GET_DOUYIN_ACTIVITY',
297 account,
298 );
299 return res;
300 }
301
302 // 获取抖音的活动详情
303 export async function getDouyinActivityDetails(
304 account: AccountModel,
305 activity_id: string,
306 ) {
307 const res: DouyinActivityDetailResponse = await window.ipcRenderer.invoke(
308 'ICP_PUBLISH_GET_DOUYIN_ACTIVITY_DETAILS',
309 account,
310 activity_id,
311 );
312 return res;
313 }
314
315 // 获取抖音活动标签
316 export async function icpGetActivityTags(account: AccountModel) {
317 const res: IRequestNetResult<DouyinActivityTagsResponse> =
318 await window.ipcRenderer.invoke(
319 'ICP_PUBLISH_GET_DOUYIN_ACTIVITY_TAGS',
320 account,
321 );
322 return res;
323 }
324
325 // 获取微信视频号的活动列表
326 export async function getSphActivity(account: AccountModel, query: string) {
327 const res: IRequestNetResult<WeChatVideoApiResponse> =
328 await window.ipcRenderer.invoke(
329 'ICP_PUBLISH_GET_WXSPH_ACTIVITY',
330 account,
331 query,
332 );
333 return res;
334 }
335
336 // 获取所有平台的用户数据
337 export async function icpGetUsers(params: IGetUsersParams) {
338 const res: IGetUsersResponse = await window.ipcRenderer.invoke(
339 'ICP_PUBLISH_GET_USERS',
340 params,
341 );
342 return res;
343 }
344
344 lines TYPESCRIPT