get-media-info.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright (C) 2020 Tencent Cloud.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. 'use strict';
  17. const { request } = require('./utils');
  18. const getAntiTheftURL = require('./get-anti-theft-url.js');
  19. const { antiTheftKey } = require('./config');
  20. /**
  21. * 获取腾讯云云点播媒体详细信息
  22. * 更多信息请访问 https://cloud.tencent.com/document/api/266/31763
  23. * @param {object} params - 参数包装对象
  24. * @param {string[]} params.mediaId - 媒体ID
  25. * @return {Promise<object>} 媒体详细信息
  26. */
  27. async function getUploadSignature({ mediaId }) {
  28. if (!mediaId) {
  29. throw new Error('待查询媒体ID不能为空');
  30. }
  31. // 调用腾讯云查询接口
  32. const {
  33. MediaInfoSet: [mediaInfo]
  34. } = await request('DescribeMediaInfos', {
  35. FileIds: [mediaId]
  36. });
  37. // 如果有配置antiTheftKey则自动生成带签名的url
  38. if (mediaInfo && antiTheftKey) {
  39. mediaInfo.BasicInfo.AntiTheftUrl = getAntiTheftURL({
  40. mediaUrl: mediaInfo.BasicInfo.MediaUrl
  41. });
  42. }
  43. return mediaInfo;
  44. }
  45. module.exports = getUploadSignature;