image-moderation.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. /**
  19. * 图片内容检测
  20. * 更多信息请访问 https://cloud.tencent.com/document/product/669/34503
  21. * @param {object} params - 参数包装对象
  22. * @param {string} params.content - 图片文件内容Base64或url地址
  23. * @return {Promise<object>} 识别结果
  24. */
  25. async function imageModeration({ content }) {
  26. if (!content) {
  27. throw new Error('图片内容不能为空');
  28. }
  29. const isUrl = /^https?:\/\//.test(content);
  30. // 调用腾讯云查询接口
  31. const { Data } = await request('ImageModeration', {
  32. FileContent: isUrl ? undefined : content,
  33. FileUrl: isUrl ? content : undefined
  34. });
  35. return Data;
  36. }
  37. module.exports = imageModeration;