polyv-live-cli
Version:
CLI tool for managing PolyV live streaming services.
194 lines • 11 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebHandler = void 0;
const fs_1 = require("fs");
const base_handler_1 = require("./base.handler");
const errors_1 = require("../utils/errors");
const api_command_1 = require("../utils/api-command");
const web_service_1 = require("../services/web-service");
class WebHandler extends base_handler_1.BaseHandler {
constructor(authConfig, serviceConfig) {
super();
this.service = new web_service_1.WebServiceSdk(authConfig, serviceConfig);
}
async getSplash(options) {
this.requireFields(options, ['channelId']);
this.show(await this.service.getSplash(options.channelId), options.output);
}
async setSplash(options) {
this.requireFields(options, ['channelId', 'splashEnabled']);
await this.confirm(options, `Update splash settings for channel ${options.channelId}?`);
this.show({ success: true, result: await this.service.setSplash((0, api_command_1.apiParams)(options)) }, options.output);
}
async setPublisher(options) {
this.requireFields(options, ['userId', 'publisher']);
await this.confirm(options, `Update publisher for ${options.channelId || 'all channels'}?`);
this.show({ success: true, result: await this.service.setPublisher((0, api_command_1.apiParams)(options)) }, options.output);
}
async updateChannelName(options) {
this.requireFields(options, ['channelId', 'name']);
await this.confirm(options, `Update channel name for ${options.channelId}?`);
this.show({ success: await this.service.updateChannelName((0, api_command_1.apiParams)(options)), channelId: options.channelId }, options.output);
}
async updateChannelLogo(options) {
this.requireFields(options, ['channelId', 'imgfile']);
await this.confirm(options, `Update channel logo for ${options.channelId}?`);
this.show({ success: true, result: await this.service.updateChannelLogo((0, api_command_1.apiParams)(options)) }, options.output);
}
async getLikes(options) {
this.requireFields(options, ['channelIds']);
this.show(await this.service.liveLikes(options.channelIds), options.output);
}
async updateLikes(options) {
this.requireFields(options, ['channelId']);
await this.confirm(options, `Update likes/viewers for channel ${options.channelId}?`);
this.show({ success: true, result: await this.service.updateLikes((0, api_command_1.apiParams)(options)) }, options.output);
}
async getCountdown(options) {
this.requireFields(options, ['channelId']);
this.show(await this.service.getCountdown(options.channelId), options.output);
}
async setCountdown(options) {
this.requireFields(options, ['channelId']);
await this.confirm(options, `Update countdown settings for channel ${options.channelId}?`);
this.show({ success: true, result: await this.service.setCountdown((0, api_command_1.apiParams)(options)) }, options.output);
}
async listMenus(options) {
this.requireFields(options, ['channelId']);
this.show(await this.service.getMenuList((0, api_command_1.apiParams)(options)), options.output);
}
async addMenu(options) {
this.requireFields(options, ['channelId', 'name', 'type']);
await this.confirm(options, `Add menu ${options.name} to channel ${options.channelId}?`);
this.show(await this.service.addMenu((0, api_command_1.apiParams)(options)), options.output);
}
async deleteMenu(options) {
this.requireFields(options, ['menuIds']);
await this.confirm(options, `Delete menu(s) ${options.menuIds}?`);
this.show({ success: true, result: await this.service.deleteMenu((0, api_command_1.apiParams)(options)) }, options.output);
}
async updateMenu(options) {
this.requireFields(options, ['menuId', 'channelId', 'content']);
await this.confirm(options, `Update menu ${options.menuId}?`);
this.show({ success: true, result: await this.service.updateMenu((0, api_command_1.apiParams)(options)) }, options.output);
}
async setMenu(options) {
this.requireFields(options, ['userId', 'channelId', 'content']);
await this.confirm(options, `Update live intro menu for channel ${options.channelId}?`);
this.show({ success: true, result: await this.service.setMenu((0, api_command_1.apiParams)({ ...options, menuType: 'desc' })) }, options.output);
}
async updateRank(options) {
this.requireFields(options, ['channelId', 'menuIds']);
await this.confirm(options, `Update menu rank for channel ${options.channelId}?`);
this.show({ success: true, result: await this.service.updateRank((0, api_command_1.apiParams)(options)) }, options.output);
}
async updateConsultingEnabled(options) {
this.requireFields(options, ['channelId', 'enabled']);
await this.confirm(options, `Update consulting switch for channel ${options.channelId}?`);
this.show({ success: true, result: await this.service.updateConsultingEnabled((0, api_command_1.apiParams)(options)) }, options.output);
}
async listTuwen(options) {
this.requireFields(options, ['channelId']);
this.show(await this.service.getTuwenList((0, api_command_1.apiParams)(options)), options.output);
}
async getDonate(options) {
this.show(await this.service.getDonate(options.channelId), options.output);
}
async updateCash(options) {
this.requireFields(options, ['cashes', 'cashMin']);
await this.confirm(options, `Update cash donate settings for ${options.channelId || 'global settings'}?`);
this.show({ success: true, result: await this.service.updateCash((0, api_command_1.apiParams)(options)) }, options.output);
}
async updateGood(options) {
this.requireFields(options, ['goods']);
await this.confirm(options, `Update gift donate settings for ${options.channelId || 'global settings'}?`);
this.show({ success: true, result: await this.service.updateGood((0, api_command_1.apiParams)(options)) }, options.output);
}
async getWeixinShare(options) {
this.requireFields(options, ['channelId']);
this.show(await this.service.getWeixinShare(options.channelId), options.output);
}
async updateWeixinShare(options) {
this.requireFields(options, ['channelId']);
await this.confirm(options, `Update WeChat share settings for channel ${options.channelId}?`);
this.show({ success: true, result: await this.service.updateWeixinShare((0, api_command_1.apiParams)(options)) }, options.output);
}
async updateGlobalEnabled(options) {
this.requireFields(options, ['channelId', 'globalEnabledType', 'enabled']);
await this.confirm(options, `Update ${options.globalEnabledType} global-enabled for channel ${options.channelId}?`);
this.show({ success: true, result: await this.service.updateGlobalEnabled((0, api_command_1.apiParams)(options)) }, options.output);
}
async uploadImage(options) {
this.requireFields(options, ['type', 'files']);
await this.confirm(options, `Upload ${options.files.length} image file(s)?`);
this.show(await this.service.uploadImage((0, api_command_1.apiParams)(options)), options.output);
}
async uploadWhiteList(options) {
this.requireFields(options, ['rank', 'file']);
await this.confirm(options, `Upload whitelist file for rank ${options.rank}?`);
this.show({ success: true, result: await this.service.uploadWhiteList((0, api_command_1.apiParams)(options)) }, options.output);
}
async downloadWhiteList(options) {
this.requireFields(options, ['rank']);
await this.downloadResult(await this.service.downloadWhiteList((0, api_command_1.apiParams)(options)), options);
}
async setAuthType(options) {
this.requireFields(options, ['channelId', 'authType']);
await this.confirm(options, `Update auth type for channel ${options.channelId}?`);
this.show({ success: true, result: await this.service.setAuthType((0, api_command_1.apiParams)(options)) }, options.output);
}
async setExternalAuth(options) {
this.requireFields(options, ['userId', 'externalUri']);
await this.confirm(options, `Update external auth for ${options.channelId || 'all channels'}?`);
this.show(await this.service.setExternalAuth((0, api_command_1.apiParams)(options)), options.output);
}
async setAuthorizedAddress(options) {
this.requireFields(options, ['userId', 'customUri']);
await this.confirm(options, `Update custom authorized address for ${options.channelId || 'all channels'}?`);
this.show(await this.service.setAuthorizedAddress((0, api_command_1.apiParams)(options)), options.output);
}
async updateAuthUrl(options) {
await this.confirm(options, `Update restrict auth URL for ${options.channelId || 'global settings'}?`);
this.show({ success: true, result: await this.service.updateAuthUrl((0, api_command_1.apiParams)(options)) }, options.output);
}
async getRecordField(options) {
this.requireFields(options, ['channelId']);
this.show(await this.service.getRecordField((0, api_command_1.apiParams)(options)), options.output);
}
async listRecordInfo(options) {
this.requireFields(options, ['channelId']);
this.show(await this.service.getRecordInfo((0, api_command_1.apiParams)(options)), options.output);
}
async listEnroll(options) {
this.requireFields(options, ['channelId']);
this.show(await this.service.enrollList((0, api_command_1.apiParams)(options)), options.output);
}
async downloadRecordInfo(options) {
this.requireFields(options, ['channelId']);
await this.downloadResult(await this.service.downloadRecordInfo((0, api_command_1.apiParams)(options)), options);
}
async confirm(options, message) {
await (0, api_command_1.confirmWrite)(options.force, message);
}
async downloadResult(data, options) {
const buffer = Buffer.from(data);
if (options.outputFile) {
(0, fs_1.writeFileSync)(options.outputFile, buffer);
}
this.show({ success: true, bytes: buffer.byteLength, outputFile: options.outputFile }, options.output);
}
show(data, output = 'table') {
this.displayData(data, output);
}
requireFields(options, fields) {
const missing = fields.filter((field) => {
const value = options[field];
return value === undefined || value === null || value === '';
});
if (missing.length > 0) {
throw new errors_1.PolyVValidationError(`Missing required option(s): ${missing.join(', ')}`, 'options', options, 'validation_failed');
}
}
}
exports.WebHandler = WebHandler;
//# sourceMappingURL=web.handler.js.map