other.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. const COS = require('../lib/cos-wx-sdk-v5');
  2. var wxfs = wx.getFileSystemManager();
  3. const config = require('../config');
  4. const { cos, requestCallback } = require('../tools');
  5. const otherDao = {
  6. '提交病毒检测任务 postVirusDetect': postVirusDetect,
  7. '查询病毒检测任务结果 getVirusDetectResult': getVirusDetectResult,
  8. '查询防盗链 describeRefer': describeRefer,
  9. '设置防盗链 setRefer': setRefer,
  10. };
  11. function postVirusDetect() {
  12. var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/virus/detect';
  13. var url = 'https://' + host;
  14. var body = COS.util.json2xml({
  15. Request: {
  16. Input: {
  17. Object: 'test/1.png', // 文件名,取值为文件在当前存储桶中的完整名称,与Url参数二选一
  18. // Url: 'http://examplebucket-1250000000.cos.ap-shanghai.myqcloud.com/virus.doc', // 病毒文件的链接地址,与Object参数二选一
  19. },
  20. Conf: {
  21. DetectType: 'Virus', // 检测的病毒类型,当前固定为:Virus
  22. // CallBack: 'http://callback.demo.com', // 任务回调的地址
  23. },
  24. },
  25. });
  26. cos.request(
  27. {
  28. Method: 'POST',
  29. Key: 'virus/detect',
  30. Url: url,
  31. Body: body,
  32. ContentType: 'application/xml',
  33. },
  34. function (err, data) {
  35. console.log(err || data);
  36. }
  37. );
  38. }
  39. function getVirusDetectResult() {
  40. var jobId = 'ss5a8d3065bd9011eda1445254009dadxx'; // 提交病毒检测任务后会返回当前任务的jobId
  41. var host = config.Bucket + '.ci.' + config.Region + '.myqcloud.com/virus/detect/' + jobId;
  42. var url = 'https://' + host;
  43. cos.request(
  44. {
  45. Method: 'GET',
  46. Key: 'virus/detect/' + jobId,
  47. Url: url,
  48. },
  49. function (err, data) {
  50. console.log(err || data);
  51. }
  52. );
  53. }
  54. function describeRefer() {
  55. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
  56. const host = config.Bucket + '.pic.' + config.Region + '.myqcloud.com/?hotlink';
  57. const url = 'https://' + host;
  58. cos.request(
  59. {
  60. Method: 'GET', // 固定值,必须
  61. Url: url, // 请求的url,必须
  62. },
  63. function (err, data) {
  64. if (err) {
  65. // 处理请求失败
  66. console.log(err);
  67. } else {
  68. // 处理请求成功
  69. console.log(data.Response);
  70. }
  71. }
  72. );
  73. }
  74. function setRefer() {
  75. // sdk引入以及初始化请参考:https://cloud.tencent.com/document/product/436/31953
  76. const host = config.Bucket + '.pic.' + config.Region + '.myqcloud.com/?hotlink';
  77. const url = 'https://' + host;
  78. const body = COS.util.json2xml({
  79. Hotlink: {
  80. Url: 'https://www.example.com', // 必须,域名地址
  81. Type: 'white', // 必须,防盗链类型,white 为白名单,black 为黑名单,off 为关闭。
  82. },
  83. });
  84. cos.request(
  85. {
  86. Method: 'PUT',
  87. Url: url,
  88. Body: body,
  89. },
  90. function (err, data) {
  91. console.log(err || data);
  92. }
  93. );
  94. }
  95. module.exports = otherDao;