text-sample.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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/35618
  21. * @param {object} params - 参数包装对象
  22. * @param {int} params.limit - 数量限制
  23. * @param {int} params.offset - 偏移量
  24. * @return {Promise<object>} 文本样本的信息
  25. */
  26. async function listTextSample({ limit = 20, offset = 0 }) {
  27. // 调用腾讯云接口
  28. const { TextSampleSet, TotalCount } = await request('DescribeTextSample', {
  29. Limit: limit,
  30. Offset: offset
  31. });
  32. return {
  33. TextSampleSet,
  34. TotalCount
  35. };
  36. }
  37. /**
  38. * 新增文本样本
  39. * 更多信息请访问 https://cloud.tencent.com/document/product/669/35620
  40. * @param {object} params - 参数包装对象
  41. * @param {string[]} params.contents - 关键词数组
  42. * @param {string} params.evilType - 恶意类型
  43. * @param {string} params.label - 样本类型 1:黑库 2:白库
  44. * @return {Promise<int>} 任务状态
  45. */
  46. async function createTextSample({ contents, evilType, label }) {
  47. if (!contents || !contents.length || !evilType || !label) {
  48. throw new Error('关键词/恶意类型/样本类型不能为空');
  49. }
  50. // 调用腾讯云接口
  51. const { Progress } = await request('CreateTextSample', {
  52. Contents: contents,
  53. EvilType: evilType,
  54. Label: label
  55. });
  56. return Progress;
  57. }
  58. /**
  59. * 删除文本样本
  60. * 更多信息请访问 https://cloud.tencent.com/document/product/669/35619
  61. * @param {object} params - 参数包装对象
  62. * @param {string[]} params.ids - 唯一标识数组
  63. * @return {Promise<int>} 任务状态
  64. */
  65. async function deleteTextSample({ ids }) {
  66. if (!ids || !ids.length) {
  67. throw new Error('唯一标识不能为空');
  68. }
  69. // 调用腾讯云接口
  70. const { Progress } = await request('DeleteTextSample', {
  71. Ids: ids
  72. });
  73. return Progress;
  74. }
  75. module.exports = {
  76. listTextSample,
  77. createTextSample,
  78. deleteTextSample
  79. };