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

51 lines
1.3 KiB

3 months ago
  1. import copy from 'copy-to';
  2. import urlutil from 'url';
  3. import merge from 'merge-descriptors';
  4. import is from 'is-type-of';
  5. import { isIP } from '../utils/isIP';
  6. import { checkConfigValid } from '../utils/checkConfigValid';
  7. export function getReqUrl(this: any, params) {
  8. const ep: any = {};
  9. const isCname = this.options.cname;
  10. checkConfigValid(this.options.endpoint, 'endpoint');
  11. copy(this.options.endpoint, false).to(ep);
  12. if (params.bucket && !isCname && !isIP(ep.hostname) && !this.options.sldEnable) {
  13. ep.host = `${params.bucket}.${ep.host}`;
  14. }
  15. let resourcePath = '/';
  16. if (params.bucket && this.options.sldEnable) {
  17. resourcePath += `${params.bucket}/`;
  18. }
  19. if (params.object) {
  20. // Preserve '/' in result url
  21. resourcePath += this._escape(params.object).replace(/\+/g, '%2B');
  22. }
  23. ep.pathname = resourcePath;
  24. const query = {};
  25. if (params.query) {
  26. merge(query, params.query);
  27. }
  28. if (params.subres) {
  29. let subresAsQuery = {};
  30. if ((is as any).string(params.subres)) {
  31. subresAsQuery[params.subres] = '';
  32. } else if (is.array(params.subres)) {
  33. params.subres.forEach(k => {
  34. subresAsQuery[k] = '';
  35. });
  36. } else {
  37. subresAsQuery = params.subres;
  38. }
  39. merge(query, subresAsQuery);
  40. }
  41. ep.query = query;
  42. return urlutil.format(ep);
  43. }