polyv-live-cli
Version:
CLI tool for managing PolyV live streaming services.
113 lines • 4.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PlatformLabelHandler = void 0;
const base_handler_1 = require("./base.handler");
const errors_1 = require("../utils/errors");
const platform_label_service_1 = require("../services/platform-label-service");
class PlatformLabelHandler extends base_handler_1.BaseHandler {
constructor(authConfig, serviceConfig) {
super();
this.labelService = new platform_label_service_1.PlatformLabelServiceSdk(authConfig, serviceConfig);
}
async listLabels(options) {
return this.executeWithErrorHandling(async () => {
const format = this.validateOutputFormat(options.output);
const labels = await this.labelService.listViewerLabels();
if (format === 'json') {
this.displayData(labels, 'json');
}
else {
this.displayLabelsTable(labels);
}
}, 'platformLabel.listLabels');
}
async createLabel(options) {
return this.executeWithErrorHandling(async () => {
const format = this.validateOutputFormat(options.output);
this.validateLabelName(options.labelName);
const label = await this.labelService.createViewerLabel({
labelName: options.labelName,
});
if (format === 'json') {
this.displayData(label, 'json');
}
else {
this.displaySuccess('标签创建成功');
this.displayLabelInfo(label);
}
}, 'platformLabel.createLabel');
}
async updateLabel(options) {
return this.executeWithErrorHandling(async () => {
const format = this.validateOutputFormat(options.output);
this.validateLabelId(options.labelId);
this.validateLabelName(options.labelName);
await this.labelService.updateViewerLabel({
labelId: options.labelId,
labelName: options.labelName,
});
if (format === 'json') {
this.displayData({ success: true }, 'json');
}
else {
console.log('标签更新成功');
}
}, 'platformLabel.updateLabel');
}
async deleteLabel(options) {
return this.executeWithErrorHandling(async () => {
const format = this.validateOutputFormat(options.output);
this.validateLabelId(options.labelId);
await this.labelService.deleteViewerLabel({
labelId: options.labelId,
});
if (format === 'json') {
this.displayData({ success: true }, 'json');
}
else {
console.log('标签删除成功');
}
}, 'platformLabel.deleteLabel');
}
validateOutputFormat(output) {
if (!output) {
return 'table';
}
if (output !== 'table' && output !== 'json') {
throw new errors_1.PolyVValidationError('output 格式必须是 table 或 json', 'output', output, 'validation_failed');
}
return output;
}
validateLabelName(labelName) {
if (!labelName || typeof labelName !== 'string' || labelName.trim().length === 0) {
throw new errors_1.PolyVValidationError('labelName 不能为空', 'labelName', labelName, 'validation_failed');
}
}
validateLabelId(labelId) {
if (labelId === undefined || labelId === null || labelId <= 0 || !Number.isInteger(labelId)) {
throw new errors_1.PolyVValidationError('labelId 必须是正整数', 'labelId', labelId, 'validation_failed');
}
}
displayLabelsTable(labels) {
if (!labels || labels.length === 0) {
console.log('暂无标签数据');
return;
}
const tableData = labels.map((label) => ({
'标签ID': label.labelId,
'标签名称': label.labelName,
'创建时间': label.createdTime || '-',
}));
this.displayAsTable(tableData);
}
displayLabelInfo(label) {
const tableData = {
'标签ID': label.labelId,
'标签名称': label.labelName,
'创建时间': label.createdTime || '-',
};
this.displayAsTable(tableData);
}
}
exports.PlatformLabelHandler = PlatformLabelHandler;
//# sourceMappingURL=platform-label.handler.js.map