Let's use AI to Earn!
TypeScript auto-publishdouyindouyin-apielectron-appelectron-reactkuaishoukwaipublishedshipinhaotoolxiaohongshu
feat: 添加图文发布记录数据库的逻辑,添加图文发布入口
gaoSir2860e87008ca
diff --git a/electron/db/models/imgText.ts b/electron/db/models/imgText.tsnew file mode 100644index 00000000..b6a04829--- /dev/null+++ b/electron/db/models/imgText.ts@@ -0,0 +1,15 @@+/*+ * @Author: nevin+ * @Date: 2025-01-20 16:24:16+ * @LastEditTime: 2025-02-12 18:32:28+ * @LastEditors: nevin+ * @Description: 视频发布记录+ */+import { Column, Entity } from 'typeorm';+import { WorkData } from './workData';++@Entity({ name: 'imgText' })+export class ImgTextModel extends WorkData {+ @Column({ type: 'json', nullable: true, comment: '多个图片的路径' })+ imagesPath?: string[];+}diff --git a/electron/db/models/video.ts b/electron/db/models/video.tsindex bb2531c8..f768a2a4 100644--- a/electron/db/models/video.ts+++ b/electron/db/models/video.ts@@ -5,112 +5,12 @@* @LastEditors: nevin* @Description: 视频发布记录*/-import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';+import { Entity, Column } from 'typeorm';import { WorkData } from './workData';-import { VisibleTypeEnum } from '../../../commont/publish/PublishEnum';-import { AccountType } from '../../../commont/AccountEnum';-import type { ILocationDataItem, WxSphEvent } from '../../main/plat/plat.type';-import { DeclarationDouyin } from '../../plat/douyin/common.douyin';--// 包含一个name和一个value的对象-export interface ILableValue {- label: string;- value: string | number;-}--/**- * 不同平台的差异化参数- * 每个平台有相同点,有不同点,这不同点都在这个参数下集合- */-export type DiffParmasType = {- [AccountType.Xhs]?: {};- [AccountType.Douyin]?: {- // 申请关联的热点- hotPoint?: ILableValue;- // 申请关联的活动- activitys?: ILableValue[];- // 自主声明- selfDeclare?: DeclarationDouyin;- };- [AccountType.WxSph]?: {- // 是否为原创- isOriginal?: boolean;- // 扩展链接- extLink?: string;- // 活动- activity?: WxSphEvent;- };- [AccountType.KWAI]?: {};-};@Entity({ name: 'video' })export class VideoModel extends WorkData {- @PrimaryGeneratedColumn({ type: 'int', comment: 'id' })- id?: number;-- @Column({ type: 'varchar', nullable: false, comment: '用户id' })- userId!: string;-- @Column({- type: 'int',- nullable: false,- comment: '发布记录id,对应PubRecord表id',- })- pubRecordId!: number;-- @Column({ type: 'int', nullable: false, comment: '账号id,对应account表id' })- accountId!: number;-- // 标题- @Column({ type: 'varchar', nullable: true, comment: '标题' })- title?: string;-- // 简介- @Column({ type: 'varchar', nullable: true, comment: '简介' })- desc?: string;-// 视频路径@Column({ type: 'varchar', nullable: true, comment: '视频路径' })videoPath?: string;-- // 封面路径- @Column({ type: 'varchar', nullable: true, comment: '封面路径' })- coverPath?: string;-- // 最后统计时间- @Column({ type: 'datetime', nullable: true, comment: '最后统计时间' })- lastStatsTime?: Date;-- // 话题- @Column({ type: 'json', nullable: true, comment: '话题' })- topics?: string[];-- // 位置- @Column({ type: 'json', nullable: true, comment: '位置' })- location?: ILocationDataItem;-- // 差异化参数- @Column({ type: 'json', nullable: true, comment: '不同平台的差异化参数' })- diffParams?: DiffParmasType;-- // 定时发布日期- @Column({ type: 'datetime', nullable: true, comment: '定时发布日期' })- timingTime?: Date;-- // @用户- @Column({ type: 'json', nullable: true, comment: '@用户数组' })- mentionedUserInfo?: ILableValue[];-- // 预览地址- @Column({ type: 'varchar', nullable: true, comment: '预览地址' })- previewVideoLink?: string;-- // 视频可见性- @Column({- type: 'tinyint',- nullable: false,- comment: '视频可见性',- default: VisibleTypeEnum.Private,- })- visibleType?: VisibleTypeEnum;}diff --git a/electron/db/models/workData.ts b/electron/db/models/workData.tsindex 6d4cd36c..46f4631b 100644--- a/electron/db/models/workData.ts+++ b/electron/db/models/workData.ts@@ -5,16 +5,115 @@* @LastEditors: nevin* @Description: 视频发布记录 不是数据表实体*/-import { Column } from 'typeorm';+import { Column, PrimaryGeneratedColumn } from 'typeorm';import { TempModel } from './temp';import { PubStatus } from './pubRecord';import { AccountType } from '../../../commont/AccountEnum';+import type { ILocationDataItem, WxSphEvent } from '../../main/plat/plat.type';+import { DeclarationDouyin } from '../../plat/douyin/common.douyin';+import { VisibleTypeEnum } from '../../../commont/publish/PublishEnum';++// 包含一个name和一个value的对象+export interface ILableValue {+ label: string;+ value: string | number;+}++/**+ * 不同平台的差异化参数+ * 每个平台有相同点,有不同点,这不同点都在这个参数下集合+ */+export type DiffParmasType = {+ [AccountType.Xhs]?: {};+ [AccountType.Douyin]?: {+ // 申请关联的热点+ hotPoint?: ILableValue;+ // 申请关联的活动+ activitys?: ILableValue[];+ // 自主声明+ selfDeclare?: DeclarationDouyin;+ };+ [AccountType.WxSph]?: {+ // 是否为原创+ isOriginal?: boolean;+ // 扩展链接+ extLink?: string;+ // 活动+ activity?: WxSphEvent;+ };+ [AccountType.KWAI]?: {};+};export class WorkData extends TempModel {// 数据唯一ID@Column({ type: 'varchar', nullable: true, comment: '数据唯一ID' })dataId?: string;+ @PrimaryGeneratedColumn({ type: 'int', comment: 'id' })+ id?: number;++ @Column({ type: 'varchar', nullable: false, comment: '用户id' })+ userId!: string;++ // 标题+ @Column({ type: 'varchar', nullable: true, comment: '标题' })+ title?: string;++ // 简介+ @Column({ type: 'varchar', nullable: true, comment: '简介' })+ desc?: string;++ // 封面路径+ @Column({ type: 'varchar', nullable: true, comment: '封面路径' })+ coverPath?: string;++ // 最后统计时间+ @Column({ type: 'datetime', nullable: true, comment: '最后统计时间' })+ lastStatsTime?: Date;++ // 话题+ @Column({ type: 'json', nullable: true, comment: '话题' })+ topics?: string[];++ // 位置+ @Column({ type: 'json', nullable: true, comment: '位置' })+ location?: ILocationDataItem;++ // 差异化参数+ @Column({ type: 'json', nullable: true, comment: '不同平台的差异化参数' })+ diffParams?: DiffParmasType;++ // 可见性+ @Column({+ type: 'tinyint',+ nullable: false,+ comment: '可见性',+ default: VisibleTypeEnum.Private,+ })+ visibleType?: VisibleTypeEnum;++ // 定时发布日期+ @Column({ type: 'datetime', nullable: true, comment: '定时发布日期' })+ timingTime?: Date;++ // @用户+ @Column({ type: 'json', nullable: true, comment: '@用户数组' })+ mentionedUserInfo?: ILableValue[];++ // 预览地址+ @Column({ type: 'varchar', nullable: true, comment: '预览地址' })+ previewVideoLink?: string;++ @Column({+ type: 'int',+ nullable: false,+ comment: '发布记录id,对应PubRecord表id',+ })+ pubRecordId!: number;++ @Column({ type: 'int', nullable: false, comment: '账号id,对应account表id' })+ accountId!: number;+@Column({type: 'varchar',enum: AccountType,diff --git a/electron/main/plat/index.ts b/electron/main/plat/index.tsindex b9d1460b..be003f7d 100644--- a/electron/main/plat/index.ts+++ b/electron/main/plat/index.ts@@ -20,6 +20,8 @@ import { PublishVideoResult } from './module';import { VideoModel } from '../../db/models/video';import { PubItemVideo } from './pub/PubItemVideo';import { AccountType } from '../../../commont/AccountEnum';+import { PubItemImgText } from './pub/PubItemImgText';+import { ImgTextModel } from '../../db/models/imgText';class PlatController {// 所有平台@@ -92,6 +94,31 @@ class PlatController {return await Promise.all(tasks);}+ /**+ * 发布图文,支持发布到多个平台+ * @param imgTextModels 图文记录数据+ * @param accountModels 该用户的账号记录数据+ */+ public async imgTextPublish(+ imgTextModels: ImgTextModel[],+ accountModels: AccountModel[],+ ) {+ // 总发布记录状态更新+ const tasks: Promise<PublishVideoResult>[] = [];+ for (const videoModel of imgTextModels) {+ const platform = this.getPlatform(videoModel.type);+ if (platform) {+ const pubItemVideo = new PubItemImgText(+ accountModels.find((v) => v.id === videoModel.accountId)!,+ videoModel,+ platform,+ );+ tasks.push(pubItemVideo.publishImgText());+ }+ }+ return await Promise.all(tasks);+ }+/*** 获取某个平台的话题数据* @param account@@ -152,7 +179,7 @@ class PlatController {/*** 获取作品列表* @param account- * @param pageInfo+ * @param pcursor*/public async getWorkList(account: AccountModel, pcursor?: string) {const platform = this.platforms.get(account.type)!;@@ -162,7 +189,8 @@ class PlatController {/*** 获取评论列表* @param account- * @param pageInfo+ * @param dataId+ * @param pcursor*/public async getCommentList(account: AccountModel,@@ -176,7 +204,8 @@ class PlatController {/*** 获取评论列表* @param account- * @param pageInfo+ * @param dataId+ * @param pcursor*/public async getCreatorCommentListByOther(account: AccountModel,@@ -194,7 +223,8 @@ class PlatController {/*** 创建评论* @param account- * @param pageInfo+ * @param dataId+ * @param content*/public async createComment(account: AccountModel,@@ -208,7 +238,8 @@ class PlatController {/*** 创建评论* @param account- * @param pageInfo+ * @param dataId+ * @param content*/public async createCommentByOther(account: AccountModel,@@ -222,7 +253,9 @@ class PlatController {/*** 回复评论* @param account- * @param pageInfo+ * @param commentId+ * @param content+ * @param option*/public async replyCommentByOther(account: AccountModel,@@ -245,7 +278,9 @@ class PlatController {/*** 回复评论* @param account- * @param pageInfo+ * @param commentId+ * @param content+ * @param option*/public async replyComment(account: AccountModel,diff --git a/electron/main/plat/pub/PubItemBase.ts b/electron/main/plat/pub/PubItemBase.tsindex 81aad35c..5d563222 100644--- a/electron/main/plat/pub/PubItemBase.ts+++ b/electron/main/plat/pub/PubItemBase.ts@@ -1,10 +1,31 @@import { AccountModel } from '../../../db/models/account';import { PlatformBase } from '../PlatformBase';+import { WorkData } from '../../../db/models/workData';+import { VisibleTypeEnum } from '../../../../commont/publish/PublishEnum';export abstract class PubItemBase {accountModel: AccountModel;platform: PlatformBase;+ /**+ * 通用发布参数解析+ * @param workData+ */+ commonParamsParse(workData: WorkData) {+ return {+ ...workData,+ cookies: JSON.parse(this.accountModel.loginCookie),+ desc: workData.desc!,+ title: workData.title || '',+ topics: workData.topics || [],+ coverPath: workData.coverPath || '',+ visibleType: workData.visibleType || VisibleTypeEnum.Private,+ diffParams: workData.diffParams || {},+ timingTime: workData.timingTime,+ location: workData.location,+ };+ }+protected constructor(accountModel: AccountModel, platform: PlatformBase) {this.accountModel = accountModel;this.platform = platform;diff --git a/electron/main/plat/pub/PubItemImgText.ts b/electron/main/plat/pub/PubItemImgText.tsnew file mode 100644index 00000000..d7a7b761--- /dev/null+++ b/electron/main/plat/pub/PubItemImgText.ts@@ -0,0 +1,60 @@+/*+ * @Author: nevin+ * @Date: 2025-02-07 20:00:47+ * @LastEditTime: 2025-03-19 14:27:53+ * @LastEditors: nevin+ * @Description:+ */+import { AccountModel } from '../../../db/models/account';+import { PubItemBase } from './PubItemBase';+import { PlatformBase } from '../PlatformBase';+import { ImgTextModel } from '../../../db/models/imgText';+import { PubStatus } from '../../../db/models/pubRecord';+import { EtEvent } from '../../../global/event';++/**+ * 视频发布单条处理逻辑+ */+export class PubItemImgText extends PubItemBase {+ imgTextModel: ImgTextModel;++ constructor(+ accountModel: AccountModel,+ imgTextModel: ImgTextModel,+ platform: PlatformBase,+ ) {+ super(accountModel, platform);+ this.imgTextModel = imgTextModel;+ }++ async publishImgText() {+ const publishVideoResult = await this.platform.imgTextPublish(+ {+ ...this.commonParamsParse(this.imgTextModel),+ imagesPath: this.imgTextModel.imagesPath!,+ },+ (progress: number, msg?: string) => {+ console.log(progress, msg);+ },+ );+ // 发布失败+ if (publishVideoResult.code === 0) {+ this.imgTextModel.status = PubStatus.FAIL;+ this.imgTextModel.failMsg = publishVideoResult.msg;+ } else {+ // 发布成功+ this.imgTextModel.status = PubStatus.RELEASED;+ this.imgTextModel.dataId = publishVideoResult.dataId;+ this.imgTextModel.previewVideoLink = publishVideoResult.previewVideoLink;+ }+ await this.uploadRecord();+ return publishVideoResult;+ }++ /**+ * 更新图文记录+ */+ async uploadRecord() {+ EtEvent.emit('ET_PUBLISH_UPDATE_IMG_TEXT_PUL', this.imgTextModel);+ }+}diff --git a/electron/main/plat/pub/PubItemVideo.ts b/electron/main/plat/pub/PubItemVideo.tsindex a78860f6..eec8e41a 100644--- a/electron/main/plat/pub/PubItemVideo.ts+++ b/electron/main/plat/pub/PubItemVideo.ts@@ -11,7 +11,6 @@ import { PubItemBase } from './PubItemBase';import { PlatformBase } from '../PlatformBase';import { PubStatus } from '../../../db/models/pubRecord';import { EtEvent } from '../../../global/event';-import { VisibleTypeEnum } from '../../../../commont/publish/PublishEnum';import windowOperate from '../../../util/windowOperate';import { SendChannelEnum } from '../../../../commont/UtilsEnum';@@ -44,17 +43,8 @@ export class PubItemVideo extends PubItemBase {async publishVideo() {const publishVideoResult = await this.platform.videoPublish({- ...this.videoModel,- cookies: JSON.parse(this.accountModel.loginCookie),- desc: this.videoModel.desc!,videoPath: this.videoModel.videoPath!,- title: this.videoModel.title || '',- topics: this.videoModel.topics || [],- coverPath: this.videoModel.coverPath || '',- visibleType: this.videoModel.visibleType || VisibleTypeEnum.Private,- diffParams: this.videoModel.diffParams || {},- timingTime: this.videoModel.timingTime,- location: this.videoModel.location,+ ...this.commonParamsParse(this.videoModel),},(progress: number, msg?: string) => {const args: VideoPublishProgressRes = {diff --git a/electron/main/publish/imgText/controller.ts b/electron/main/publish/imgText/controller.tsnew file mode 100644index 00000000..bca7840f--- /dev/null+++ b/electron/main/publish/imgText/controller.ts@@ -0,0 +1,24 @@+import { Controller, Et, Inject } from '../../core/decorators';+import { VideoPubService } from '../video/service';+import { PublishService } from '../service';+import { AccountService } from '../../account/service';+import { ImgTextPubService } from './service';+import { ImgTextModel } from '../../../db/models/imgText';++@Controller()+export class ImgTextPubController {+ @Inject(VideoPubService)+ private readonly imgTextRepository!: ImgTextPubService;++ @Inject(PublishService)+ private readonly publishService!: PublishService;++ @Inject(AccountService)+ private readonly accountService!: AccountService;++ // 更新视频发布数据+ @Et('ET_PUBLISH_UPDATE_IMG_TEXT_PUL')+ async updateImgTextPul(imgTextModel: ImgTextModel): Promise<any> {+ await this.imgTextRepository.updateImgTextPul(imgTextModel);+ }+}diff --git a/electron/main/publish/imgText/service.ts b/electron/main/publish/imgText/service.tsnew file mode 100644index 00000000..c3f89639--- /dev/null+++ b/electron/main/publish/imgText/service.ts@@ -0,0 +1,18 @@+import { Repository } from 'typeorm';+import { ImgTextModel } from '../../../db/models/imgText';+import { AppDataSource } from '../../../db';+import { VideoModel } from '../../../db/models/video';+import { Injectable } from '../../core/decorators';++@Injectable()+export class ImgTextPubService {+ private imgTextRepository: Repository<ImgTextModel>;++ constructor() {+ this.imgTextRepository = AppDataSource.getRepository(VideoModel);+ }++ async updateImgTextPul(imgTextModel: ImgTextModel) {+ return await this.imgTextRepository.update(imgTextModel.id!, imgTextModel);+ }+}diff --git a/electron/main/publish/video/comment.ts b/electron/main/publish/video/comment.tsindex b947a054..e69de29b 100644--- a/electron/main/publish/video/comment.ts+++ b/electron/main/publish/video/comment.ts@@ -1,11 +0,0 @@-import { PubStatus } from '../../../db/models/pubRecord';--export interface PubVideoData {- title: string;- desc: string;- videoPath: string;- coverPath: string;- otherInfo: Record<string, any>;- publishTime?: Date;- status?: PubStatus;-}