postAsyncFetch.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 { host = '', contentMD5 = '', callback = '', storageClass = '', ignoreSameKey = true } = options;
  18. const paramXMLObj = {
  19. AsyncFetchTaskConfiguration: {
  20. Url: url,
  21. Object: object,
  22. Host: host,
  23. ContentMD5: contentMD5,
  24. Callback: callback,
  25. StorageClass: storageClass,
  26. IgnoreSameKey: ignoreSameKey
  27. }
  28. };
  29. const params = this._objectRequestParams('POST', '', options);
  30. params.mime = 'xml';
  31. params.xmlResponse = true;
  32. params.successStatuses = [200];
  33. params.content = obj2xml(paramXMLObj);
  34. const result = await this.request(params);
  35. return {
  36. res: result.res,
  37. status: result.status,
  38. taskId: result.data.TaskId
  39. };
  40. }