租房小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.4 KiB

3 months ago
  1. /* eslint-disable object-curly-newline */
  2. const utility = require('utility');
  3. const { obj2xml } = require('../utils/obj2xml');
  4. const proto = exports;
  5. proto.deleteMulti = async function deleteMulti(names, options = {}) {
  6. const objects = [];
  7. if (!names || !names.length) {
  8. throw new Error('names is required');
  9. }
  10. for (let i = 0; i < names.length; i++) {
  11. const object = {};
  12. if (typeof names[i] === 'string') {
  13. object.Key = utility.escape(this._objectName(names[i]));
  14. } else {
  15. const { key, versionId } = names[i];
  16. object.Key = utility.escape(this._objectName(key));
  17. object.VersionId = versionId;
  18. }
  19. objects.push(object);
  20. }
  21. const paramXMLObj = {
  22. Delete: {
  23. Quiet: !!options.quiet,
  24. Object: objects
  25. }
  26. };
  27. const paramXML = obj2xml(paramXMLObj, {
  28. headers: true
  29. });
  30. options.subres = Object.assign({ delete: '' }, options.subres);
  31. if (options.versionId) {
  32. options.subres.versionId = options.versionId;
  33. }
  34. const params = this._objectRequestParams('POST', '', options);
  35. params.mime = 'xml';
  36. params.content = paramXML;
  37. params.xmlResponse = true;
  38. params.successStatuses = [200];
  39. const result = await this.request(params);
  40. const r = result.data;
  41. let deleted = (r && r.Deleted) || null;
  42. if (deleted) {
  43. if (!Array.isArray(deleted)) {
  44. deleted = [deleted];
  45. }
  46. }
  47. return {
  48. res: result.res,
  49. deleted: deleted || []
  50. };
  51. };