QNUploadInfoCollector.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //
  2. // QNUploadInfoCollector.h
  3. // QiniuSDK
  4. //
  5. // Created by WorkSpace_Sun on 2020/4/15.
  6. // Copyright © 2020 Qiniu. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #define Collector [QNUploadInfoCollector sharedInstance]
  10. @class QNHttpResponseInfo;
  11. @class QNResponseInfo;
  12. // request types
  13. typedef enum : NSUInteger {
  14. QNRequestType_form,
  15. QNRequestType_mkblk,
  16. QNRequestType_bput,
  17. QNRequestType_mkfile,
  18. QNRequestType_put,
  19. QNRequestType_initParts,
  20. QNRequestType_uploadParts,
  21. QNRequestType_completeParts,
  22. QNRequestType_ucQuery,
  23. QNRequestType_httpdnsQuery
  24. } QNRequestType;
  25. typedef NSString QNCollectKey;
  26. // update key
  27. extern QNCollectKey *const CK_bucket;
  28. extern QNCollectKey *const CK_key;
  29. extern QNCollectKey *const CK_targetRegionId;
  30. extern QNCollectKey *const CK_currentRegionId;
  31. extern QNCollectKey *const CK_result;
  32. extern QNCollectKey *const CK_recoveredFrom;
  33. extern QNCollectKey *const CK_fileSize;
  34. extern QNCollectKey *const CK_blockApiVersion;
  35. // append key
  36. extern QNCollectKey *const CK_blockBytesSent;
  37. extern QNCollectKey *const CK_totalBytesSent;
  38. // Upload Result Type
  39. extern NSString *const upload_ok; // 上传成功
  40. extern NSString *const zero_size_file; // ⽂件⼤小错误
  41. extern NSString *const invalid_file; // 文件内容错误
  42. extern NSString *const invalid_args; // 调用参数出错
  43. extern NSString *const local_io_error; // 本地 I/O 错误
  44. /// Network Error Type
  45. extern NSString *const unknown_error; // 未知错误
  46. extern NSString *const network_error; // 未知网络错误
  47. extern NSString *const network_timeout; // 超时错误
  48. extern NSString *const unknown_host; // DNS 解析错误
  49. extern NSString *const cannot_connect_to_host; // 连接服务器器错误
  50. extern NSString *const transmission_error; // 传输错误
  51. extern NSString *const proxy_error; // 使用了 HTTP Proxy 且 Proxy 出错
  52. extern NSString *const ssl_error; // SSL 加密错误
  53. extern NSString *const response_error; // 收到响应,但状态码非 200
  54. extern NSString *const parse_error; // 解析响应错误
  55. extern NSString *const malicious_response; // 用户劫持错误
  56. extern NSString *const user_canceled; // 用户主动取消
  57. extern NSString *const bad_request; // API 失败是由于客户端的参数错误导致,⽆法依靠重试来解决的(例如 4xx 错误, upload token 错误,⽬标 bucket 不存在,⽂件已经存在,区域不正确,额度不够 等)
  58. extern NSString *const protocol_error; // 协议错误
  59. extern int64_t QN_IntNotSet;
  60. // 用于统计上传质量 和生成QNResponseInfo实例
  61. @interface QNUploadInfoCollector : NSObject
  62. - (id)init __attribute__((unavailable("Use sharedInstance: instead.")));
  63. + (instancetype)sharedInstance;
  64. /**
  65. * 注册上传统计实例
  66. *
  67. * @param identifier 此次上传的唯一标识
  68. * @param token 上传token
  69. *
  70. */
  71. - (void)registerWithIdentifier:(NSString *)identifier token:(NSString *)token;
  72. /**
  73. * 更新QNCollectKey对应的上传信息
  74. *
  75. * @param key 需要更新的QNCollectKey
  76. * @param identifier 此次上传的唯一标识
  77. *
  78. */
  79. - (void)update:(QNCollectKey *)key value:(id)value identifier:(NSString *)identifier;
  80. /**
  81. * 拼接QNCollectKey对应的上传信息 一般用于拼接数字类型常量
  82. *
  83. * @param key 需要拼接的QNCollectKey
  84. * @param identifier 此次上传的唯一标识
  85. *
  86. */
  87. - (void)append:(QNCollectKey *)key value:(id)value identifier:(NSString *)identifier;
  88. /**
  89. * 记录此次上传中单次http请求结果
  90. *
  91. * @param upType 请求类型
  92. * @param httpResponseInfo 请求返回信息
  93. * @param fileOffset data偏移量(非分片上传请求时该值为0)
  94. * @param targetRegionId 目标区域id
  95. * @param currentRegionId 当前区域id
  96. * @param identifier 此次上传的唯一标识
  97. *
  98. */
  99. - (void)addRequestWithType:(QNRequestType)upType httpResponseInfo:(QNHttpResponseInfo *)httpResponseInfo fileOffset:(int64_t)fileOffset targetRegionId:(NSString *)targetRegionId currentRegionId:(NSString *)currentRegionId identifier:(NSString *)identifier;
  100. /**
  101. * 根据http请求结果返回QNResponseInfo
  102. *
  103. * @param lastHttpResponseInfo 最后一个请求的返回信息
  104. * @param identifier 此次上传的唯一标识
  105. *
  106. * @return QNResponseInfo 返回信息
  107. */
  108. - (QNResponseInfo *)completeWithHttpResponseInfo:(QNHttpResponseInfo *)lastHttpResponseInfo identifier:(NSString *)identifier;
  109. /**
  110. * 参数问题导致上传结束并返回QNResponseInfo
  111. *
  112. * @param text 描述
  113. * @param identifier 此次上传的唯一标识
  114. *
  115. * @return QNResponseInfo 返回信息
  116. */
  117. - (QNResponseInfo *)completeWithInvalidArgument:(NSString *)text identifier:(NSString *)identifier;
  118. /**
  119. * token无效导致上传结束并返回QNResponseInfo
  120. *
  121. * @param text 描述
  122. * @param identifier 此次上传的唯一标识
  123. *
  124. * @return QNResponseInfo 返回信息
  125. */
  126. - (QNResponseInfo *)completeWithInvalidToken:(NSString *)text identifier:(NSString *)identifier;
  127. /**
  128. * 文件内容出错导致上传结束并返回QNResponseInfo
  129. *
  130. * @param error 报错信息
  131. * @param identifier 此次上传的唯一标识
  132. *
  133. * @return QNResponseInfo 返回信息
  134. */
  135. - (QNResponseInfo *)completeWithFileError:(NSError *)error identifier:(NSString *)identifier;
  136. /**
  137. * 本地 I/O 出错导致上传结束并返回QNResponseInfo
  138. *
  139. * @param error 报错信息
  140. * @param identifier 此次上传的唯一标识
  141. *
  142. * @return QNResponseInfo 返回信息
  143. */
  144. - (QNResponseInfo *)completeWithLocalIOError:(NSError *)error identifier:(NSString *)identifier;
  145. /**
  146. * zero data问题导致上传结束并返回QNResponseInfo
  147. *
  148. * @param path 文件路径
  149. * @param identifier 此次上传的唯一标识
  150. *
  151. * @return QNResponseInfo 返回信息
  152. */
  153. - (QNResponseInfo *)completeWithZeroData:(NSString *)path identifier:(NSString *)identifier;
  154. /**
  155. * 用户取消导致上传结束并返回QNResponseInfo
  156. *
  157. * @param identifier 此次上传的唯一标识
  158. *
  159. * @return QNResponseInfo 返回信息
  160. */
  161. - (QNResponseInfo *)userCancel:(NSString *)identifier;
  162. @end