postAsyncFetch.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { obj2xml } from '../utils/obj2xml';
  2. /*
  3. * postAsyncFetch
  4. * @param {String} name the object key
  5. * @param {String} url
  6. * @param {Object} options
  7. * {String} options.host
  8. * {String} options.contentMD5
  9. * {String} options.callback
  10. * {String} options.storageClass Standard/IA/Archive
  11. * {Boolean} options.ignoreSameKey default value true
  12. */
  13. export async function postAsyncFetch(this: any, object, url, options: any = {}): Promise<object> {
  14. options.subres = Object.assign({ asyncFetch: '' }, options.subres);
  15. options.headers = options.headers || {};
  16. object = this._objectName(object);
  17. const {
  18. host = '',
  19. contentMD5 = '',
  20. callback = '',
  21. storageClass = '',
  22. ignoreSameKey = true
  23. } = options;
  24. const paramXMLObj = {
  25. AsyncFetchTaskConfiguration: {
  26. Url: url,
  27. Object: object,
  28. Host: host,
  29. ContentMD5: contentMD5,
  30. Callback: callback,
  31. StorageClass: storageClass,
  32. IgnoreSameKey: ignoreSameKey
  33. }
  34. };
  35. const params = this._objectRequestParams('POST', '', options);
  36. params.mime = 'xml';
  37. params.xmlResponse = true;
  38. params.successStatuses = [200];
  39. params.content = obj2xml(paramXMLObj);
  40. const result = await this.request(params);
  41. return {
  42. res: result.res,
  43. status: result.status,
  44. taskId: result.data.TaskId
  45. };
  46. }