租房小程序前端代码
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.

41 lines
1.0 KiB

3 months ago
  1. const { checkEnv } = require('../utils/checkEnv');
  2. const proto = exports;
  3. /**
  4. * head
  5. * @param {String} name - object name
  6. * @param {Object} options
  7. * @param {{res}}
  8. */
  9. proto.head = async function head(name, options = {}) {
  10. checkEnv(
  11. 'Because HeadObject has gzip enabled, head cannot get the file size correctly. If you need to get the file size, please use getObjectMeta'
  12. );
  13. options.subres = Object.assign({}, options.subres);
  14. if (options.versionId) {
  15. options.subres.versionId = options.versionId;
  16. }
  17. const params = this._objectRequestParams('HEAD', name, options);
  18. params.successStatuses = [200, 304];
  19. const result = await this.request(params);
  20. const data = {
  21. meta: null,
  22. res: result.res,
  23. status: result.status
  24. };
  25. if (result.status === 200) {
  26. Object.keys(result.headers).forEach(k => {
  27. if (k.indexOf('x-oss-meta-') === 0) {
  28. if (!data.meta) {
  29. data.meta = {};
  30. }
  31. data.meta[k.substring(11)] = result.headers[k];
  32. }
  33. });
  34. }
  35. return data;
  36. };