| 1 | /* |
| 2 | * @Author: nevin |
| 3 | * @Date: 2025-02-07 20:00:47 |
| 4 | * @LastEditTime: 2025-03-19 14:27:53 |
| 5 | * @LastEditors: nevin |
| 6 | * @Description: |
| 7 | */ |
| 8 | import { VideoModel } from '../../../db/models/video'; |
| 9 | import { AccountModel } from '../../../db/models/account'; |
| 10 | import { PubItemBase } from './PubItemBase'; |
| 11 | import { PlatformBase } from '../PlatformBase'; |
| 12 | import { EtEvent } from '../../../global/event'; |
| 13 | import windowOperate from '../../../util/windowOperate'; |
| 14 | import { SendChannelEnum } from '../../../../commont/UtilsEnum'; |
| 15 | import { PubStatus } from '../../../../commont/publish/PublishEnum'; |
| 16 | |
| 17 | // 视频发布进度返回值 |
| 18 | export interface PublishProgressRes { |
| 19 | // 为 -1 表示失败 |
| 20 | progress: number; |
| 21 | msg: string; |
| 22 | account: AccountModel; |
| 23 | id: number; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * 视频发布单条处理逻辑 |
| 28 | */ |
| 29 | export class PubItemVideo extends PubItemBase { |
| 30 | videoModel: VideoModel; |
| 31 | |
| 32 | constructor( |
| 33 | accountModel: AccountModel, |
| 34 | videoModel: VideoModel, |
| 35 | platform: PlatformBase, |
| 36 | ) { |
| 37 | super(accountModel, platform); |
| 38 | this.videoModel = videoModel; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * 发布视频 |
| 43 | */ |
| 44 | async publishVideo() { |
| 45 | const publishVideoResult = await this.platform.videoPublish( |
| 46 | { |
| 47 | ...this.videoModel, |
| 48 | cookies: JSON.parse(this.accountModel.loginCookie), |
| 49 | token: this.accountModel.token, |
| 50 | }, |
| 51 | (progress: number, msg?: string) => { |
| 52 | const args: PublishProgressRes = { |
| 53 | progress, |
| 54 | msg: msg || '', |
| 55 | account: this.accountModel, |
| 56 | id: this.videoModel.pubRecordId!, |
| 57 | }; |
| 58 | // 视频发布进度,向渲染层发送进度 |
| 59 | windowOperate.sendRenderMsg(SendChannelEnum.VideoPublishProgress, args); |
| 60 | }, |
| 61 | ); |
| 62 | // 发布失败 |
| 63 | if (publishVideoResult.code === 0) { |
| 64 | this.videoModel.status = PubStatus.FAIL; |
| 65 | this.videoModel.failMsg = publishVideoResult.msg.toString(); |
| 66 | windowOperate.sendRenderMsg(SendChannelEnum.VideoPublishProgress, { |
| 67 | progress: -1, |
| 68 | msg: '发布失败!', |
| 69 | account: this.accountModel, |
| 70 | id: this.videoModel.pubRecordId, |
| 71 | }); |
| 72 | } else { |
| 73 | // 发布成功 |
| 74 | if (typeof publishVideoResult.pubStatus === 'number') { |
| 75 | this.videoModel.status = publishVideoResult.pubStatus; |
| 76 | } else { |
| 77 | this.videoModel.status = PubStatus.RELEASED; |
| 78 | } |
| 79 | this.videoModel.dataId = publishVideoResult.dataId; |
| 80 | this.videoModel.previewVideoLink = publishVideoResult.previewVideoLink; |
| 81 | windowOperate.sendRenderMsg(SendChannelEnum.VideoPublishProgress, { |
| 82 | id: this.videoModel.pubRecordId, |
| 83 | progress: 100, |
| 84 | msg: '发布成功!', |
| 85 | account: this.accountModel, |
| 86 | }); |
| 87 | } |
| 88 | await this.uploadRecord(); |
| 89 | return publishVideoResult; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * 更新视频记录 |
| 94 | */ |
| 95 | async uploadRecord() { |
| 96 | this.videoModel.proxyIp = undefined; |
| 97 | EtEvent.emit('ET_PUBLISH_UPDATE_VIDEO_PUL', this.videoModel); |
| 98 | } |
| 99 | } |
| 100 |