| 1 | /* |
| 2 | * @Author: nevin |
| 3 | * @Date: 2025-01-20 22:02:54 |
| 4 | * @LastEditTime: 2025-02-22 20:39:02 |
| 5 | * @LastEditors: nevin |
| 6 | * @Description: |
| 7 | */ |
| 8 | import { Controller, Icp, Inject } from '../core/decorators'; |
| 9 | import { PublishService } from './service'; |
| 10 | import { getUserInfo } from '../user/comment'; |
| 11 | import { Between, FindOptionsWhere } from 'typeorm'; |
| 12 | import { |
| 13 | backPageData, |
| 14 | type CorrectQuery, |
| 15 | type pubRecordListQuery, |
| 16 | } from '../../global/table'; |
| 17 | import { PubRecordModel } from '../../db/models/pubRecord'; |
| 18 | import { PubStatus, PubType } from '../../../commont/publish/PublishEnum'; |
| 19 | import { VideoPubService } from './video/service'; |
| 20 | import { VideoModel } from '../../db/models/video'; |
| 21 | import platController from '../plat'; |
| 22 | import { AccountModel } from '../../db/models/account'; |
| 23 | import type { |
| 24 | IGetLocationDataParams, |
| 25 | IGetUsersParams, |
| 26 | } from '../plat/plat.type'; |
| 27 | import { douyinService } from '../../plat/douyin'; |
| 28 | import { shipinhaoService } from '../../plat/shipinhao'; |
| 29 | |
| 30 | @Controller() |
| 31 | export class PublishController { |
| 32 | @Inject(PublishService) |
| 33 | private readonly publishService!: PublishService; |
| 34 | |
| 35 | @Inject(VideoPubService) |
| 36 | private readonly videoPubService!: VideoPubService; |
| 37 | |
| 38 | // 创建发布记录 |
| 39 | @Icp('ICP_PUBLISH_CREATE_PUB_RECORD') |
| 40 | async createPubRecord( |
| 41 | event: Electron.IpcMainInvokeEvent, |
| 42 | pubRecord: PubRecordModel, |
| 43 | ): Promise<any> { |
| 44 | pubRecord.userId = getUserInfo().id; |
| 45 | pubRecord.publishTime = new Date(); |
| 46 | return await this.publishService.createPubRecord(pubRecord); |
| 47 | } |
| 48 | |
| 49 | // 获取发布记录列表 |
| 50 | @Icp('ICP_PUBLISH_GET_PUB_RECORD_LIST') |
| 51 | async getPubRecordList( |
| 52 | event: Electron.IpcMainInvokeEvent, |
| 53 | page: CorrectQuery, |
| 54 | query?: pubRecordListQuery, |
| 55 | ): Promise<any> { |
| 56 | const userInfo = getUserInfo(); |
| 57 | const filters: FindOptionsWhere<PubRecordModel> = !query |
| 58 | ? {} |
| 59 | : { |
| 60 | ...(query.type !== undefined && { type: query.type }), |
| 61 | ...(query.status === undefined |
| 62 | ? {} |
| 63 | : { |
| 64 | status: query.status, |
| 65 | }), |
| 66 | ...(query.time !== undefined && |
| 67 | query.time.length === 2 && |
| 68 | Between(new Date(query.time[0]), new Date(query.time[1]))), |
| 69 | }; |
| 70 | return await this.publishService.getPubRecordList( |
| 71 | userInfo.id, |
| 72 | page, |
| 73 | filters, |
| 74 | ); |
| 75 | } |
| 76 | |
| 77 | // 获取草稿列表 |
| 78 | @Icp('ICP_PUBLISH_GET_PUB_RECORD_DRAFTS_LIST') |
| 79 | async getPubRecordDraftsList( |
| 80 | event: Electron.IpcMainInvokeEvent, |
| 81 | page: CorrectQuery, |
| 82 | query?: { |
| 83 | time?: [string, string]; |
| 84 | type?: PubType; |
| 85 | }, |
| 86 | ): Promise<any> { |
| 87 | const userInfo = getUserInfo(); |
| 88 | const filters: FindOptionsWhere<PubRecordModel> = !query |
| 89 | ? { |
| 90 | status: PubStatus.UNPUBLISH, |
| 91 | } |
| 92 | : { |
| 93 | status: PubStatus.UNPUBLISH, |
| 94 | ...(query.type !== undefined && { type: query.type }), |
| 95 | ...(query.time !== undefined && |
| 96 | query.time.length === 2 && |
| 97 | Between(new Date(query.time[0]), new Date(query.time[1]))), |
| 98 | }; |
| 99 | return await this.publishService.getPubRecordList( |
| 100 | userInfo.id, |
| 101 | page, |
| 102 | filters, |
| 103 | ); |
| 104 | } |
| 105 | |
| 106 | // 获取发布记录的发布内容列表 |
| 107 | @Icp('ICP_PUBLISH_GET_PUB_RECORD_ITEM_LIST') |
| 108 | async getPubRecordItemList( |
| 109 | event: Electron.IpcMainInvokeEvent, |
| 110 | page: CorrectQuery, |
| 111 | id: number, |
| 112 | ): Promise<any> { |
| 113 | let res = backPageData<VideoModel | never>([], 0, page); |
| 114 | const pubRecordInfo = await this.publishService.getPubRecordInfo(id); |
| 115 | if (!pubRecordInfo) return res; |
| 116 | |
| 117 | if (pubRecordInfo.type === PubType.VIDEO) { |
| 118 | res = await this.videoPubService.getVideoPulListByPubRecordIdToShow( |
| 119 | id, |
| 120 | page, |
| 121 | ); |
| 122 | } else if (pubRecordInfo.type === PubType.ARTICLE) { |
| 123 | // TODO: 图文 |
| 124 | return res; |
| 125 | } |
| 126 | |
| 127 | return res; |
| 128 | } |
| 129 | |
| 130 | // 获取发布记录信息 |
| 131 | @Icp('ICP_PUBLISH_GET_PUB_RECORD_INFO') |
| 132 | async getPubRecordInfo( |
| 133 | event: Electron.IpcMainInvokeEvent, |
| 134 | id: number, |
| 135 | ): Promise<any> { |
| 136 | return await this.publishService.getPubRecordInfo(id); |
| 137 | } |
| 138 | |
| 139 | // 删除发布记录 |
| 140 | @Icp('ICP_PUBLISH_DEL_PUB_RECORD_BY_ID') |
| 141 | async delPubRecord(event: Electron.IpcMainInvokeEvent, id: number) { |
| 142 | return await this.publishService.deletePubRecordById(id); |
| 143 | } |
| 144 | |
| 145 | // 获取所有平台话题 |
| 146 | @Icp('ICP_PUBLISH_GET_TOPIC') |
| 147 | async getTopic( |
| 148 | event: Electron.IpcMainInvokeEvent, |
| 149 | account: AccountModel, |
| 150 | keyword: string, |
| 151 | ) { |
| 152 | return await platController.getTopic(account, keyword); |
| 153 | } |
| 154 | |
| 155 | // 获取所有平台位置数据 |
| 156 | @Icp('ICP_PUBLISH_GET_LOCATION') |
| 157 | async getLocationData( |
| 158 | event: Electron.IpcMainInvokeEvent, |
| 159 | params: IGetLocationDataParams, |
| 160 | ) { |
| 161 | return await platController.getLocationData(params); |
| 162 | } |
| 163 | |
| 164 | // 获取所有平台合集数据 |
| 165 | @Icp('ICP_PUBLISH_GET_MIX_LIST') |
| 166 | async getMixList(event: Electron.IpcMainInvokeEvent, account: AccountModel) { |
| 167 | return await platController.getMixList(account); |
| 168 | } |
| 169 | |
| 170 | // 获取所有平台的用户数据 |
| 171 | @Icp('ICP_PUBLISH_GET_USERS') |
| 172 | async getUsers(event: Electron.IpcMainInvokeEvent, params: IGetUsersParams) { |
| 173 | return await platController.getUsers(params); |
| 174 | } |
| 175 | |
| 176 | // 获取抖音热点数据 |
| 177 | @Icp('ICP_PUBLISH_GET_DOYTIN_HOT') |
| 178 | async getDoytinHot( |
| 179 | event: Electron.IpcMainInvokeEvent, |
| 180 | account: AccountModel, |
| 181 | query: string, |
| 182 | ) { |
| 183 | const res = await douyinService.getHotspotData({ |
| 184 | query: query, |
| 185 | cookie: JSON.parse(account.loginCookie), |
| 186 | }); |
| 187 | return res.data; |
| 188 | } |
| 189 | |
| 190 | // 获取抖音所有热点数据 |
| 191 | @Icp('ICP_PUBLISH_GET_ALL_DOYTIN_HOT') |
| 192 | async getDoytinHotAll(event: Electron.IpcMainInvokeEvent) { |
| 193 | const res = await douyinService.getAllHotspotData(); |
| 194 | return res.data; |
| 195 | } |
| 196 | |
| 197 | // 获取抖音的活动列表 |
| 198 | @Icp('ICP_PUBLISH_GET_DOUYIN_ACTIVITY') |
| 199 | async getDouyinActivity( |
| 200 | event: Electron.IpcMainInvokeEvent, |
| 201 | account: AccountModel, |
| 202 | ) { |
| 203 | const res = await douyinService.getActivity( |
| 204 | JSON.parse(account.loginCookie), |
| 205 | ); |
| 206 | return res.data; |
| 207 | } |
| 208 | |
| 209 | // 获取抖音的活动详情 |
| 210 | @Icp('ICP_PUBLISH_GET_DOUYIN_ACTIVITY_DETAILS') |
| 211 | async getDouyinActivityDetails( |
| 212 | event: Electron.IpcMainInvokeEvent, |
| 213 | account: AccountModel, |
| 214 | activity_id: string, |
| 215 | ) { |
| 216 | const res = await douyinService.getActivityDetails( |
| 217 | JSON.parse(account.loginCookie), |
| 218 | activity_id, |
| 219 | ); |
| 220 | return res.data; |
| 221 | } |
| 222 | |
| 223 | // 获取抖音活动标签 |
| 224 | @Icp('ICP_PUBLISH_GET_DOUYIN_ACTIVITY_TAGS') |
| 225 | async getActivityTags( |
| 226 | event: Electron.IpcMainInvokeEvent, |
| 227 | account: AccountModel, |
| 228 | ) { |
| 229 | return await douyinService.getActivityTags(JSON.parse(account.loginCookie)); |
| 230 | } |
| 231 | |
| 232 | // 获取微信视频号的活动 |
| 233 | @Icp('ICP_PUBLISH_GET_WXSPH_ACTIVITY') |
| 234 | async getSphActivity( |
| 235 | event: Electron.IpcMainInvokeEvent, |
| 236 | account: AccountModel, |
| 237 | query: string, |
| 238 | ) { |
| 239 | return await shipinhaoService.getActivityList({ |
| 240 | cookie: JSON.parse(account.loginCookie), |
| 241 | query, |
| 242 | }); |
| 243 | } |
| 244 | } |
| 245 |