polyv-live-cli
Version:
CLI tool for managing PolyV live streaming services.
188 lines • 8.09 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlatformServiceSdk = void 0;
const platform_1 = require("../types/platform");
const sdk_1 = require("../sdk");
const errors_1 = require("../utils/errors");
class PlatformServiceSdk {
constructor(authConfig, serviceConfig) {
this.authConfig = authConfig;
this.config = serviceConfig;
}
async getUserInfo() {
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
const result = await client.account.getUserInfo();
return result;
}
async getSwitchConfig() {
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
const result = await client.account.switchGet();
return result;
}
async updateSwitchConfig(params) {
this.validateUpdateParams(params);
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
const result = await client.account.switchUpdate({
param: params.param,
enabled: params.enabled,
});
return result;
}
validateUpdateParams(params) {
const errors = [];
if (!params.param || typeof params.param !== 'string' || params.param.trim().length === 0) {
errors.push('param (配置项名称) 是必需的');
}
else if (!platform_1.VALID_SWITCH_PARAMS.includes(params.param)) {
errors.push(`不支持的配置项: ${params.param}。可用配置项: ${platform_1.VALID_SWITCH_PARAMS.join(', ')}`);
}
if (!params.enabled || typeof params.enabled !== 'string') {
errors.push('enabled 必须是 Y 或 N');
}
else if (params.enabled !== 'Y' && params.enabled !== 'N') {
errors.push('enabled 必须是 Y 或 N');
}
if (errors.length > 0) {
throw new errors_1.PolyVValidationError(errors.join('; '), 'params', params, 'validation_failed');
}
}
async getCallbackSettings() {
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
const result = await client.v4User.getCallback();
return result;
}
async updateCallbackSettings(params) {
this.validateCallbackParams(params);
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
const updateParams = {};
if (params.url !== undefined) {
updateParams.streamCallbackUrl = params.url;
}
if (params.enabled !== undefined) {
updateParams.rebirthVodCallbackEnabled = params.enabled ? 'Y' : 'N';
}
await client.v4User.updateCallback(updateParams);
return { success: true };
}
validateCallbackParams(params) {
const errors = [];
if (params.url === undefined && params.enabled === undefined) {
errors.push('至少需要提供一个参数 (url 或 enabled)');
}
if (params.url !== undefined && params.url !== '') {
if (!params.url.startsWith('http://') && !params.url.startsWith('https://')) {
errors.push('url 必须以 http:// 或 https:// 开头');
}
}
if (params.enabled !== undefined && typeof params.enabled !== 'boolean') {
errors.push('enabled 必须是布尔值');
}
if (errors.length > 0) {
throw new errors_1.PolyVValidationError(errors.join('; '), 'params', params, 'validation_failed');
}
}
async getGlobalChannelSettings() {
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
const result = await client.v4User.getGlobalChannelSettings();
return result;
}
async updateGlobalChannelSettings(params) {
this.validateGlobalSettingsParams(params);
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
const updateParams = {};
const booleanFields = [
'channelConcurrencesEnabled',
'timelyConvertEnabled',
'donateEnabled',
'rebirthAutoUploadEnabled',
'rebirthAutoConvertEnabled',
'pptCoveredEnabled',
'testModeButtonEnabled',
];
for (const field of booleanFields) {
if (params[field] !== undefined) {
updateParams[field] = params[field];
}
}
if (params.coverImgType !== undefined) {
updateParams.coverImgType = params.coverImgType;
}
await client.v4User.updateGlobalChannelSettings(updateParams);
}
async createAnchor(params) {
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
return client.platform.createAnchor(params);
}
async getAnchor(anchorId) {
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
return client.platform.getAnchor(anchorId);
}
async listAnchors(params = {}) {
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
return client.platform.listAnchors(params);
}
async listAnchorRelations(params) {
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
return client.platform.listAnchorRelations(params);
}
async listAnchorUnrelations(params) {
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
return client.platform.listAnchorUnrelations(params);
}
async updateAnchor(params) {
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
return client.platform.updateAnchor(params);
}
async updateAnchorStatus(params) {
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
return client.platform.updateAnchorStatus(params);
}
async listContentGroups(type) {
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
return client.platform.listContentGroups(type);
}
async searchCouponViewers(params) {
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
return client.v4Platform.searchCouponViewers(params);
}
async updateCoupon(params) {
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
return client.v4Platform.updateCoupon(params);
}
async updateCouponsStatusBatch(params) {
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
return client.v4Platform.updateCouponsStatusBatch(params);
}
validateGlobalSettingsParams(params) {
const errors = [];
const booleanFields = [
'channelConcurrencesEnabled',
'timelyConvertEnabled',
'donateEnabled',
'rebirthAutoUploadEnabled',
'rebirthAutoConvertEnabled',
'pptCoveredEnabled',
'testModeButtonEnabled',
];
const hasAnyField = booleanFields.some((field) => params[field] !== undefined) || params.coverImgType !== undefined;
if (!hasAnyField) {
errors.push('至少需要提供一个参数');
}
for (const field of booleanFields) {
const value = params[field];
if (value !== undefined && value !== 'Y' && value !== 'N') {
errors.push(`${field} 必须是 Y 或 N`);
}
}
if (params.coverImgType !== undefined) {
if (params.coverImgType !== 'contain' && params.coverImgType !== 'cover') {
errors.push('coverImgType 必须是 contain 或 cover');
}
}
if (errors.length > 0) {
throw new errors_1.PolyVValidationError(errors.join('; '), 'params', params, 'validation_failed');
}
}
}
exports.PlatformServiceSdk = PlatformServiceSdk;
//# sourceMappingURL=platform-service.js.map