UNPKG

polyv-live-cli

Version:

CLI tool for managing PolyV live streaming services.

341 lines 17.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RecordHandler = void 0; const base_handler_1 = require("./base.handler"); const record_service_sdk_1 = require("../services/record.service.sdk"); const api_command_1 = require("../utils/api-command"); const PLAYBACK_ENABLED_MAP = { 'Y': '开启', 'N': '关闭', }; const PLAYBACK_TYPE_MAP = { 'single': '单个回放', 'list': '列表回放', }; const PLAYBACK_ORIGIN_MAP = { 'record': '录制文件', 'playback': '回放列表', 'vod': '点播列表', 'material': '素材库', }; const PROGRESS_BAR_TYPE_MAP = { 'drag': '拖动', 'prohibitDrag': '禁止拖动', 'dragHistoryOnly': '只能拖动已观看内容', }; const Y_N_MAP = { 'Y': '是', 'N': '否', }; class RecordHandler extends base_handler_1.BaseHandler { constructor(authConfig, serviceConfig, recordService) { super(); this.recordService = recordService ?? new record_service_sdk_1.RecordServiceSdk(authConfig, serviceConfig); } async getPlaybackSetting(options) { return this.executeWithErrorHandling(async () => { if (!options.channelId || options.channelId.trim() === '') { throw new Error('channelId is required'); } const result = await this.recordService.getPlaybackSetting(options.channelId); this.displayPlaybackSetting(result, options.channelId, options.output); }, 'record.setting.get'); } async setPlaybackSetting(options) { return this.executeWithErrorHandling(async () => { if (!options.channelId || options.channelId.trim() === '') { throw new Error('channelId is required'); } await this.recordService.setPlaybackSetting(options.channelId, options); this.displaySetPlaybackSettingResult(options); }, 'record.setting.set'); } async recordConvert(options) { return this.executeWithErrorHandling(async () => { if (!options.channelId || options.channelId.trim() === '') { throw new Error('channelId is required'); } if (!options.async && (!options.fileName || options.fileName.trim() === '')) { throw new Error('fileName is required'); } await (0, api_command_1.confirmWrite)(options.force, `Convert record file for channel ${options.channelId}?`); let result; if (options.async) { result = await this.recordService.recordConvertAsync(options.channelId, options); } else { result = await this.recordService.recordConvert(options.channelId, options); } this.displayConvertResult(options, result); }, 'record.convert'); } async setRecordDefault(options) { return this.executeWithErrorHandling(async () => { if (!options.channelId || options.channelId.trim() === '') { throw new Error('channelId is required'); } if (!options.videoId || options.videoId.trim() === '') { throw new Error('videoId is required'); } await this.recordService.setRecordDefault(options.channelId, options.videoId, options.listType); this.displaySetDefaultResult(options); }, 'record.set-default'); } async getRecordFile(options) { return this.executeWithErrorHandling(async () => { const result = await this.recordService.getRecordFile(options.channelId, options.fileId); this.displayResult(result, options.output); }, 'record.temp-list'); } async listRecordFiles(options) { return this.executeWithErrorHandling(async () => { const result = await this.recordService.listRecordFiles(this.compactOptions(options)); this.displayResult(result, options.output); }, 'record.file.list'); } async listMaterialRecordFiles(options) { return this.executeWithErrorHandling(async () => { const result = await this.recordService.listMaterialRecordFiles(this.compactOptions(options)); this.displayResult(result, options.output); }, 'record.material-list'); } async clipRecordFile(options) { return this.executeWithErrorHandling(async () => { await (0, api_command_1.confirmWrite)(options.force, `Clip record file ${options.fileId} for channel ${options.channelId}?`); const result = await this.recordService.clipRecordFile(options.channelId, this.compactOptions({ fileId: options.fileId, startTime: options.startTime, endTime: options.endTime, fileName: options.fileName, callbackUrl: options.callbackUrl, })); this.displayResult(result, options.output); }, 'record.clip'); } async mergeRecordFiles(options) { return this.executeWithErrorHandling(async () => { await (0, api_command_1.confirmWrite)(options.force, `Merge record files for channel ${options.channelId}?`); const result = await this.recordService.mergeRecordFiles(this.compactOptions({ channelId: options.channelId, urls: options.urls, fileIds: options.fileIds, fileName: options.fileName, })); this.displayResult(result, options.output); }, 'record.file.merge'); } async recordMergeMp4(options) { return this.executeWithErrorHandling(async () => { await (0, api_command_1.confirmWrite)(options.force, `Merge MP4 recordings for channel ${options.channelId} between ${options.startTime} and ${options.endTime}?`); const result = await this.recordService.recordMergeMp4(options.channelId, this.compactOptions({ startTime: options.startTime, endTime: options.endTime, fileName: options.fileName, callbackUrl: options.callbackUrl, })); this.displayResult(result, options.output); }, 'record.merge-mp4'); } async recordMergeMp4Start(options) { return this.executeWithErrorHandling(async () => { await (0, api_command_1.confirmWrite)(options.force, `Start MP4 merge for channel ${options.channelId} between ${options.startTime} and ${options.endTime}?`); const result = await this.recordService.recordMergeMp4Start(options.channelId, this.compactOptions({ startTime: options.startTime, endTime: options.endTime, fileName: options.fileName, callbackUrl: options.callbackUrl, })); this.displayResult({ channelId: options.channelId, startTime: options.startTime, endTime: options.endTime, submitted: result }, options.output); }, 'record.merge-mp4-start'); } async deleteRecordFile(options) { return this.executeWithErrorHandling(async () => { await (0, api_command_1.confirmWrite)(options.force, `Delete record file(s) from channel ${options.channelId}?`); await this.recordService.deleteRecordFile(this.compactOptions({ channelId: options.channelId, sessionId: options.sessionId, startTime: options.startTime, })); this.displayResult({ channelId: options.channelId, sessionId: options.sessionId, startTime: options.startTime, deleted: true }, options.output); }, 'record.file.delete'); } async convertRecordFileToVod(options) { return this.executeWithErrorHandling(async () => { await (0, api_command_1.confirmWrite)(options.force, `Convert historical record file for channel ${options.channelId}?`); const result = await this.recordService.convertRecordFileToVod(this.compactOptions({ channelId: options.channelId, userId: options.userId, fileName: options.fileName, fileUrl: options.fileUrl, sessionId: options.sessionId, cataid: options.cataid, cataname: options.cataname, toPlayList: options.toPlayList, setAsDefault: options.setAsDefault, })); this.displayResult(result, options.output); }, 'record.file.convert'); } async recordAddBreakpoint(options) { return this.executeWithErrorHandling(async () => { const action = options.type === 'resume' ? 'Resume' : 'Pause'; await (0, api_command_1.confirmWrite)(options.force, `${action} recording (breakpoint) for channel ${options.channelId}?`); const result = await this.recordService.recordAddBreakpoint(options.channelId, this.compactOptions({ type: options.type, fromStartStop: options.fromStartStop, })); this.displayResult({ channelId: options.channelId, type: options.type, success: result }, options.output); }, 'record.breakpoint.add'); } async createRecordFileOutline(options) { return this.executeWithErrorHandling(async () => { await (0, api_command_1.confirmWrite)(options.force, `Create outline for record file ${options.fileId}?`); const result = await this.recordService.createRecordFileOutline(this.compactOptions({ fileId: options.fileId, aiKnowledgeQuizEnabled: options.aiKnowledgeQuizEnabled, aiSummaryAuditEnabled: options.aiSummaryAuditEnabled, syncToPlaybackDotEnabled: options.syncToPlaybackDotEnabled, })); this.displayResult(result, options.output); }, 'record.outline.create'); } async getRecordFileOutline(options) { return this.executeWithErrorHandling(async () => { const result = await this.recordService.getRecordFileOutline(options.channelId, options.fileId); this.displayResult(result, options.output); }, 'record.outline.get'); } async batchPublishRecordFileSubtitles(options) { return this.executeWithErrorHandling(async () => { await (0, api_command_1.confirmWrite)(options.force, `Publish ${options.subtitles.length} record file subtitle(s)?`); await this.recordService.batchPublishRecordFileSubtitles(options.subtitles); this.displayResult({ published: true, subtitles: options.subtitles }, options.output); }, 'record.subtitle.publish'); } displayPlaybackSetting(setting, channelId, format = 'table') { this.displayInfo(`回放设置 - 频道: ${channelId}`); if (format === 'json') { this.displayData(setting, 'json'); } else { this.displayPlaybackSettingTable(setting); } } compactOptions(options) { return Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined && value !== '')); } displayResult(result, format = 'table') { this.displayData(result ?? { success: true }, format); } displayPlaybackSettingTable(setting) { const tableData = []; tableData.push({ '属性': '回放开关', '值': PLAYBACK_ENABLED_MAP[setting.playbackEnabled ?? ''] ?? setting.playbackEnabled ?? '-' }); tableData.push({ '属性': '回放类型', '值': PLAYBACK_TYPE_MAP[setting.type ?? ''] ?? setting.type ?? '-' }); tableData.push({ '属性': '回放来源', '值': PLAYBACK_ORIGIN_MAP[setting.origin ?? ''] ?? setting.origin ?? '-' }); tableData.push({ '属性': '视频ID', '值': setting.videoId ?? '-' }); tableData.push({ '属性': '视频名称', '值': setting.videoName ?? '-' }); tableData.push({ '属性': '倍数播放', '值': PLAYBACK_ENABLED_MAP[setting.playbackMultiplierEnabled ?? ''] ?? setting.playbackMultiplierEnabled ?? '-' }); tableData.push({ '属性': '进度条', '值': PLAYBACK_ENABLED_MAP[setting.playbackProgressBarEnabled ?? ''] ?? setting.playbackProgressBarEnabled ?? '-' }); tableData.push({ '属性': '进度条操作', '值': PROGRESS_BAR_TYPE_MAP[setting.playbackProgressBarOperationType ?? ''] ?? setting.playbackProgressBarOperationType ?? '-' }); tableData.push({ '属性': '显示播放按钮', '值': PLAYBACK_ENABLED_MAP[setting.showPlayButtonEnabled ?? ''] ?? setting.showPlayButtonEnabled ?? '-' }); tableData.push({ '属性': '聊天互动重现', '值': PLAYBACK_ENABLED_MAP[setting.chatPlaybackEnabled ?? ''] ?? setting.chatPlaybackEnabled ?? '-' }); tableData.push({ '属性': '商品库重现', '值': PLAYBACK_ENABLED_MAP[setting.productPlaybackEnabled ?? ''] ?? setting.productPlaybackEnabled ?? '-' }); this.displayAsTable(tableData); } displaySetPlaybackSettingResult(options) { const format = options['output'] || 'table'; const resultData = { channelId: options['channelId'], status: 'success', }; if (options['playbackEnabled'] !== undefined) resultData.playbackEnabled = options['playbackEnabled']; if (options['type'] !== undefined) resultData.type = options['type']; if (options['origin'] !== undefined) resultData.origin = options['origin']; if (options['videoId'] !== undefined) resultData.videoId = options['videoId']; this.displayInfo(`设置成功 - 频道: ${options['channelId']}`); if (format === 'json') { this.displayData(resultData, 'json'); } else { const tableData = []; tableData.push({ '属性': '频道', '值': options['channelId'] }); tableData.push({ '属性': '状态', '值': '已更新' }); if (options['playbackEnabled'] !== undefined) { tableData.push({ '属性': '回放开关', '值': PLAYBACK_ENABLED_MAP[options['playbackEnabled']] ?? options['playbackEnabled'] }); } this.displayAsTable(tableData); } } displayConvertResult(options, result) { const format = options.output || 'table'; if (result.async) { this.displayInfo(`转存任务已提交 - 频道: ${options.channelId}`); const resultData = { channelId: options.channelId, fileIds: options.fileIds, fileName: options.fileName, status: 'processing', }; if (format === 'json') { this.displayData(resultData, 'json'); } else { const tableData = []; tableData.push({ '属性': '录制文件ID', '值': options.fileIds ?? '-' }); tableData.push({ '属性': '文件名', '值': options.fileName ?? '-' }); tableData.push({ '属性': '状态', '值': '处理中' }); tableData.push({ '属性': '说明', '值': '异步转存不立即返回视频ID,请在点播后台查看' }); this.displayAsTable(tableData); } } else { this.displayInfo(`转存成功 - 频道: ${options.channelId}`); const resultData = { channelId: options.channelId, sessionId: options.sessionId, fileName: options.fileName, toPlayList: options.toPlayList, setAsDefault: options.setAsDefault, vid: result.vid, }; if (format === 'json') { this.displayData(resultData, 'json'); } else { const tableData = []; tableData.push({ '属性': '源场次ID', '值': options.sessionId ?? '-' }); tableData.push({ '属性': '文件名', '值': options.fileName ?? '-' }); tableData.push({ '属性': '存入回放列表', '值': Y_N_MAP[options.toPlayList ?? ''] ?? options.toPlayList ?? '-' }); tableData.push({ '属性': '设为默认回放', '值': Y_N_MAP[options.setAsDefault ?? ''] ?? options.setAsDefault ?? '-' }); tableData.push({ '属性': '点播视频ID', '值': result.vid ?? '-' }); this.displayAsTable(tableData); } } } displaySetDefaultResult(options) { const format = options.output || 'table'; const resultData = { channelId: options.channelId, videoId: options.videoId, listType: options.listType, status: 'success', }; this.displayInfo(`设置成功 - 频道: ${options.channelId}`); if (format === 'json') { this.displayData(resultData, 'json'); } else { const tableData = []; tableData.push({ '属性': '视频ID', '值': options.videoId }); tableData.push({ '属性': '列表类型', '值': options.listType === 'playback' ? '回放列表' : options.listType === 'vod' ? '点播列表' : '-' }); tableData.push({ '属性': '状态', '值': '已设为默认回放' }); this.displayAsTable(tableData); } } } exports.RecordHandler = RecordHandler; //# sourceMappingURL=record.handler.js.map