QNFixedZone.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. //
  2. // QNFixZone.m
  3. // QiniuSDK
  4. //
  5. // Created by yangsen on 2020/4/16.
  6. // Copyright © 2020 Qiniu. All rights reserved.
  7. //
  8. #import "QNFixedZone.h"
  9. #import "QNZoneInfo.h"
  10. @interface QNFixedZone ()
  11. @property (nonatomic, strong) QNZonesInfo *zonesInfo;
  12. @end
  13. @implementation QNFixedZone
  14. + (instancetype)zone0 {
  15. static QNFixedZone *z0 = nil;
  16. static dispatch_once_t onceToken;
  17. dispatch_once(&onceToken, ^{
  18. z0 = [[QNFixedZone alloc] initWithUpDomainList:@[@"upload.qiniup.com", @"up.qiniup.com"]
  19. oldUpList:@[@"upload.qbox.me", @"up.qbox.me"]
  20. regionId:@"z0"];
  21. });
  22. return z0;
  23. }
  24. + (instancetype)zone1 {
  25. static QNFixedZone *z1 = nil;
  26. static dispatch_once_t onceToken;
  27. dispatch_once(&onceToken, ^{
  28. z1 = [[QNFixedZone alloc] initWithUpDomainList:@[@"upload-z1.qiniup.com", @"up-z1.qiniup.com"]
  29. oldUpList:@[@"upload-z1.qbox.me", @"up-z1.qbox.me"]
  30. regionId:@"z1"];
  31. });
  32. return z1;
  33. }
  34. + (instancetype)zone2 {
  35. static QNFixedZone *z2 = nil;
  36. static dispatch_once_t onceToken;
  37. dispatch_once(&onceToken, ^{
  38. z2 = [[QNFixedZone alloc] initWithUpDomainList:@[@"upload-z2.qiniup.com", @"up-z2.qiniup.com"]
  39. oldUpList:@[@"upload-z2.qbox.me", @"up-z2.qbox.me"]
  40. regionId:@"z2"];
  41. });
  42. return z2;
  43. }
  44. + (instancetype)zoneNa0 {
  45. static QNFixedZone *zNa0 = nil;
  46. static dispatch_once_t onceToken;
  47. dispatch_once(&onceToken, ^{
  48. zNa0 = [[QNFixedZone alloc] initWithUpDomainList:@[@"upload-na0.qiniup.com", @"up-na0.qiniup.com"]
  49. oldUpList:@[@"upload-na0.qbox.me", @"up-na0.qbox.me"]
  50. regionId:@"na0"];
  51. });
  52. return zNa0;
  53. }
  54. + (instancetype)zoneAs0 {
  55. static QNFixedZone *zAs0 = nil;
  56. static dispatch_once_t onceToken;
  57. dispatch_once(&onceToken, ^{
  58. zAs0 = [[QNFixedZone alloc] initWithUpDomainList:@[@"upload-as0.qiniup.com", @"up-as0.qiniup.com"]
  59. oldUpList:@[@"upload-as0.qbox.me", @"up-as0.qbox.me"]
  60. regionId:@"as0"];;
  61. });
  62. return zAs0;
  63. }
  64. + (instancetype)zoneFogCnEast1 {
  65. static QNFixedZone *zFogCnEast1 = nil;
  66. static dispatch_once_t onceToken;
  67. dispatch_once(&onceToken, ^{
  68. zFogCnEast1 = [[QNFixedZone alloc] initWithUpDomainList:@[@"upload-fog-cn-east-1.qiniup.com",
  69. @"up-fog-cn-east-1.qiniup.com"]
  70. oldUpList:@[@"upload-fog-cn-east-1.qiniup.com",
  71. @"up-fog-cn-east-1.qiniup.com"]
  72. regionId:@"fog-cn-east-1"];;
  73. });
  74. return zFogCnEast1;
  75. }
  76. + (QNFixedZone *)localsZoneInfo{
  77. NSArray *zones = @[[QNFixedZone zone0],
  78. [QNFixedZone zone1],
  79. [QNFixedZone zone2],
  80. [QNFixedZone zoneNa0],
  81. [QNFixedZone zoneAs0]];
  82. NSMutableArray <QNZoneInfo *> *zoneInfoArray = [NSMutableArray array];
  83. for (QNFixedZone *zone in zones) {
  84. if (zone.zonesInfo.zonesInfo) {
  85. [zoneInfoArray addObjectsFromArray:zone.zonesInfo.zonesInfo];
  86. }
  87. }
  88. QNFixedZone *fixedZone = [[QNFixedZone alloc] init];
  89. fixedZone.zonesInfo = [[QNZonesInfo alloc] initWithZonesInfo:[zoneInfoArray copy]];
  90. return fixedZone;
  91. }
  92. + (instancetype)createWithHost:(NSArray<NSString *> *)upList {
  93. return [[QNFixedZone alloc] initWithUpDomainList:upList oldUpList:nil regionId:nil];
  94. }
  95. - (QNZonesInfo *)createZonesInfo:(NSArray <NSString *> *)upDomains
  96. regionId:(NSString *)regionId {
  97. return [self createZonesInfo:upDomains oldUpDomains:nil regionId:regionId];
  98. }
  99. - (QNZonesInfo *)createZonesInfo:(NSArray <NSString *> *)upDomains
  100. oldUpDomains:(NSArray <NSString *> *)oldUpDomains
  101. regionId:(NSString *)regionId {
  102. if (!upDomains && upDomains.count == 0) {
  103. return nil;
  104. }
  105. QNZoneInfo *zoneInfo = [QNZoneInfo zoneInfoWithMainHosts:upDomains oldHosts:oldUpDomains regionId:regionId];
  106. QNZonesInfo *zonesInfo = [[QNZonesInfo alloc] initWithZonesInfo:@[zoneInfo]];
  107. return zonesInfo;
  108. }
  109. - (instancetype)initWithUpDomainList:(NSArray<NSString *> *)upList {
  110. if (self = [super init]) {
  111. self.zonesInfo = [self createZonesInfo:upList regionId:nil];
  112. }
  113. return self;
  114. }
  115. - (instancetype)initWithUpDomainList:(NSArray<NSString *> *)upList
  116. regionId:(NSString *)regionId {
  117. if (self = [super init]) {
  118. self.zonesInfo = [self createZonesInfo:upList regionId:regionId];
  119. }
  120. return self;
  121. }
  122. - (instancetype)initWithUpDomainList:(NSArray<NSString *> *)upList
  123. oldUpList:(NSArray<NSString *> *)oldUpList
  124. regionId:(NSString *)regionId {
  125. if (self = [super init]) {
  126. self.zonesInfo = [self createZonesInfo:upList oldUpDomains:oldUpList regionId:regionId];
  127. }
  128. return self;
  129. }
  130. - (void)preQuery:(QNUpToken *)token
  131. on:(QNPrequeryReturn)ret {
  132. ret(0, nil, nil);
  133. }
  134. - (QNZonesInfo *)getZonesInfoWithToken:(QNUpToken *)token {
  135. return self.zonesInfo;
  136. }
  137. @end