image-sample.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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/37187
  21. * @param {object} params - 参数包装对象
  22. * @param {int} params.limit - 数量限制
  23. * @param {int} params.offset - 偏移量
  24. * @return {Promise<object>} 图片样本的信息
  25. */
  26. async function listImageSample({ limit = 20, offset = 0 }) {
  27. // 调用腾讯云接口
  28. const { FileSampleSet, TotalCount } = await request('DescribeFileSample', {
  29. Limit: limit,
  30. Offset: offset
  31. });
  32. return {
  33. FileSampleSet,
  34. TotalCount
  35. };
  36. }
  37. /**
  38. * 新增图片样本
  39. * 更多信息请访问 https://cloud.tencent.com/document/product/669/37189
  40. * @param {object} params - 参数包装对象
  41. * @param {string} params.fileName - 图片文件名称
  42. * @param {string} params.fileUrl - 图片文件路径
  43. * @param {string} params.fileMd5 - 图片文件MD5
  44. * @param {string} params.evilType - 恶意类型
  45. * @param {string} params.label - 样本类型 1:黑库 2:白库
  46. * @return {Promise<int>} 任务状态
  47. */
  48. async function createImageSample({ fileName, fileUrl, fileMd5, evilType, label }) {
  49. if (!fileName || !fileUrl || !fileMd5 || !evilType || !label) {
  50. throw new Error('fileName/fileUrl/fileMd5/evilType/label不能为空');
  51. }
  52. // 调用腾讯云接口
  53. const { Progress } = await request('CreateFileSample', {
  54. Contents: [
  55. {
  56. FileName: fileName,
  57. FileUrl: fileUrl,
  58. FileMd5: fileMd5
  59. }
  60. ],
  61. EvilType: evilType,
  62. Label: label,
  63. FileType: 'image'
  64. });
  65. return Progress;
  66. }
  67. /**
  68. * 删除图片样本
  69. * 更多信息请访问 https://cloud.tencent.com/document/product/669/37188
  70. * @param {object} params - 参数包装对象
  71. * @param {string[]} params.ids - 唯一标识数组
  72. * @return {Promise<int>} 任务状态
  73. */
  74. async function deleteImageSample({ ids }) {
  75. if (!ids || !ids.length) {
  76. throw new Error('ids不能为空');
  77. }
  78. // 调用腾讯云接口
  79. const { Progress } = await request('DeleteFileSample', {
  80. Ids: ids
  81. });
  82. return Progress;
  83. }
  84. module.exports = {
  85. listImageSample,
  86. createImageSample,
  87. deleteImageSample
  88. };