UNPKG

polyv-live-cli

Version:

CLI tool for managing PolyV live streaming services.

67 lines 2.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PromotionServiceSdk = void 0; const polyv_live_api_sdk_1 = require("polyv-live-api-sdk"); class PromotionServiceSdk { 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 listPopularizations(channelId) { if (!channelId || channelId.trim() === '') { throw new Error('Channel ID is required'); } const response = await this.v4Channel.listPopularizations({ channelId, pageNumber: 1, pageSize: 500, }); const data = this.unwrapData(response); const items = Array.isArray(data) ? data : (data?.contents ?? []); return items.map((item) => { const value = item; return { promoteId: value['promoteId'] ?? value['id'], popularizationName: value['popularizationName'] ?? value['name'], visitsNum: value['visitsNum'] ?? 0, reservationNum: value['reservationNum'] ?? 0, watchNum: value['watchNum'] ?? 0, viewerNum: value['viewerNum'] ?? 0, averageWatchTime: value['averageWatchTime'] ?? '', enrollNum: value['enrollNum'] ?? 0, createdTime: value['createdTime'] ?? 0, }; }); } async batchCreatePopularizations(params) { if (!params.channelId || params.channelId.trim() === '') { throw new Error('Channel ID is required'); } if (!params.names || params.names.length === 0) { throw new Error('Names array cannot be empty'); } const response = await this.v4Channel.createPopularizations({ channelId: parseInt(params.channelId, 10), names: params.names, }); const items = this.unwrapData(response) ?? []; return items.map((item) => ({ promoteId: item['promoteId'] ?? item.id, popularizationName: item['popularizationName'] ?? item.name, })); } unwrapData(value) { if (value && typeof value === 'object' && 'data' in value) { return value.data; } return value; } } exports.PromotionServiceSdk = PromotionServiceSdk; //# sourceMappingURL=promotion-service.js.map