Skip to content

Commit

Permalink
Merge pull request #420 from YangSen-qn/multi-region
Browse files Browse the repository at this point in the history
revert multi region
  • Loading branch information
bachue authored Dec 5, 2022
2 parents c253960 + aa5a48e commit 01f9b61
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 175 deletions.
12 changes: 0 additions & 12 deletions QiniuSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,6 @@
4551E56724D0065100447285 /* NSData+QNMD5.h in Headers */ = {isa = PBXBuildFile; fileRef = 4551E56524D0065100447285 /* NSData+QNMD5.h */; };
4551E56824D0065100447285 /* NSData+QNMD5.m in Sources */ = {isa = PBXBuildFile; fileRef = 4551E56624D0065100447285 /* NSData+QNMD5.m */; };
4551E56924D0065100447285 /* NSData+QNMD5.m in Sources */ = {isa = PBXBuildFile; fileRef = 4551E56624D0065100447285 /* NSData+QNMD5.m */; };
45CFDAFB292370720077890F /* QNApiType.h in Headers */ = {isa = PBXBuildFile; fileRef = 45CFDAF9292370720077890F /* QNApiType.h */; };
45CFDAFC292370720077890F /* QNApiType.h in Headers */ = {isa = PBXBuildFile; fileRef = 45CFDAF9292370720077890F /* QNApiType.h */; };
45CFDAFD292370720077890F /* QNApiType.m in Sources */ = {isa = PBXBuildFile; fileRef = 45CFDAFA292370720077890F /* QNApiType.m */; };
45CFDAFE292370720077890F /* QNApiType.m in Sources */ = {isa = PBXBuildFile; fileRef = 45CFDAFA292370720077890F /* QNApiType.m */; };
CC25135C244C7EB3003F4C65 /* QNBaseUpload.h in Headers */ = {isa = PBXBuildFile; fileRef = CC25135A244C7EB3003F4C65 /* QNBaseUpload.h */; };
CC25135D244C7EB3003F4C65 /* QNBaseUpload.m in Sources */ = {isa = PBXBuildFile; fileRef = CC25135B244C7EB3003F4C65 /* QNBaseUpload.m */; };
CC25135E244C7EB3003F4C65 /* QNBaseUpload.m in Sources */ = {isa = PBXBuildFile; fileRef = CC25135B244C7EB3003F4C65 /* QNBaseUpload.m */; };
Expand Down Expand Up @@ -593,8 +589,6 @@
4551E55E24CE81DA00447285 /* QNInetAddress.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNInetAddress.m; sourceTree = "<group>"; };
4551E56524D0065100447285 /* NSData+QNMD5.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSData+QNMD5.h"; sourceTree = "<group>"; };
4551E56624D0065100447285 /* NSData+QNMD5.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSData+QNMD5.m"; sourceTree = "<group>"; };
45CFDAF9292370720077890F /* QNApiType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNApiType.h; sourceTree = "<group>"; };
45CFDAFA292370720077890F /* QNApiType.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNApiType.m; sourceTree = "<group>"; };
466E7AACB5F77BA0D4DE4070 /* Pods-QiniuSDK_MacTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QiniuSDK_MacTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-QiniuSDK_MacTests/Pods-QiniuSDK_MacTests.debug.xcconfig"; sourceTree = "<group>"; };
6663602DA8CC701EA3B11F04 /* Pods-QiniuSDK_iOS.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QiniuSDK_iOS.debug.xcconfig"; path = "Pods/Target Support Files/Pods-QiniuSDK_iOS/Pods-QiniuSDK_iOS.debug.xcconfig"; sourceTree = "<group>"; };
69B20FB4731F84969BC5AEBE /* Pods-QiniuSDK_Mac.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QiniuSDK_Mac.debug.xcconfig"; path = "Pods/Target Support Files/Pods-QiniuSDK_Mac/Pods-QiniuSDK_Mac.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -983,8 +977,6 @@
31494475244852BA00386F16 /* QNFixedZone.m */,
31D84468254017BD005C0222 /* QNErrorCode.h */,
31D84469254017BD005C0222 /* QNErrorCode.m */,
45CFDAF9292370720077890F /* QNApiType.h */,
45CFDAFA292370720077890F /* QNApiType.m */,
);
path = Common;
sourceTree = "<group>";
Expand Down Expand Up @@ -1152,7 +1144,6 @@
318E2F212552AE2F004EDE8C /* QNResponseInfo.h in Headers */,
31C9D2552717E106006B9433 /* QNCFHttpThreadPool.h in Headers */,
318E2F1F2552AE2F004EDE8C /* QNInetAddress.h in Headers */,
45CFDAFC292370720077890F /* QNApiType.h in Headers */,
3188D4D326490A0C00183CAE /* QNUploadInfo.h in Headers */,
318E2F122552AE2B004EDE8C /* QNUploadSystemClient.h in Headers */,
318E2F042552AE05004EDE8C /* QNUrlSafeBase64.h in Headers */,
Expand Down Expand Up @@ -1200,7 +1191,6 @@
31F553972456F2F3000B66AD /* QNUrlSafeBase64.h in Headers */,
31F553A62456F2F3000B66AD /* QNFile.h in Headers */,
31FE6A0B25A8320200C02B27 /* QNConnectChecker.h in Headers */,
45CFDAFB292370720077890F /* QNApiType.h in Headers */,
31F553CB24596C3D000B66AD /* QNHttpRegionRequest.h in Headers */,
31F5539A2456F2F3000B66AD /* QNVersion.h in Headers */,
31BAA27A243DB83700B7E883 /* NSURLRequest+QNRequest.h in Headers */,
Expand Down Expand Up @@ -1575,7 +1565,6 @@
3149A1E02462A57400A2A15B /* QNUploadServer.m in Sources */,
31F553C12457FFB0000B66AD /* QNPipeline.m in Sources */,
4551E56024CE81DA00447285 /* QNInetAddress.m in Sources */,
45CFDAFD292370720077890F /* QNApiType.m in Sources */,
CC25135D244C7EB3003F4C65 /* QNBaseUpload.m in Sources */,
DF437CDA1B2429E10099587B /* QNUpToken.m in Sources */,
3177B70625A30C4500C56293 /* QNSingleFlight.m in Sources */,
Expand Down Expand Up @@ -1700,7 +1689,6 @@
3149A1E12462A57400A2A15B /* QNUploadServer.m in Sources */,
4551E56124CE81DA00447285 /* QNInetAddress.m in Sources */,
31F553AF2457D2E5000B66AD /* QNALAssetFile.m in Sources */,
45CFDAFE292370720077890F /* QNApiType.m in Sources */,
313B380F2575E49400FBB57B /* QNPartsUploadPerformer.m in Sources */,
DF437CDC1B2429E10099587B /* QNUpToken.m in Sources */,
3177B70725A30C4500C56293 /* QNSingleFlight.m in Sources */,
Expand Down
28 changes: 0 additions & 28 deletions QiniuSDK/Common/QNApiType.h

This file was deleted.

49 changes: 0 additions & 49 deletions QiniuSDK/Common/QNApiType.m

This file was deleted.

13 changes: 6 additions & 7 deletions QiniuSDK/Common/QNAutoZone.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,17 +133,16 @@ - (void)setDefaultZones:(NSArray <QNFixedZone *> *)zones {
self.defaultZone = [QNFixedZone combineZones:zones];
}

- (QNZonesInfo *)getZonesInfoWithToken:(QNUpToken * _Nullable)token
actionType:(QNActionType)actionType {
- (QNZonesInfo *)getZonesInfoWithToken:(QNUpToken * _Nullable)token {

if (token == nil) return nil;
NSString *cacheKey = [NSString stringWithFormat:@"%@%@", token.index, [QNApiType actionTypeString:actionType]] ;
NSString *cacheKey = [NSString stringWithFormat:@"%@", token.index] ;
QNZonesInfo *zonesInfo = [[QNAutoZoneCache share] cacheForKey:cacheKey];
zonesInfo = [zonesInfo copy];
return zonesInfo;
}

- (void)preQuery:(QNUpToken *)token actionType:(QNActionType)actionType on:(QNPrequeryReturn)ret {
- (void)preQuery:(QNUpToken *)token on:(QNPrequeryReturn)ret {

if (token == nil || ![token isValid]) {
ret(-1, [QNResponseInfo responseInfoWithInvalidToken:@"invalid token"], nil);
Expand All @@ -153,7 +152,7 @@ - (void)preQuery:(QNUpToken *)token actionType:(QNActionType)actionType on:(QNPr
QNUploadRegionRequestMetrics *cacheMetrics = [QNUploadRegionRequestMetrics emptyMetrics];
[cacheMetrics start];

NSString *cacheKey = [NSString stringWithFormat:@"%@%@", token.index, [QNApiType actionTypeString:actionType]] ;
NSString *cacheKey = [NSString stringWithFormat:@"%@", token.index] ;
QNZonesInfo *zonesInfo = [[QNAutoZoneCache share] zonesInfoForKey:cacheKey];

// 临时的 zonesInfo 仅能使用一次
Expand Down Expand Up @@ -190,7 +189,7 @@ - (void)preQuery:(QNUpToken *)token actionType:(QNActionType)actionType on:(QNPr
QNUploadRegionRequestMetrics *metrics = [(QNUCQuerySingleFlightValue *)value metrics];

if (responseInfo && responseInfo.isOK) {
QNZonesInfo *zonesInfo = [QNZonesInfo infoWithDictionary:response actionType:actionType];
QNZonesInfo *zonesInfo = [QNZonesInfo infoWithDictionary:response];
if ([zonesInfo isValid]) {
[[QNAutoZoneCache share] cache:zonesInfo forKey:cacheKey];
ret(0, responseInfo, metrics);
Expand All @@ -203,7 +202,7 @@ - (void)preQuery:(QNUpToken *)token actionType:(QNActionType)actionType on:(QNPr
} else {
QNZonesInfo *info = nil;
if (self.defaultZone) {
QNZonesInfo * infoP = [self.defaultZone getZonesInfoWithToken:token actionType:actionType];
QNZonesInfo * infoP = [self.defaultZone getZonesInfoWithToken:token];
if (infoP && [infoP isValid]) {
[infoP toTemporary];
info = infoP;
Expand Down
2 changes: 1 addition & 1 deletion QiniuSDK/Common/QNFixedZone.m
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ - (instancetype)initWithUpDomainList:(NSArray<NSString *> *)upList
return self;
}

- (QNZonesInfo *)getZonesInfoWithToken:(QNUpToken *)token actionType:(QNActionType)actionType {
- (QNZonesInfo *)getZonesInfoWithToken:(QNUpToken *)token {
return self.zonesInfo;
}

Expand Down
15 changes: 1 addition & 14 deletions QiniuSDK/Common/QNZone.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2020 Qiniu. All rights reserved.
//

#import "QNApiType.h"
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -22,23 +22,10 @@ typedef void (^QNPrequeryReturn)(int code, QNResponseInfo * _Nullable httpRespon
- (void)preQuery:(QNUpToken * _Nullable)token
on:(QNPrequeryReturn _Nullable)ret;

/// 根据token查询相关 Zone 信息【内部使用】
/// @param token token 信息
/// @param actionType action 类型
/// @param ret 查询回调
- (void)preQuery:(QNUpToken * _Nullable)token
actionType:(QNActionType)actionType
on:(QNPrequeryReturn _Nullable)ret;

/// 根据token获取ZonesInfo 【内部使用】
/// @param token token信息
- (QNZonesInfo *)getZonesInfoWithToken:(QNUpToken * _Nullable)token;

/// 获取ZonesInfo 【内部使用】
/// @param token token 信息
/// @param actionType action 类型
- (QNZonesInfo *)getZonesInfoWithToken:(QNUpToken * _Nullable)token actionType:(QNActionType)actionType;

@end

NS_ASSUME_NONNULL_END
11 changes: 0 additions & 11 deletions QiniuSDK/Common/QNZone.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,11 @@
@implementation QNZone

- (QNZonesInfo *)getZonesInfoWithToken:(QNUpToken *)token {
return [self getZonesInfoWithToken:token actionType:QNActionTypeNone];
}

- (QNZonesInfo *)getZonesInfoWithToken:(QNUpToken * _Nullable)token
actionType:(QNActionType)actionType {
return nil;
}

- (void)preQuery:(QNUpToken *)token
on:(QNPrequeryReturn)ret {
[self preQuery:token actionType:QNActionTypeNone on:ret];
}

- (void)preQuery:(QNUpToken *)token
actionType:(QNActionType)actionType
on:(QNPrequeryReturn)ret {
ret(0, nil, nil);
}

Expand Down
7 changes: 1 addition & 6 deletions QiniuSDK/Common/QNZoneInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Copyright © 2020 Qiniu. All rights reserved.
//

#import "QNApiType.h"
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -49,11 +49,6 @@ extern NSString *const QNZoneInfoEmptyRegionId;
/// @param dictionary 键值对信息
+ (instancetype)infoWithDictionary:(NSDictionary *)dictionary;

/// 根据键值对构造对象 【内部使用】
/// @param dictionary 键值对信息
/// @param actionType action 类型
+ (instancetype)infoWithDictionary:(NSDictionary *)dictionary actionType:(QNActionType)actionType;

- (instancetype)initWithZonesInfo:(NSArray<QNZoneInfo *> *)zonesInfo;

// 转成临时 zones, 临时 Zones,不建议长期使用
Expand Down
33 changes: 0 additions & 33 deletions QiniuSDK/Common/QNZoneInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -139,40 +139,7 @@ - (instancetype)initWithZonesInfo:(NSArray<QNZoneInfo *> *)zonesInfo{
}

+ (instancetype)infoWithDictionary:(NSDictionary *)dictionary {
return [self infoWithDictionary:dictionary actionType:QNActionTypeNone];
}

+ (instancetype)infoWithDictionary:(NSDictionary *)dictionary actionType:(QNActionType)actionType {
NSMutableArray *zonesInfo = [NSMutableArray array];

NSArray *supportApis = [QNApiType apisWithActionType:actionType];
if (supportApis != nil && supportApis.count > 0) {
NSMutableDictionary *universal = [dictionary[@"universal"] mutableCopy];
if ([universal isKindOfClass:[NSDictionary class]]) {

BOOL support = false;
NSArray *apis = universal[@"support_apis"];
if ([apis isKindOfClass:[NSArray class]]) {
support = true;
for (NSString *supportApi in supportApis) {
if (![apis containsObject:supportApi]) {
support = false;
break;
}
}
}

// 同时满足所有 api
if (support) {
[universal setObject:@"universal" forKey:@"region"];
QNZoneInfo *zoneInfo = [QNZoneInfo zoneInfoFromDictionary:universal];
if (zoneInfo && [zoneInfo isValid]) {
[zonesInfo addObject:zoneInfo];
}
}
}
}

NSArray *hosts = dictionary[@"hosts"];
if ([hosts isKindOfClass:[NSArray class]]) {
for (NSInteger i = 0; i < hosts.count; i++) {
Expand Down
16 changes: 2 additions & 14 deletions QiniuSDK/Storage/QNBaseUpload.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ - (void)run {
[self.metrics start];

kQNWeakSelf;
[_config.zone preQuery:self.token actionType:[self actionType] on:^(int code, QNResponseInfo *responseInfo, QNUploadRegionRequestMetrics *metrics) {
[_config.zone preQuery:self.token on:^(int code, QNResponseInfo *responseInfo, QNUploadRegionRequestMetrics *metrics) {
kQNStrongSelf;
self.metrics.ucQueryMetrics = metrics;

Expand Down Expand Up @@ -199,22 +199,10 @@ - (void)complete:(QNResponseInfo *)info
self.strongSelf = nil;
}

- (QNActionType)actionType {
if ([self.upType containsString:QNUploadUpTypeForm]) {
return QNActionTypeUploadByForm;
} else if ([self.upType containsString:QNUploadUpTypeResumableV1]) {
return QNActionTypeUploadByResumeV1;
} else if ([self.upType containsString:QNUploadUpTypeResumableV2]) {
return QNActionTypeUploadByResumeV2;
} else {
return QNActionTypeNone;
}
}

//MARK:-- region
- (BOOL)setupRegions{
NSMutableArray *defaultRegions = [NSMutableArray array];
NSArray *zoneInfos = [self.config.zone getZonesInfoWithToken:self.token actionType:[self actionType]].zonesInfo;
NSArray *zoneInfos = [self.config.zone getZonesInfoWithToken:self.token].zonesInfo;
for (QNZoneInfo *zoneInfo in zoneInfos) {
QNUploadDomainRegion *region = [[QNUploadDomainRegion alloc] init];
[region setupRegionData:zoneInfo];
Expand Down

0 comments on commit 01f9b61

Please sign in to comment.