polyv-live-cli
Version:
CLI tool for managing PolyV live streaming services.
186 lines • 8.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CardPushServiceSdk = void 0;
const polyv_live_api_sdk_1 = require("polyv-live-api-sdk");
class CardPushServiceSdk {
constructor(authConfig, config) {
this.client = new polyv_live_api_sdk_1.PolyVClient({
appId: authConfig.appId,
appSecret: authConfig.appSecret,
baseUrl: config?.baseUrl || 'https://api.polyv.net',
});
this.v4Channel = this.client.v4Channel;
}
async listCardPushes(channelId) {
if (!channelId || channelId.trim() === '') {
throw new Error('Channel ID is required (频道ID是必需的)');
}
const result = await this.v4Channel.listCardPushes({ channelId });
const data = this.unwrapData(result);
return Array.isArray(data) ? data : (data?.contents ?? []);
}
async createCardPush(params) {
if (!params.channelId || params.channelId.trim() === '') {
throw new Error('Channel ID is required (频道ID是必需的)');
}
if (!params.imageType || params.imageType.trim() === '') {
throw new Error('Image type is required (图片类型是必需的)');
}
if (!params.title || params.title.trim() === '') {
throw new Error('Title is required (卡片标题是必需的)');
}
if (!params.link || params.link.trim() === '') {
throw new Error('Link is required (卡片链接是必需的)');
}
if (params.duration === undefined || params.duration === null) {
throw new Error('Duration is required (卡片倒计时时长是必需的)');
}
if (!params.showCondition || params.showCondition.trim() === '') {
throw new Error('Show condition is required (弹出方式是必需的)');
}
const requestParams = {
channelId: parseInt(params.channelId, 10),
imageType: params.imageType,
title: params.title,
link: params.link,
duration: params.duration,
showCondition: params.showCondition,
};
if (params.cardType)
requestParams.cardType = params.cardType;
if (params.durationPosition)
requestParams.durationPosition = params.durationPosition;
if (params.conditionValue !== undefined)
requestParams.conditionValue = params.conditionValue;
if (params.conditionUnit)
requestParams.conditionUnit = params.conditionUnit;
if (params.countdownMsg)
requestParams.countdownMsg = params.countdownMsg;
if (params.enterEnabled)
requestParams.enterEnabled = params.enterEnabled;
if (params.linkEnabled)
requestParams.linkEnabled = params.linkEnabled;
if (params.redirectType)
requestParams.redirectType = params.redirectType;
const result = await this.v4Channel.cardPushCreate(requestParams);
return this.unwrapData(result);
}
async updateCardPush(params) {
if (!params.channelId || params.channelId.trim() === '') {
throw new Error('Channel ID is required (频道ID是必需的)');
}
if (!params.cardPushId || params.cardPushId.trim() === '') {
throw new Error('Card-push ID is required (卡片推送ID是必需的)');
}
const requestBody = {
channelId: parseInt(params.channelId, 10),
cardPushId: parseInt(params.cardPushId, 10),
};
if (params.cardType)
requestBody.cardType = params.cardType;
if (params.imageType)
requestBody.imageType = params.imageType;
if (params.title)
requestBody.title = params.title;
if (params.link)
requestBody.link = params.link;
if (params.duration !== undefined)
requestBody.duration = params.duration;
if (params.durationPosition)
requestBody.durationPosition = params.durationPosition;
if (params.showCondition)
requestBody.showCondition = params.showCondition;
if (params.conditionValue !== undefined)
requestBody.conditionValue = params.conditionValue;
if (params.conditionUnit)
requestBody.conditionUnit = params.conditionUnit;
if (params.countdownMsg)
requestBody.countdownMsg = params.countdownMsg;
if (params.enterEnabled)
requestBody.enterEnabled = params.enterEnabled;
if (params.linkEnabled)
requestBody.linkEnabled = params.linkEnabled;
if (params.redirectType)
requestBody.redirectType = params.redirectType;
const result = await this.v4Channel.cardPushUpdate(requestBody);
return this.unwrapData(result) || { id: parseInt(params.cardPushId, 10) };
}
async pushCard(params) {
if (!params.channelId || params.channelId.trim() === '') {
throw new Error('Channel ID is required (频道ID是必需的)');
}
if (!params.cardPushId || params.cardPushId.trim() === '') {
throw new Error('Card-push ID is required (卡片推送ID是必需的)');
}
await this.v4Channel.cardPushPush({
channelId: parseInt(params.channelId, 10),
cardPushId: parseInt(params.cardPushId, 10),
});
}
async cancelPush(params) {
if (!params.channelId || params.channelId.trim() === '') {
throw new Error('Channel ID is required (频道ID是必需的)');
}
if (!params.cardPushId || params.cardPushId.trim() === '') {
throw new Error('Card-push ID is required (卡片推送ID是必需的)');
}
await this.v4Channel.cardPushCancelPush({
channelId: parseInt(params.channelId, 10),
cardPushId: parseInt(params.cardPushId, 10),
});
}
async deleteCardPush(params) {
if (!params.channelId || params.channelId.trim() === '') {
throw new Error('Channel ID is required (频道ID是必需的)');
}
if (!params.cardPushId || params.cardPushId.trim() === '') {
throw new Error('Card-push ID is required (卡片推送ID是必需的)');
}
await this.v4Channel.cardPushDelete({
channelId: parseInt(params.channelId, 10),
cardPushId: parseInt(params.cardPushId, 10),
});
}
async getShare(channelId) {
if (!channelId || channelId.trim() === '') {
throw new Error('Channel ID is required (频道ID是必需的)');
}
const result = await this.v4Channel.shareGet({ channelId });
return this.unwrapData(result) || {};
}
async updateShare(params) {
if (!params.channelId || params.channelId.trim() === '') {
throw new Error('Channel ID is required (频道ID是必需的)');
}
if (params.shareBtnEnable !== 'Y' && params.shareBtnEnable !== 'N') {
throw new Error('shareBtnEnable must be Y or N');
}
if (!params.titleType || params.titleType.trim() === '') {
throw new Error('titleType is required');
}
const requestParams = this.compactParams({
channelId: params.channelId,
shareBtnEnable: params.shareBtnEnable,
titleType: params.titleType,
weixinShareTitle: params.weixinShareTitle,
weixinShareDesc: params.weixinShareDesc,
weixinShareCustomUrl: params.weixinShareCustomUrl,
webShareCustomUrl: params.webShareCustomUrl,
weixinShareCustomUrlWithParamEnabled: params.weixinShareCustomUrlWithParamEnabled,
webShareCustomUrlWithParamEnabled: params.webShareCustomUrlWithParamEnabled,
});
const result = await this.v4Channel.shareUpdate(requestParams);
return this.unwrapData(result) || { success: true };
}
unwrapData(value) {
if (value && typeof value === 'object' && 'data' in value) {
return value.data;
}
return value;
}
compactParams(params) {
return Object.fromEntries(Object.entries(params).filter(([, value]) => value !== undefined && value !== ''));
}
}
exports.CardPushServiceSdk = CardPushServiceSdk;
//# sourceMappingURL=card-push-service.js.map