UNPKG

polyv-live-cli

Version:

CLI tool for managing PolyV live streaming services.

217 lines (206 loc) 8.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateOutputFormat = validateOutputFormat; exports.registerDonateCommands = registerDonateCommands; const donate_handler_1 = require("../handlers/donate.handler"); const manager_1 = require("../config/manager"); const auth_adapter_1 = require("../config/auth-adapter"); const errors_1 = require("../utils/errors"); function validateOutputFormat(value) { if (!['table', 'json'].includes(value)) { throw new Error('Output format must be either "table" or "json"'); } return value; } function registerDonateCommands(program) { const donateCmd = program.command('donate'); donateCmd.description('Manage live streaming donate interactions'); const configCmd = donateCmd.command('config'); configCmd.description('Manage donate configuration'); const getCmd = configCmd .command('get') .description('Get donate configuration') .requiredOption('-c, --channel-id <id>', 'channel ID') .option('-o, --output <format>', 'output format (table|json)', validateOutputFormat, 'table') .action(async (options) => { try { const parentOptions = program.opts(); const { authConfig, serviceConfig } = await loadAuthAndServiceConfig(parentOptions); const donateHandler = new donate_handler_1.DonateHandler(authConfig, serviceConfig); await donateHandler.getConfig({ channelId: options.channelId, output: options.output, }); } catch (error) { (0, errors_1.logError)(error instanceof Error ? error : new Error(String(error))); process.exit(1); } }); getCmd.addHelpText('after', ` Examples: # Get donate configuration $ polyv-live-cli donate config get -c "3151318" # JSON output $ polyv-live-cli donate config get -c "3151318" -o json Output Formats: table - Formatted table output (default) json - JSON format for programmatic use `); const updateCmd = configCmd .command('update') .description('Update gift donate configuration') .requiredOption('-c, --channel-id <id>', 'channel ID') .option('--cash-enabled <Y|N>', 'enable generated cash gift entries (Y/N, requires --amounts)') .option('--gift-enabled <Y|N>', 'enable gift donate (Y/N)') .option('--amounts <values>', 'donate amounts (comma-separated, e.g., "0.88,6.66,8.88")') .option('-f, --force', 'skip confirmation prompt') .option('-o, --output <format>', 'output format (table|json)', validateOutputFormat, 'table') .action(async (options) => { try { const parentOptions = program.opts(); const { authConfig, serviceConfig } = await loadAuthAndServiceConfig(parentOptions); const donateHandler = new donate_handler_1.DonateHandler(authConfig, serviceConfig); await donateHandler.updateConfig({ channelId: options.channelId, cashEnabled: options.cashEnabled, giftEnabled: options.giftEnabled, amounts: options.amounts, force: options.force, output: options.output, }); } catch (error) { (0, errors_1.logError)(error instanceof Error ? error : new Error(String(error))); process.exit(1); } }); updateCmd.addHelpText('after', ` Examples: # Enable gift donate $ polyv-live-cli donate config update -c "3151318" --gift-enabled Y # Update cash gift amounts $ polyv-live-cli donate config update -c "3151318" --amounts "0.88,6.66,8.88,18.88" # Update all gift donate settings $ polyv-live-cli donate config update -c "3151318" --gift-enabled Y --cash-enabled Y --amounts "1,5,10" Output Formats: table - Formatted table output (default) json - JSON format for programmatic use `); const listCmd = donateCmd .command('list') .description('List donate records') .requiredOption('-c, --channel-id <id>', 'channel ID') .requiredOption('--start <timestamp>', 'start time (timestamp in milliseconds)', parseInt) .requiredOption('--end <timestamp>', 'end time (timestamp in milliseconds)', parseInt) .option('--page <number>', 'page number', parseInt) .option('--size <number>', 'page size', parseInt) .option('-o, --output <format>', 'output format (table|json)', validateOutputFormat, 'table') .action(async (options) => { try { const parentOptions = program.opts(); const { authConfig, serviceConfig } = await loadAuthAndServiceConfig(parentOptions); const donateHandler = new donate_handler_1.DonateHandler(authConfig, serviceConfig); await donateHandler.listRecords({ channelId: options.channelId, start: options.start, end: options.end, page: options.page, size: options.size, output: options.output, }); } catch (error) { (0, errors_1.logError)(error instanceof Error ? error : new Error(String(error))); process.exit(1); } }); listCmd.addHelpText('after', ` Examples: # List donate records with time range $ polyv-live-cli donate list -c "3151318" --start 1615772426000 --end 1615858826000 # List with pagination $ polyv-live-cli donate list -c "3151318" --start 1615772426000 --end 1615858826000 --page 2 --size 20 # JSON output $ polyv-live-cli donate list -c "3151318" --start 1615772426000 --end 1615858826000 -o json Note: --start and --end require 13-digit millisecond timestamps (e.g., 1615772426000) Output Formats: table - Formatted table output (default) json - JSON format for programmatic use `); const likesCmd = donateCmd .command('likes') .description('List like reward records') .requiredOption('-c, --channel-id <id>', 'channel ID') .option('--start <timestamp>', 'start time (timestamp in milliseconds)', parseInt) .option('--end <timestamp>', 'end time (timestamp in milliseconds)', parseInt) .option('--page <number>', 'page number', parseInt) .option('--size <number>', 'page size', parseInt) .option('-o, --output <format>', 'output format (table|json)', validateOutputFormat, 'table') .action(async (options) => { try { const parentOptions = program.opts(); const { authConfig, serviceConfig } = await loadAuthAndServiceConfig(parentOptions); const donateHandler = new donate_handler_1.DonateHandler(authConfig, serviceConfig); await donateHandler.listLikes({ channelId: options.channelId, start: options.start, end: options.end, page: options.page, size: options.size, output: options.output, }); } catch (error) { (0, errors_1.logError)(error instanceof Error ? error : new Error(String(error))); process.exit(1); } }); likesCmd.addHelpText('after', ` Examples: # List like reward records $ polyv-live-cli donate likes -c "3151318" # List with a time range $ polyv-live-cli donate likes -c "3151318" --start 1615772426000 --end 1615858826000 Output Formats: table - Formatted table output (default) json - JSON format for programmatic use `); } 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: 30000, debug: false } }; } else { throw error; } } const serviceConfig = { baseUrl: configResult.config.baseUrl, timeout: configResult.config.timeout, debug: configResult.config.debug, }; return { authConfig: authResult.config, serviceConfig, }; } //# sourceMappingURL=donate.commands.js.map