QNConfiguration.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. //
  2. // QNConfiguration.h
  3. // QiniuSDK
  4. //
  5. // Created by bailong on 15/5/21.
  6. // Copyright (c) 2015年 Qiniu. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import "QNRecorderDelegate.h"
  10. /**
  11. * 断点上传时的分块大小
  12. */
  13. extern const UInt32 kQNBlockSize;
  14. /**
  15. * 转换为用户需要的url
  16. *
  17. * @param url 上传url
  18. *
  19. * @return 根据上传url算出代理url
  20. */
  21. typedef NSString * (^QNUrlConvert)(NSString *url);
  22. @class QNConfigurationBuilder;
  23. @class QNZone;
  24. /**
  25. * Builder block
  26. *
  27. * @param builder builder实例
  28. */
  29. typedef void (^QNConfigurationBuilderBlock)(QNConfigurationBuilder *builder);
  30. @interface QNConfiguration : NSObject
  31. /**
  32. * 存储区域
  33. */
  34. @property (copy, nonatomic, readonly) QNZone *zone;
  35. /**
  36. * 断点上传时的分片大小
  37. */
  38. @property (readonly) UInt32 chunkSize;
  39. /**
  40. * 如果大于此值就使用断点上传,否则使用form上传
  41. */
  42. @property (readonly) UInt32 putThreshold;
  43. /**
  44. * 上传失败的重试次数
  45. */
  46. @property (readonly) UInt32 retryMax;
  47. /**
  48. * 超时时间 单位 秒
  49. */
  50. @property (readonly) UInt32 timeoutInterval;
  51. /**
  52. * 是否使用 https,默认为 YES
  53. */
  54. @property (nonatomic, assign) BOOL useHttps;
  55. @property (nonatomic, readonly) id<QNRecorderDelegate> recorder;
  56. @property (nonatomic, readonly) QNRecorderKeyGenerator recorderKeyGen;
  57. @property (nonatomic, readonly) NSDictionary *proxy;
  58. @property (nonatomic, readonly) QNUrlConvert converter;
  59. @property (readonly) BOOL disableATS;
  60. + (instancetype)build:(QNConfigurationBuilderBlock)block;
  61. @end
  62. typedef void (^QNPrequeryReturn)(int code);
  63. @class QNUpToken;
  64. @class QNZoneInfo;
  65. @interface QNZone : NSObject
  66. @property (nonatomic, strong) NSArray<NSString *> *upDomainList;
  67. @property (nonatomic, strong) QNZoneInfo *zoneInfo;
  68. /**
  69. * 默认上传服务器地址列表
  70. */
  71. - (void)preQuery:(QNUpToken *)token
  72. on:(QNPrequeryReturn)ret;
  73. - (NSString *)up:(QNUpToken *)token
  74. isHttps:(BOOL)isHttps
  75. frozenDomain:(NSString *)frozenDomain;
  76. @end
  77. @interface QNZoneInfo : NSObject
  78. @property (readonly, nonatomic) long ttl;
  79. @property (readonly, nonatomic) NSMutableArray<NSString *> *upDomainsList;
  80. @property (readonly, nonatomic) NSMutableDictionary *upDomainsDic;
  81. - (instancetype)init:(long)ttl
  82. upDomainsList:(NSMutableArray<NSString *> *)upDomainsList
  83. upDomainsDic:(NSMutableDictionary *)upDomainsDic;
  84. - (QNZoneInfo *)buildInfoFromJson:(NSDictionary *)resp;
  85. @end
  86. @interface QNFixedZone : QNZone
  87. /**
  88. * zone 0 华东
  89. *
  90. * @return 实例
  91. */
  92. + (instancetype)zone0;
  93. /**
  94. * zone 1 华北
  95. *
  96. * @return 实例
  97. */
  98. + (instancetype)zone1;
  99. /**
  100. * zone 2 华南
  101. *
  102. * @return 实例
  103. */
  104. + (instancetype)zone2;
  105. /**
  106. * zone Na0 北美
  107. *
  108. * @return 实例
  109. */
  110. + (instancetype)zoneNa0;
  111. /**
  112. * zone As0 新加坡
  113. *
  114. * @return 实例
  115. */
  116. + (instancetype)zoneAs0;
  117. /**
  118. * Zone初始化方法
  119. *
  120. * @param upList 默认上传服务器地址列表
  121. *
  122. * @return Zone实例
  123. */
  124. - (instancetype)initWithupDomainList:(NSArray<NSString *> *)upList;
  125. /**
  126. * Zone初始化方法
  127. *
  128. * @param upList 默认上传服务器地址列表
  129. *
  130. * @return Zone实例
  131. */
  132. + (instancetype)createWithHost:(NSArray<NSString *> *)upList;
  133. - (void)preQuery:(QNUpToken *)token
  134. on:(QNPrequeryReturn)ret;
  135. - (NSString *)up:(QNUpToken *)token
  136. isHttps:(BOOL)isHttps
  137. frozenDomain:(NSString *)frozenDomain;
  138. @end
  139. @interface QNAutoZone : QNZone
  140. - (NSString *)up:(QNUpToken *)token
  141. isHttps:(BOOL)isHttps
  142. frozenDomain:(NSString *)frozenDomain;
  143. @end
  144. @interface QNConfigurationBuilder : NSObject
  145. /**
  146. * 默认上传服务器地址
  147. */
  148. @property (nonatomic, strong) QNZone *zone;
  149. /**
  150. * 断点上传时的分片大小
  151. */
  152. @property (assign) UInt32 chunkSize;
  153. /**
  154. * 如果大于此值就使用断点上传,否则使用form上传
  155. */
  156. @property (assign) UInt32 putThreshold;
  157. /**
  158. * 上传失败的重试次数
  159. */
  160. @property (assign) UInt32 retryMax;
  161. /**
  162. * 超时时间 单位 秒
  163. */
  164. @property (assign) UInt32 timeoutInterval;
  165. /**
  166. * 是否使用 https,默认为 YES
  167. */
  168. @property (nonatomic, assign) BOOL useHttps;
  169. @property (nonatomic, strong) id<QNRecorderDelegate> recorder;
  170. @property (nonatomic, strong) QNRecorderKeyGenerator recorderKeyGen;
  171. @property (nonatomic, strong) NSDictionary *proxy;
  172. @property (nonatomic, strong) QNUrlConvert converter;
  173. @property (assign) BOOL disableATS;
  174. @end