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

52 lines
1.5 KiB

3 months ago
  1. const urlutil = require('url');
  2. const utility = require('utility');
  3. const copy = require('copy-to');
  4. const signHelper = require('../../common/signUtils');
  5. const { isIP } = require('../utils/isIP');
  6. const proto = exports;
  7. /**
  8. * signatureUrl
  9. * @deprecated will be deprecated in 7.x
  10. * @param {String} name object name
  11. * @param {Object} options options
  12. * @param {boolean} [strictObjectNameValidation=true] the flag of verifying object name strictly
  13. */
  14. proto.signatureUrl = function signatureUrl(name, options, strictObjectNameValidation = true) {
  15. if (isIP(this.options.endpoint.hostname)) {
  16. throw new Error('can not get the object URL when endpoint is IP');
  17. }
  18. if (strictObjectNameValidation && /^\?/.test(name)) {
  19. throw new Error(`Invalid object name ${name}`);
  20. }
  21. options = options || {};
  22. name = this._objectName(name);
  23. options.method = options.method || 'GET';
  24. const expires = utility.timestamp() + (options.expires || 1800);
  25. const params = {
  26. bucket: this.options.bucket,
  27. object: name
  28. };
  29. const resource = this._getResource(params);
  30. if (this.options.stsToken) {
  31. options['security-token'] = this.options.stsToken;
  32. }
  33. const signRes = signHelper._signatureForURL(this.options.accessKeySecret, options, resource, expires);
  34. const url = urlutil.parse(this._getReqUrl(params));
  35. url.query = {
  36. OSSAccessKeyId: this.options.accessKeyId,
  37. Expires: expires,
  38. Signature: signRes.Signature
  39. };
  40. copy(signRes.subResource).to(url.query);
  41. return url.format();
  42. };