text-moderation.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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/34502
  21. * @param {object} params - 参数包装对象
  22. * @param {string} params.content - 需要识别的文本内容
  23. * @return {Promise<object>} 识别结果
  24. */
  25. async function textModeration({ content }) {
  26. if (!content) {
  27. throw new Error('文本内容不能为空');
  28. }
  29. // 调用腾讯云查询接口
  30. const { Data } = await request('TextModeration', {
  31. Content: Buffer.from(content).toString('base64')
  32. });
  33. return Data;
  34. }
  35. module.exports = textModeration;