polyv-live-cli
Version:
CLI tool for managing PolyV live streaming services.
179 lines • 8.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DocumentServiceSdk = void 0;
const errors_1 = require("../utils/errors");
const sdk_1 = require("../sdk");
const VALID_STATUSES = ['normal', 'waitUpload', 'failUpload', 'waitConvert', 'failConvert'];
const VALID_CONVERT_TYPES = ['common', 'animate'];
const VALID_DOC_TYPES = ['old', 'new'];
class DocumentServiceSdk {
constructor(authConfig, serviceConfig) {
this.authConfig = authConfig;
this.config = serviceConfig;
}
async getDocumentList(options) {
this.validateListOptions(options);
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
const params = {
channelId: options.channelId,
isShowUrl: 'Y',
};
if (options.status !== undefined) {
params.status = options.status;
}
if (options.page !== undefined) {
params.page = options.page;
}
if (options.pageSize !== undefined) {
params.limit = options.pageSize;
}
const result = await client.channel.getDocList(params);
return {
contents: (result.contents || []).map((item) => ({
fileId: item.fileId,
fileName: item.fileName,
fileUrl: item.fileUrl,
fileType: item.fileType,
totalPage: item.totalPage,
channelId: item.channelId,
status: item.status,
createTime: item.createTime,
convertType: item.convertType,
type: item.type,
})),
pageNumber: result.page || 1,
pageSize: result.pageSize || result.limit || 10,
totalItems: result.total || 0,
totalPages: Math.ceil((result.total || 0) / (result.pageSize || result.limit || 10)),
};
}
async uploadDocument(channelId, options) {
this.validateUploadParams(channelId, options);
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
const params = { url: options.url };
if (options.type !== undefined) {
params.type = options.type;
}
if (options.docName !== undefined) {
params.docName = options.docName;
}
if (options.callbackUrl !== undefined) {
params.callbackUrl = options.callbackUrl;
}
const result = await client.channel.uploadDoc(channelId, params);
return {
fileId: result.fileId,
status: result.status,
type: result.type,
};
}
async deleteDocument(channelId, fileId, type) {
this.validateDeleteParams(channelId, fileId, type);
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
const result = await client.channel.deleteDocument(channelId, fileId, type);
return result;
}
async getDocumentStatus(channelId, fileId) {
this.validateStatusParams(channelId, fileId);
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
const result = await client.channel.getDocConvertStatus(channelId, fileId);
return result.map((item) => ({
fileId: item.fileId,
convertStatus: item.convertStatus,
type: item.type,
totalPage: item.totalPage,
imageCount: item.imageCount,
htmlUrl: item.htmlUrl,
}));
}
async updateTeacherDocRelation(teacherId, fileIds, operation) {
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
return client.channel.updateTeacherDocRelation(teacherId, fileIds, operation);
}
async getChannelMultimediaResourceList(channelId, options) {
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
return client.channel.getChannelMultimediaResourceList(channelId, options);
}
async getChannelMultimediaResourceDetail(channelId, options) {
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
return client.channel.getChannelMultimediaResourceDetail(channelId, options);
}
async linkChannelMultimediaResource(channelId, vids) {
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
return client.channel.linkChannelMultimediaResource(channelId, vids);
}
async unlinkChannelMultimediaResource(channelId, vids) {
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
return client.channel.unlinkChannelMultimediaResource(channelId, vids);
}
async getUserMultimediaResourceDetail(vids) {
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
return client.channel.getUserMultimediaResourceDetail(vids);
}
async deleteUserMultimediaResource(vids) {
const client = (0, sdk_1.createSdkClient)(this.authConfig, this.config.baseUrl);
return client.channel.deleteUserMultimediaResource(vids);
}
validateListOptions(options) {
const errors = [];
if (!options.channelId || typeof options.channelId !== 'string' || options.channelId.trim().length === 0) {
errors.push('channelId is required and must be a non-empty string');
}
if (options.page !== undefined && (!Number.isInteger(options.page) || options.page < 1)) {
errors.push('page must be a positive integer');
}
if (options.pageSize !== undefined && (!Number.isInteger(options.pageSize) || options.pageSize < 1)) {
errors.push('pageSize must be a positive integer');
}
if (options.status !== undefined && !VALID_STATUSES.includes(options.status)) {
errors.push(`status must be one of: ${VALID_STATUSES.join(', ')}`);
}
if (errors.length > 0) {
throw new errors_1.PolyVValidationError(`Document list options validation failed: ${errors.join(', ')}`, 'options', options, 'validation_failed');
}
}
validateUploadParams(channelId, options) {
const errors = [];
if (!channelId || typeof channelId !== 'string' || channelId.trim().length === 0) {
errors.push('channelId is required and must be a non-empty string');
}
if (!options.url || typeof options.url !== 'string' || options.url.trim().length === 0) {
errors.push('url is required and must be a non-empty string');
}
if (options.type !== undefined && !VALID_CONVERT_TYPES.includes(options.type)) {
errors.push(`type must be one of: ${VALID_CONVERT_TYPES.join(', ')}`);
}
if (errors.length > 0) {
throw new errors_1.PolyVValidationError(`Document upload parameters validation failed: ${errors.join(', ')}`, 'params', { channelId, ...options }, 'validation_failed');
}
}
validateDeleteParams(channelId, fileId, type) {
const errors = [];
if (!channelId || typeof channelId !== 'string' || channelId.trim().length === 0) {
errors.push('channelId is required and must be a non-empty string');
}
if (!fileId || typeof fileId !== 'string' || fileId.trim().length === 0) {
errors.push('fileId is required and must be a non-empty string');
}
if (!VALID_DOC_TYPES.includes(type)) {
errors.push(`type must be one of: ${VALID_DOC_TYPES.join(', ')}`);
}
if (errors.length > 0) {
throw new errors_1.PolyVValidationError(`Document delete parameters validation failed: ${errors.join(', ')}`, 'params', { channelId, fileId, type }, 'validation_failed');
}
}
validateStatusParams(channelId, fileId) {
const errors = [];
if (!channelId || typeof channelId !== 'string' || channelId.trim().length === 0) {
errors.push('channelId is required and must be a non-empty string');
}
if (!fileId || typeof fileId !== 'string' || fileId.trim().length === 0) {
errors.push('fileId is required and must be a non-empty string');
}
if (errors.length > 0) {
throw new errors_1.PolyVValidationError(`Document status parameters validation failed: ${errors.join(', ')}`, 'params', { channelId, fileId }, 'validation_failed');
}
}
}
exports.DocumentServiceSdk = DocumentServiceSdk;
//# sourceMappingURL=document.service.sdk.js.map