cos.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. SecretId: '',
  9. SecretKey: '',
  10. XCosSecurityToken: '', // 使用临时密钥需要注意自行刷新 Token
  11. ChunkRetryTimes: 2,
  12. FileParallelLimit: 3,
  13. ChunkParallelLimit: 3,
  14. ChunkSize: 1024 * 1024,
  15. SliceSize: 1024 * 1024,
  16. CopyChunkParallelLimit: 20,
  17. CopyChunkSize: 1024 * 1024 * 10,
  18. CopySliceSize: 1024 * 1024 * 10,
  19. MaxPartNumber: 10000,
  20. ProgressInterval: 1000,
  21. UploadQueueSize: 10000,
  22. Domain: '',
  23. ServiceDomain: '',
  24. Protocol: '',
  25. CompatibilityMode: false,
  26. ForcePathStyle: false,
  27. Timeout: 0, // 单位毫秒,0 代表不设置超时时间
  28. CorrectClockSkew: true,
  29. SystemClockOffset: 0, // 单位毫秒,ms
  30. UploadCheckContentMd5: false,
  31. UploadIdCacheLimit: 50,
  32. UseAccelerate: false,
  33. };
  34. // 对外暴露的类
  35. var COS = function (options) {
  36. this.options = util.extend(util.clone(defaultOptions), options || {});
  37. this.options.FileParallelLimit = Math.max(1, this.options.FileParallelLimit);
  38. this.options.ChunkParallelLimit = Math.max(1, this.options.ChunkParallelLimit);
  39. this.options.ChunkRetryTimes = Math.max(0, this.options.ChunkRetryTimes);
  40. this.options.ChunkSize = Math.max(1024 * 1024, this.options.ChunkSize);
  41. this.options.CopyChunkParallelLimit = Math.max(1, this.options.CopyChunkParallelLimit);
  42. this.options.CopyChunkSize = Math.max(1024 * 1024, this.options.CopyChunkSize);
  43. this.options.CopySliceSize = Math.max(0, this.options.CopySliceSize);
  44. this.options.MaxPartNumber = Math.max(1024, Math.min(10000, this.options.MaxPartNumber));
  45. this.options.Timeout = Math.max(0, this.options.Timeout);
  46. if (this.options.AppId) {
  47. console.warn('warning: AppId has been deprecated, Please put it at the end of parameter Bucket(E.g: "test-1250000000").');
  48. }
  49. if (this.options.SecretId && this.options.SecretId.indexOf(' ') > -1) {
  50. console.error('error: SecretId格式错误,请检查');
  51. console.error('error: SecretId format is incorrect. Please check');
  52. }
  53. if (this.options.SecretKey && this.options.SecretKey.indexOf(' ') > -1) {
  54. console.error('error: SecretKey格式错误,请检查');
  55. console.error('error: SecretKey format is incorrect. Please check');
  56. }
  57. event.init(this);
  58. task.init(this);
  59. };
  60. base.init(COS, task);
  61. advance.init(COS, task);
  62. COS.getAuthorization = util.getAuth;
  63. COS.version = '1.1.5';
  64. module.exports = COS;