UNPKG

polyv-live-cli

Version:

CLI tool for managing PolyV live streaming services.

145 lines 8.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PlayerHandler = void 0; const base_handler_1 = require("./base.handler"); const player_service_sdk_1 = require("../services/player.service.sdk"); const errors_1 = require("../utils/errors"); const api_command_1 = require("../utils/api-command"); class PlayerHandler extends base_handler_1.BaseHandler { constructor(authConfig, serviceConfig, playerService) { super(); this.playerService = playerService ?? new player_service_sdk_1.PlayerServiceSdk(authConfig, serviceConfig); } async getConfig(options) { return this.executeWithErrorHandling(async () => { const config = await this.playerService.getChannelDecorate(options); this.displayConfig(config, options.channelId, options.output); }, 'player.config.get'); } displayConfig(config, channelId, format = 'table') { this.displayInfo(`播放器配置`); this.displayInfo(`频道号: ${channelId}`); if (format === 'json') { this.displayData(config, 'json'); } else { this.displayConfigTable(config); } } displayConfigTable(config) { this.displayInfo('\n水印设置 (watermark):'); const watermarkTable = [ { '配置项 (field)': '水印开关 (watermarkEnabled)', '值': `${config.watermarkEnabled} (${config.watermarkEnabled === 'Y' ? '开启' : '关闭'})` }, { '配置项 (field)': '水印图片 (watermarkUrl)', '值': config.watermarkUrl || '-' }, { '配置项 (field)': '水印位置 (watermarkPosition)', '值': `${config.watermarkPosition} (${this.getPositionLabel(config.watermarkPosition)})` }, { '配置项 (field)': '水印透明度 (watermarkOpacity)', '值': config.watermarkOpacity }, { '配置项 (field)': '水印链接 (watermarkLink)', '值': config.watermarkLink || '-' }, ]; this.displayAsTable(watermarkTable); this.displayInfo('\n暖场设置 (warmup):'); const warmupTable = [ { '配置项 (field)': '暖场开关 (warmupEnabled)', '值': `${config.warmupEnabled} (${config.warmupEnabled === 'Y' ? '开启' : '关闭'})` }, { '配置项 (field)': '暖场图片 (warmupImageUrl)', '值': config.warmupImageUrl || '-' }, { '配置项 (field)': '封面跳转 (coverJumpUrl)', '值': config.coverJumpUrl || '-' }, { '配置项 (field)': '背景图片 (backgroundImageUrl)', '值': config.backgroundImageUrl || '-' }, ]; this.displayAsTable(warmupTable); this.displayInfo('\n观看数据 (view data):'); const viewDataTable = [ { '配置项 (field)': '基础观看次数 (basePv)', '值': config.basePv }, { '配置项 (field)': '实际观看次数 (actualPv)', '值': config.actualPv }, ]; this.displayAsTable(viewDataTable); } getPositionLabel(position) { const positionMap = { 'tl': '左上角', 'tr': '右上角', 'bl': '左下角', 'br': '右下角', }; return positionMap[position] || position; } async updateConfig(options) { return this.executeWithErrorHandling(async () => { const result = await this.playerService.updateChannelDecorate(options); this.displayUpdateResult(result, options.channelId, options.output); }, 'player.config.update'); } async getAntiRecord(options) { this.requireFields(options, ['channelId']); this.displayData(await this.playerService.getAntiRecordSettings(options.channelId), options.output || 'table'); } async updateAntiRecord(options) { this.requireFields(options, ['channelId', 'antiRecordType', 'modelType', 'content', 'fontSize']); const params = (0, api_command_1.apiParams)({ ...options, channelId: undefined }); await (0, api_command_1.confirmWrite)(options.force, `Update anti-record settings for channel ${options.channelId}?`); this.displayData({ success: true, result: await this.playerService.setAntiRecordSettings(options.channelId, params) }, options.output || 'table'); } async setMarqueeUrl(options) { this.requireFields(options, ['channelId', 'marqueeRestrict']); const params = (0, api_command_1.apiParams)({ ...options, channelId: undefined }); await (0, api_command_1.confirmWrite)(options.force, `Update marquee URL for channel ${options.channelId}?`); this.displayData({ success: true, result: await this.playerService.setMarqueeUrl(options.channelId, params) }, options.output || 'table'); } async updateHeadAdvert(options) { this.requireFields(options, ['channelId', 'headAdvertType']); const params = (0, api_command_1.apiParams)({ ...options, channelId: undefined }); await (0, api_command_1.confirmWrite)(options.force, `Update head advert for channel ${options.channelId}?`); this.displayData({ success: true, result: await this.playerService.updateHeadAdvert(options.channelId, params) }, options.output || 'table'); } async updateStopAdvert(options) { this.requireFields(options, ['channelId']); const params = (0, api_command_1.apiParams)({ ...options, channelId: undefined }); await (0, api_command_1.confirmWrite)(options.force, `Update stop advert for channel ${options.channelId}?`); this.displayData({ success: true, result: await this.playerService.updateStopAdvert(options.channelId, params) }, options.output || 'table'); } async listWatchFeedback(options) { this.displayData(await this.playerService.getWatchFeedbackList((0, api_command_1.apiParams)(options)), options.output || 'table'); } async updateLogo(options) { this.requireFields(options, ['channelId', 'logoImage']); const params = (0, api_command_1.apiParams)({ ...options, channelId: undefined }); await (0, api_command_1.confirmWrite)(options.force, `Update player logo for channel ${options.channelId}?`); this.displayData({ success: await this.playerService.updatePlayerLogo(options.channelId, params), channelId: options.channelId }, options.output || 'table'); } async updateWarmupSwitch(options) { this.requireFields(options, ['channelId', 'warmUpEnabled']); await (0, api_command_1.confirmWrite)(options.force, `Update warmup switch for channel ${options.channelId}?`); this.displayData({ success: true, result: await this.playerService.updateWarmupSwitch({ channelId: options.channelId, warmUpEnabled: options.warmUpEnabled, }), }, options.output || 'table'); } async updateSkinBatch(options) { this.requireFields(options, ['channelIds', 'skin']); await (0, api_command_1.confirmWrite)(options.force, `Update player skin for ${options.channelIds.length} channel(s)?`); this.displayData({ success: await this.playerService.updateSkinBatch((0, api_command_1.apiParams)(options)) }, options.output || 'table'); } requireFields(options, fields) { const missing = fields.filter((field) => options[field] === undefined || options[field] === null || options[field] === ''); if (missing.length > 0) { throw new errors_1.PolyVValidationError(`Missing required option(s): ${missing.join(', ')}`, 'options', options, 'validation_failed'); } } displayUpdateResult(result, channelId, format = 'table') { this.displayInfo(`播放器配置更新${result.success ? 'success' : '失败'}`); this.displayInfo(`频道号: ${channelId}`); if (format === 'json') { this.displayData(result, 'json'); } else { if (result.updatedFields.length > 0) { this.displayInfo('\n已更新:'); result.updatedFields.forEach((field) => { this.displayInfo(`- ${field}`); }); } } } } exports.PlayerHandler = PlayerHandler; //# sourceMappingURL=player.handler.js.map