| 1 | /* |
| 2 | * @Author: nevin |
| 3 | * @Date: 2025-02-07 20:00:47 |
| 4 | * @LastEditTime: 2025-04-24 14:30:42 |
| 5 | * @LastEditors: nevin |
| 6 | * @Description: |
| 7 | */ |
| 8 | import { AccountModel } from '../../../db/models/account'; |
| 9 | import { PubItemBase } from './PubItemBase'; |
| 10 | import { PlatformBase } from '../PlatformBase'; |
| 11 | import { ImgTextModel } from '../../../db/models/imgText'; |
| 12 | import { EtEvent } from '../../../global/event'; |
| 13 | import { PublishProgressRes } from './PubItemVideo'; |
| 14 | import windowOperate from '../../../util/windowOperate'; |
| 15 | import { SendChannelEnum } from '../../../../commont/UtilsEnum'; |
| 16 | import { PubStatus } from '../../../../commont/publish/PublishEnum'; |
| 17 | |
| 18 | /** |
| 19 | * 视频发布单条处理逻辑 |
| 20 | */ |
| 21 | export class PubItemImgText extends PubItemBase { |
| 22 | imgTextModel: ImgTextModel; |
| 23 | |
| 24 | constructor( |
| 25 | accountModel: AccountModel, |
| 26 | imgTextModel: ImgTextModel, |
| 27 | platform: PlatformBase, |
| 28 | ) { |
| 29 | super(accountModel, platform); |
| 30 | this.imgTextModel = imgTextModel; |
| 31 | } |
| 32 | |
| 33 | async publishImgText() { |
| 34 | const params: ImgTextModel = { |
| 35 | ...this.imgTextModel, |
| 36 | cookies: JSON.parse(this.accountModel.loginCookie), |
| 37 | token: this.accountModel.token, |
| 38 | }; |
| 39 | console.log('图文发布原始参数:', params); |
| 40 | const publishVideoResult = await this.platform.imgTextPublish(params); |
| 41 | // 发布失败 |
| 42 | if (publishVideoResult.code === 0) { |
| 43 | this.imgTextModel.status = PubStatus.FAIL; |
| 44 | this.imgTextModel.failMsg = publishVideoResult.msg.toString(); |
| 45 | } else { |
| 46 | // 发布成功 |
| 47 | this.imgTextModel.status = PubStatus.RELEASED; |
| 48 | this.imgTextModel.dataId = publishVideoResult.dataId; |
| 49 | this.imgTextModel.previewVideoLink = publishVideoResult.previewVideoLink; |
| 50 | } |
| 51 | // 发布进度 |
| 52 | const progressRes: PublishProgressRes = { |
| 53 | id: 1, |
| 54 | progress: publishVideoResult.code === 0 ? -1 : 100, |
| 55 | msg: '', |
| 56 | account: this.accountModel, |
| 57 | }; |
| 58 | // 图文发布进度,向渲染层发送进度 |
| 59 | windowOperate.sendRenderMsg( |
| 60 | SendChannelEnum.ImgTextPublishProgress, |
| 61 | progressRes, |
| 62 | ); |
| 63 | await this.uploadRecord(); |
| 64 | return publishVideoResult; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * 更新图文记录 |
| 69 | */ |
| 70 | async uploadRecord() { |
| 71 | this.imgTextModel.proxyIp = undefined; |
| 72 | EtEvent.emit('ET_PUBLISH_UPDATE_IMG_TEXT_PUL', this.imgTextModel); |
| 73 | } |
| 74 | } |
| 75 |