Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat: 小红书和抖音图文发布参数归一化完成。
gaoSirc6bea6bfbea7
diff --git a/electron/main/plat/PlatformBase.ts b/electron/main/plat/PlatformBase.tsindex 016a3a91..404c3e6a 100644--- a/electron/main/plat/PlatformBase.ts+++ b/electron/main/plat/PlatformBase.ts@@ -16,6 +16,7 @@ import {IGetTopicsResponse,IGetUsersParams,IGetUsersResponse,+ IImgTextPublishParams,IVideoPublishParams,ResponsePageInfo,StatisticsData,@@ -182,7 +183,7 @@ export abstract class PlatformBase {): Promise<boolean>;/**- * 在该平台发布视频+ * 视频发布*/abstract videoPublish(params: IVideoPublishParams,@@ -190,7 +191,18 @@ export abstract class PlatformBase {callback: VideoCallbackType,): Promise<PublishVideoResult>;- // 获取这个平台的话题+ /**+ * 图文发布,有些平台不支持图文发布+ */+ imgTextPublish(+ params: IImgTextPublishParams,+ // 获取发布进度的回调函数+ callback: VideoCallbackType,+ ): Promise<PublishVideoResult> {+ throw `平台${this.type}不支持图文发布`;+ }++ // 话题数据获取abstract getTopics(params: IGetTopicsParams): Promise<IGetTopicsResponse>;// 获取位置数据diff --git a/electron/main/plat/plat.type.ts b/electron/main/plat/plat.type.tsindex ad8d3103..74e44ec1 100644--- a/electron/main/plat/plat.type.ts+++ b/electron/main/plat/plat.type.ts@@ -84,8 +84,8 @@ export interface WxSphEvent {eventName: string;}-// 发布视频入参-export interface IVideoPublishParams {+// 发布通用参数+export interface IPublishParams {// 调用该平台的cookiescookies: CookiesType;// 标题,有些平台没有标题@@ -94,10 +94,6 @@ export interface IVideoPublishParams {desc: string;// 话题topics: string[];- // 视频的路径- videoPath: string;- // 封面路径- coverPath: string;// 可见性visibleType: VisibleTypeEnum;// 各个平台的差异化参数@@ -108,9 +104,25 @@ export interface IVideoPublishParams {location?: ILocationDataItem;// @用户mentionedUserInfo?: ILableValue[];+ // 封面路径+ coverPath: string;+}++// 视频发布参数+export interface IVideoPublishParams extends IPublishParams {+ // 视频的路径+ videoPath: string;other?: any;}+// 图文发布参数+export interface IImgTextPublishParams extends IPublishParams {+ // 图片路径+ imagesPath: string[];+ // token,只有抖音需要+ token?: string;+}+// 获取用户参数export interface IGetUsersParams {keyword: string;diff --git a/electron/main/plat/platforms/douyin/index.ts b/electron/main/plat/platforms/douyin/index.tsindex d12abe37..2472d6aa 100644--- a/electron/main/plat/platforms/douyin/index.ts+++ b/electron/main/plat/platforms/douyin/index.ts@@ -16,12 +16,17 @@ import {IGetTopicsParams,IGetTopicsResponse,IGetUsersParams,+ IImgTextPublishParams,+ IPublishParams,IVideoPublishParams,VideoCallbackType,WorkData,} from '../../plat.type';import { PublishVideoResult } from '../../module';-import { douyinService } from '../../../../plat/douyin';+import {+ DouyinPlatformSettingType,+ douyinService,+} from '../../../../plat/douyin';import { AccountType } from '../../../../../commont/AccountEnum';import { AccountModel } from '../../../../db/models/account';import { VisibleTypeEnum } from '../../../../../commont/publish/PublishEnum';@@ -378,55 +383,58 @@ export class Douyin extends PlatformBase {return false;}+ pubParamsParse(params: IPublishParams): DouyinPlatformSettingType {+ const douyinParams = params.diffParams![AccountType.Douyin];+ return {+ userDeclare: douyinParams?.selfDeclare,+ activity: douyinParams?.activitys?.map((v) => {+ return {+ label: v.label,+ value: `${v.value}`,+ };+ }),+ hot_sentence: douyinParams?.hotPoint?.label,+ mentionedUserInfo: params.mentionedUserInfo?.map((v) => {+ return {+ nickName: v.label,+ uid: `${v.value}`,+ };+ }),+ title: params.title,+ topics: params.topics,+ caption: params.desc,+ cover: params.coverPath,+ timingTime: params.timingTime?.getTime(),+ // 可见性+ visibility_type:+ params.visibleType === VisibleTypeEnum.Public+ ? 0+ : params.visibleType === VisibleTypeEnum.Private+ ? 1+ : 2,+ // 地址+ ...(params.location+ ? {+ poiInfo: {+ poiId: `${params.location.id}`,+ poiName: params.location.name,+ },+ }+ : {}),+ };+ }+async videoPublish(params: IVideoPublishParams,callback: VideoCallbackType,): Promise<PublishVideoResult> {return new Promise(async (resolve) => {- const douyinParams = params.diffParams![AccountType.Douyin];-const result = await douyinService.publishVideoWorkApi(JSON.stringify(params.cookies),params.other!,params.videoPath,- {- userDeclare: douyinParams?.selfDeclare,- activity: douyinParams?.activitys?.map((v) => {- return {- label: v.label,- value: `${v.value}`,- };- }),- hot_sentence: douyinParams?.hotPoint?.label,- mentionedUserInfo: params.mentionedUserInfo?.map((v) => {- return {- nickName: v.label,- uid: `${v.value}`,- };- }),- title: params.title,- topics: params.topics,- caption: params.desc,- cover: params.coverPath,- timingTime: params.timingTime?.getTime(),- // 可见性- visibility_type:- params.visibleType === VisibleTypeEnum.Public- ? 0- : params.visibleType === VisibleTypeEnum.Private- ? 1- : 2,- // 地址- ...(params.location- ? {- poiInfo: {- poiId: `${params.location.id}`,- poiName: params.location.name,- },- }- : {}),- },+ this.pubParamsParse(params),callback,).catch((e) => {@@ -505,6 +513,40 @@ export class Douyin extends PlatformBase {}),};}++ async imgTextPublish(+ params: IImgTextPublishParams,+ // 获取发布进度的回调函数+ callback: VideoCallbackType,+ ): Promise<PublishVideoResult> {+ return new Promise(async (resolve) => {+ const result = await douyinService+ .publishImageWorkApi(+ JSON.stringify(params.cookies),+ params.token!,+ params.imagesPath,+ this.pubParamsParse(params),+ )+ .catch((e) => {+ resolve({+ code: 0,+ msg: e,+ });+ });+ if (!result.publishId)+ return resolve({+ code: 0,+ msg: '网络繁忙,请稍后重试',+ });++ return resolve({+ code: 1,+ msg: '发布成功',+ dataId: result.publishId,+ previewVideoLink: result.shareLink,+ });+ });+ }}const douyin = new Douyin();diff --git a/electron/main/plat/platforms/xhs/index.ts b/electron/main/plat/platforms/xhs/index.tsindex 4ebae4ab..207782ec 100644--- a/electron/main/plat/platforms/xhs/index.ts+++ b/electron/main/plat/platforms/xhs/index.ts@@ -16,12 +16,17 @@ import {IGetTopicsParams,IGetTopicsResponse,IGetUsersParams,+ IImgTextPublishParams,+ IPublishParams,IVideoPublishParams,VideoCallbackType,WorkData,} from '../../plat.type';import { PublishVideoResult } from '../../module';-import { xiaohongshuService } from '../../../../plat/xiaohongshu';+import {+ xiaohongshuService,+ XSLPlatformSettingType,+} from '../../../../plat/xiaohongshu';import { AccountType } from '../../../../../commont/AccountEnum';import { AccountModel } from '../../../../db/models/account';import { VisibleTypeEnum } from '../../../../../commont/publish/PublishEnum';@@ -306,36 +311,7 @@ export class Xhs extends PlatformBase {.publishVideoWorkApi(JSON.stringify(params.cookies),params.videoPath,- {- cover: params.coverPath,- desc: params.desc,- title: params.title,- topicsDetail:- params.topics?.map((v) => ({- topicId: v,- topicName: v,- })) || [],- timingTime: params.timingTime?.getTime(),- privacy: params.visibleType !== VisibleTypeEnum.Public,- // 位置- poiInfo: params.location- ? {- poiType: params.location.poi_type!,- poiId: params.location.id,- poiName: params.location.name,- poiAddress: params.location.simpleAddress,- }- : undefined,- // @用户- mentionedUserInfo: params.mentionedUserInfo- ? params.mentionedUserInfo.map((v) => {- return {- nickName: v.label,- uid: `${v.value}`,- };- })- : undefined,- },+ this.pubParamsParse(params),callback,).catch((err) => {@@ -419,6 +395,73 @@ export class Xhs extends PlatformBase {}),};}++ pubParamsParse(params: IPublishParams): XSLPlatformSettingType {+ return {+ cover: params.coverPath,+ desc: params.desc,+ title: params.title,+ topicsDetail:+ params.topics?.map((v) => ({+ topicId: v,+ topicName: v,+ })) || [],+ timingTime: params.timingTime?.getTime(),+ privacy: params.visibleType !== VisibleTypeEnum.Public,+ // 位置+ poiInfo: params.location+ ? {+ poiType: params.location.poi_type!,+ poiId: params.location.id,+ poiName: params.location.name,+ poiAddress: params.location.simpleAddress,+ }+ : undefined,+ // @用户+ mentionedUserInfo: params.mentionedUserInfo+ ? params.mentionedUserInfo.map((v) => {+ return {+ nickName: v.label,+ uid: `${v.value}`,+ };+ })+ : undefined,+ };+ }++ async imgTextPublish(+ params: IImgTextPublishParams,+ // 获取发布进度的回调函数+ callback: VideoCallbackType,+ ): Promise<PublishVideoResult> {+ return new Promise(async (resolve) => {+ const result = await xiaohongshuService+ .publishImageWorkApi(+ JSON.stringify(params.cookies),+ params.imagesPath,+ this.pubParamsParse(params),+ )+ .catch((err) => {+ resolve({+ code: 0,+ msg: err,+ });+ });++ if (!result || !result.publishId)+ return resolve({+ code: 0,+ msg: '网络繁忙,请稍后重试!',+ });++ return resolve({+ code: 1,+ msg: '成功!',+ dataId: result!.publishId,+ previewVideoLink: result.shareLink,+ });+ });+ }}const xhs = new Xhs();diff --git a/electron/main/test/controller.ts b/electron/main/test/controller.tsindex 12643713..b8c5d062 100644--- a/electron/main/test/controller.ts+++ b/electron/main/test/controller.ts@@ -8,7 +8,6 @@import { Controller, Icp, Inject } from '../core/decorators';import { TestService } from './service';import { douyinService } from '../../plat/douyin/index';-import { getNowTimeStamp } from '../../util/time';import { xiaohongshuService } from '../../plat/xiaohongshu/index';import { shipinhaoService } from '../../plat/shipinhao/index';@@ -20,31 +19,6 @@ export class TestController {@Inject(TestService)private readonly testService!: TestService;- /**- * 测试-抖音发布- */- @Icp('ICP_TEST_DOUYIN_VIDEO_PUB')- async testDouyinVideoPub(event: Electron.IpcMainInvokeEvent): Promise<any> {- const account = await this.testService.getInfoById(2);- if (!account) return;- const res = await douyinService.publishVideoWorkApi(- account.loginCookie,- account.token!,- 'C:\\Users\\Administrator\\Desktop\\相册.mp4',- {- cover:- 'https://help-static-aliyun-doc.aliyuncs.com/assets/img/zh-CN/6069415171/p792953.png',- title: '元宵节快乐',- topics: ['元宵节'],- timingTime: getNowTimeStamp(),- visibility_type: 0,- },- () => {},- );-- return 1;- }-/*** 测试-抖音登录*/@@ -65,35 +39,6 @@ export class TestController {};}- /**- * 测试2-抖音发布- */- @Icp('ICP_TEST_DOUYIN_VIDEO_PUB_2')- async testDouyinVideoPub2(- event: Electron.IpcMainInvokeEvent,- cookie: any,- token: string,- ): Promise<any> {- if (!cookie) return;- if (!token) return;-- const res = await douyinService.publishVideoWorkApi(- cookie,- token!,- videoPath,- {- cover: coverPath,- title: '元宵节快乐',- topics: ['元宵节'],- timingTime: getNowTimeStamp(),- visibility_type: 0,- },- () => {},- );-- return 1;- }-/*** 每10秒运行一次*/diff --git a/electron/plat/douyin/index.ts b/electron/plat/douyin/index.tsindex aa098516..536099cc 100644--- a/electron/plat/douyin/index.ts+++ b/electron/plat/douyin/index.ts@@ -24,7 +24,7 @@ import requestNet from '../requestNet';import { jsonToQueryString } from '../../util';import { DeclarationDouyin } from './common.douyin';-type PlatformSettingType = {+export type DouyinPlatformSettingType = {// 自主声明userDeclare?: DeclarationDouyin;// 合集@@ -509,7 +509,7 @@ export class DouyinService {cookies: string,tokens: any,filePath: string,- platformSetting: PlatformSettingType,+ platformSetting: DouyinPlatformSettingType,callback: (progress: number, msg?: string) => void,): Promise<any> {console.log('开始发布视频作品,参数:', platformSetting);@@ -651,7 +651,7 @@ export class DouyinService {cookies: any,tokens: any,imagePath: string[],- platformSetting: any,+ platformSetting: DouyinPlatformSettingType,): Promise<any> {console.log(`[${new Date().toLocaleString()}] 开始发布图片作品,参数:`, {cookies: typeof cookies === 'string' ? cookies.length : cookies.length,@@ -1694,7 +1694,7 @@ export class DouyinService {}// 发布视频、v2 api参数处理- private getPublishPublicParamsV2(platformSetting: PlatformSettingType) {+ private getPublishPublicParamsV2(platformSetting: DouyinPlatformSettingType) {console.log('platformSetting:', platformSetting);const parmasDisposeOK = this.getPublishPublicParams(platformSetting);@@ -1785,7 +1785,7 @@ export class DouyinService {* 获取视频|图文公共发布参数* @param platformSetting 平台设置参数*/- private getPublishPublicParams(platformSetting: PlatformSettingType): any {+ private getPublishPublicParams(platformSetting: DouyinPlatformSettingType): any {console.log('开始处理发布参数...');// 处理描述let text = `${platformSetting['title'] || ''} ${platformSetting['caption'] || ''}`;@@ -2376,7 +2376,6 @@ export class DouyinService {return res;}- //// 回复其他人的评论async creatorCommentReplyOther(cookie: Electron.Cookie[], data: any) {const thisUri = `https://www.douyin.com/aweme/v1/web/comment/publish/?${jsonToQueryString(diff --git a/electron/plat/xiaohongshu/index.ts b/electron/plat/xiaohongshu/index.tsindex 2eb8b874..0c2cdb47 100644--- a/electron/plat/xiaohongshu/index.ts+++ b/electron/plat/xiaohongshu/index.ts@@ -14,6 +14,35 @@ import {XiaohongshuApiResponse,} from './xiaohongshu.type';+export type XSLPlatformSettingType = {+ // 标题+ title?: string;+ // 描述+ desc?: string;+ // 定时发布+ timingTime?: number;+ // @用户+ mentionedUserInfo?: {+ nickName: string;+ uid: string;+ }[];+ // 话题+ topicsDetail?: {+ topicId: string;+ topicName: string;+ }[];+ // 位置+ poiInfo?: {+ poiType: number;+ poiId: string;+ poiName: string;+ poiAddress: string;+ };+ cover: string;+ // true=私有 flase=公开+ privacy: boolean;+};+export class XiaohongshuService {private defaultUserAgent ='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36';@@ -783,8 +812,12 @@ export class XiaohongshuService {async publishImageWorkApi(cookies: string,imagePath: string[],- platformSetting: any,- ) {+ platformSetting: XSLPlatformSettingType,+ ): Promise<{+ publishTime: number;+ publishId: string;+ shareLink: string;+ }> {return new Promise(async (resolve, reject) => {// try {// 初始化cookie@@ -1157,34 +1190,7 @@ export class XiaohongshuService {async publishVideoWorkApi(cookies: string,filePath: string,- platformSetting: {- // 标题- title?: string;- // 描述- desc?: string;- // 定时发布- timingTime?: number;- // @用户- mentionedUserInfo?: {- nickName: string;- uid: string;- }[];- // 话题- topicsDetail?: {- topicId: string;- topicName: string;- }[];- // 位置- poiInfo?: {- poiType: number;- poiId: string;- poiName: string;- poiAddress: string;- };- cover: string;- // true=私有 flase=公开- privacy: boolean;- },+ platformSetting: XSLPlatformSettingType,callback: (progress: number, msg?: string) => void,): Promise<{publishTime: number;