UNPKG

polyv-live-cli

Version:

CLI tool for managing PolyV live streaming services.

131 lines 5.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.loadAuthAndServiceConfig = loadAuthAndServiceConfig; exports.validateOutputFormat = validateOutputFormat; exports.validateAssociationType = validateAssociationType; exports.registerTransmitCommands = registerTransmitCommands; const transmit_handler_1 = require("../handlers/transmit.handler"); const auth_adapter_1 = require("../config/auth-adapter"); const manager_1 = require("../config/manager"); const errors_1 = require("../utils/errors"); const api_command_1 = require("../utils/api-command"); const DEFAULT_TIMEOUT_MS = 30000; async function loadAuthAndServiceConfig(parentOptions) { const authResult = auth_adapter_1.authAdapter.tryGetAuthConfig(parentOptions); if (!authResult) { throw new Error(auth_adapter_1.authAdapter.getStatusMessage(parentOptions)); } let configResult; try { configResult = await manager_1.configManager.load({ cliOptions: parentOptions, }); } catch (error) { if (error instanceof Error && error.message.includes('Auth configuration is incomplete')) { configResult = { config: { baseUrl: 'https://api.polyv.net', timeout: DEFAULT_TIMEOUT_MS, debug: false, }, }; } else { throw error; } } const serviceConfig = { baseUrl: configResult.config.baseUrl, timeout: configResult.config.timeout, debug: configResult.config.debug, }; const isVerbose = !!parentOptions['verbose']; if (isVerbose) { console.log('Using authentication from:', authResult.source); } return { authConfig: authResult.config, serviceConfig, isVerbose }; } function validateOutputFormat(format) { if (format !== 'table' && format !== 'json') { throw new Error('Invalid output format. Must be table or json'); } return format; } function validateAssociationType(type) { if (type !== 'add' && type !== 'cancel') { throw new Error('Association type must be add or cancel'); } return type; } function registerTransmitCommands(program) { const transmitCmd = program .command('transmit') .description('Manage transmit channels for live streaming (管理直播转播频道)'); transmitCmd .command('create') .description('Batch create transmit channels (批量创建转播频道)') .requiredOption('--channelId <id>', 'Source channel ID (发起转播的频道号)') .requiredOption('--names <names>', 'Channel names comma-separated (频道名称,逗号分隔)') .option('-o, --output <format>', 'Output format (table|json)', validateOutputFormat, 'table') .action(async (options) => { try { const { authConfig, serviceConfig } = await loadAuthAndServiceConfig(options); const handler = new transmit_handler_1.TransmitHandler(authConfig, serviceConfig); await handler.batchCreateTransmitChannels({ channelId: options.channelId, names: options.names, output: options.output, }); } catch (error) { (0, errors_1.logError)(error instanceof Error ? error : new Error(String(error))); process.exit(1); } }); transmitCmd .command('list') .description('Get transmit associations (获取转播关联列表)') .requiredOption('--channelId <id>', 'Channel ID (频道号)') .option('-o, --output <format>', 'Output format (table|json)', validateOutputFormat, 'table') .action(async (options) => { try { const { authConfig, serviceConfig } = await loadAuthAndServiceConfig(options); const handler = new transmit_handler_1.TransmitHandler(authConfig, serviceConfig); await handler.getTransmitAssociations({ channelId: options.channelId, output: options.output, }); } catch (error) { (0, errors_1.logError)(error instanceof Error ? error : new Error(String(error))); process.exit(1); } }); transmitCmd .command('associate') .description('Add or cancel receive channel transmit associations (关联或取消接收转播频道)') .requiredOption('--channelId <id>', 'Source channel ID (发起转播的频道号)') .requiredOption('--receive-channel-ids <ids>', 'Receive channel IDs, comma-separated (接收频道号,逗号分隔)', api_command_1.parseStringList) .option('--type <type>', 'Operation type: add|cancel', validateAssociationType, 'add') .option('-f, --force', 'Skip confirmation prompt') .option('-o, --output <format>', 'Output format (table|json)', validateOutputFormat, 'table') .action(async (options) => { try { const { authConfig, serviceConfig } = await loadAuthAndServiceConfig(options); const handler = new transmit_handler_1.TransmitHandler(authConfig, serviceConfig); await handler.associationReceiveChannels({ channelId: options.channelId, receiveChannelIds: options.receiveChannelIds, type: options.type, force: options.force, output: options.output, }); } catch (error) { (0, errors_1.logError)(error instanceof Error ? error : new Error(String(error))); process.exit(1); } }); } //# sourceMappingURL=transmit.commands.js.map