cos.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. 'use strict';
  2. var util = require('./util');
  3. var event = require('./event');
  4. var task = require('./task');
  5. var base = require('./base');
  6. var advance = require('./advance');
  7. var defaultOptions = {
  8. AppId: '', // AppId 已废弃,请拼接到 Bucket 后传入,例如:test-1250000000
  9. SecretId: '',
  10. SecretKey: '',
  11. SecurityToken: '', // 使用临时密钥需要注意自行刷新 Token
  12. ChunkRetryTimes: 2,
  13. FileParallelLimit: 3,
  14. ChunkParallelLimit: 3,
  15. ChunkSize: 1024 * 1024,
  16. SliceSize: 1024 * 1024,
  17. CopyChunkParallelLimit: 20,
  18. CopyChunkSize: 1024 * 1024 * 10,
  19. CopySliceSize: 1024 * 1024 * 10,
  20. MaxPartNumber: 10000,
  21. ProgressInterval: 1000,
  22. Domain: '',
  23. ServiceDomain: '',
  24. Protocol: '',
  25. CompatibilityMode: false,
  26. ForcePathStyle: false,
  27. UseRawKey: false,
  28. Timeout: 0, // 单位毫秒,0 代表不设置超时时间
  29. CorrectClockSkew: true,
  30. SystemClockOffset: 0, // 单位毫秒,ms
  31. UploadCheckContentMd5: false,
  32. UploadQueueSize: 10000,
  33. UploadAddMetaMd5: false,
  34. UploadIdCacheLimit: 50,
  35. UseAccelerate: false,
  36. };
  37. // 对外暴露的类
  38. var COS = function (options) {
  39. this.options = util.extend(util.clone(defaultOptions), options || {});
  40. this.options.FileParallelLimit = Math.max(1, this.options.FileParallelLimit);
  41. this.options.ChunkParallelLimit = Math.max(1, this.options.ChunkParallelLimit);
  42. this.options.ChunkRetryTimes = Math.max(0, this.options.ChunkRetryTimes);
  43. this.options.ChunkSize = Math.max(1024 * 1024, this.options.ChunkSize);
  44. this.options.CopyChunkParallelLimit = Math.max(1, this.options.CopyChunkParallelLimit);
  45. this.options.CopyChunkSize = Math.max(1024 * 1024, this.options.CopyChunkSize);
  46. this.options.CopySliceSize = Math.max(0, this.options.CopySliceSize);
  47. this.options.MaxPartNumber = Math.max(1024, Math.min(10000, this.options.MaxPartNumber));
  48. this.options.Timeout = Math.max(0, this.options.Timeout);
  49. if (this.options.AppId) {
  50. console.warn('warning: AppId has been deprecated, Please put it at the end of parameter Bucket(E.g: "test-1250000000").');
  51. }
  52. if (util.isNode()) {
  53. console.warn('warning: cos-js-sdk-v5 不支持 nodejs 环境使用,请改用 cos-nodejs-sdk-v5,参考文档: https://cloud.tencent.com/document/product/436/8629');
  54. console.warn('warning: cos-js-sdk-v5 does not support nodejs environment. Please use cos-nodejs-sdk-v5 instead. See: https://cloud.tencent.com/document/product/436/8629');
  55. }
  56. event.init(this);
  57. task.init(this);
  58. };
  59. base.init(COS, task);
  60. advance.init(COS, task);
  61. COS.util = {
  62. md5: util.md5,
  63. xml2json: util.xml2json,
  64. json2xml: util.json2xml,
  65. };
  66. COS.getAuthorization = util.getAuth;
  67. COS.version = '1.3.1';
  68. module.exports = COS;