head.js 832 B

12345678910111213141516171819202122232425262728293031323334353637
  1. const proto = exports;
  2. /**
  3. * head
  4. * @param {String} name - object name
  5. * @param {Object} options
  6. * @param {{res}}
  7. */
  8. proto.head = async function head(name, options = {}) {
  9. options.subres = Object.assign({}, options.subres);
  10. if (options.versionId) {
  11. options.subres.versionId = options.versionId;
  12. }
  13. const params = this._objectRequestParams('HEAD', name, options);
  14. params.successStatuses = [200, 304];
  15. const result = await this.request(params);
  16. const data = {
  17. meta: null,
  18. res: result.res,
  19. status: result.status
  20. };
  21. if (result.status === 200) {
  22. Object.keys(result.headers).forEach((k) => {
  23. if (k.indexOf('x-oss-meta-') === 0) {
  24. if (!data.meta) {
  25. data.meta = {};
  26. }
  27. data.meta[k.substring(11)] = result.headers[k];
  28. }
  29. });
  30. }
  31. return data;
  32. };