hosts.d.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { InternalConfig } from './base';
  2. export declare class Host {
  3. host: string;
  4. protocol: InternalConfig['upprotocol'];
  5. constructor(host: string, protocol: InternalConfig['upprotocol']);
  6. /**
  7. * @description 当前 host 是否为冻结状态
  8. */
  9. isFrozen(): boolean;
  10. /**
  11. * @param {number} time 单位秒,默认 20s
  12. * @description 冻结该 host 对象,该 host 将在指定时间内不可用
  13. */
  14. freeze(time?: number): void;
  15. /**
  16. * @description 解冻该 host
  17. */
  18. unfreeze(): void;
  19. /**
  20. * @description 获取当前 host 的完整 url
  21. */
  22. getUrl(): string;
  23. /**
  24. * @description 获取解冻时间
  25. */
  26. getUnfreezeTime(): number | undefined;
  27. }
  28. export declare class HostPool {
  29. private initHosts;
  30. /**
  31. * @description 缓存的 host 表,以 bucket 和 accessKey 作为 key
  32. */
  33. private cachedHostsMap;
  34. /**
  35. * @param {string[]} initHosts
  36. * @description 如果在构造时传入 initHosts,则该 host 池始终使用传入的 initHosts 做为可用的数据
  37. */
  38. constructor(initHosts?: string[]);
  39. /**
  40. * @param {string} accessKey
  41. * @param {string} bucketName
  42. * @param {string[]} hosts
  43. * @param {InternalConfig['upprotocol']} protocol
  44. * @returns {void}
  45. * @description 注册可用 host
  46. */
  47. private register;
  48. /**
  49. * @param {string} accessKey
  50. * @param {string} bucketName
  51. * @param {InternalConfig['upprotocol']} protocol
  52. * @returns {Promise<void>}
  53. * @description 刷新最新的 host 数据,如果用户在构造时该类时传入了 host 或者已经存在缓存则不会发起请求
  54. */
  55. private refresh;
  56. /**
  57. * @param {string} accessKey
  58. * @param {string} bucketName
  59. * @param {InternalConfig['upprotocol']} protocol
  60. * @returns {Promise<Host | null>}
  61. * @description 获取一个可用的上传 Host,排除已冻结的
  62. */
  63. getUp(accessKey: string, bucketName: string, protocol: InternalConfig['upprotocol']): Promise<Host | null>;
  64. }