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

21 lines
665 B

3 months ago
  1. const { isIP } = require('../utils/isIP');
  2. const proto = exports;
  3. /**
  4. * Get Object url by name
  5. * @param {String} name - object name
  6. * @param {String} [baseUrl] - If provide `baseUrl`,
  7. * will use `baseUrl` instead the default `endpoint`.
  8. * @return {String} object url
  9. */
  10. proto.getObjectUrl = function getObjectUrl(name, baseUrl) {
  11. if (isIP(this.options.endpoint.hostname)) {
  12. throw new Error('can not get the object URL when endpoint is IP');
  13. }
  14. if (!baseUrl) {
  15. baseUrl = this.options.endpoint.format();
  16. } else if (baseUrl[baseUrl.length - 1] !== '/') {
  17. baseUrl += '/';
  18. }
  19. return baseUrl + this._escape(this._objectName(name));
  20. };