From aa5a48edfdb213dcf729c8f04f514c80a335095a Mon Sep 17 00:00:00 2001 From: yangsen Date: Fri, 2 Dec 2022 18:40:16 +0800 Subject: [PATCH] revert multi region --- QiniuSDK.xcodeproj/project.pbxproj | 12 -------- QiniuSDK/Common/QNApiType.h | 28 ----------------- QiniuSDK/Common/QNApiType.m | 49 ------------------------------ QiniuSDK/Common/QNAutoZone.m | 13 ++++---- QiniuSDK/Common/QNFixedZone.m | 2 +- QiniuSDK/Common/QNZone.h | 15 +-------- QiniuSDK/Common/QNZone.m | 11 ------- QiniuSDK/Common/QNZoneInfo.h | 7 +---- QiniuSDK/Common/QNZoneInfo.m | 33 -------------------- QiniuSDK/Storage/QNBaseUpload.m | 16 ++-------- 10 files changed, 11 insertions(+), 175 deletions(-) delete mode 100644 QiniuSDK/Common/QNApiType.h delete mode 100644 QiniuSDK/Common/QNApiType.m diff --git a/QiniuSDK.xcodeproj/project.pbxproj b/QiniuSDK.xcodeproj/project.pbxproj index aed1aabc..6265ed9f 100644 --- a/QiniuSDK.xcodeproj/project.pbxproj +++ b/QiniuSDK.xcodeproj/project.pbxproj @@ -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 */; }; @@ -593,8 +589,6 @@ 4551E55E24CE81DA00447285 /* QNInetAddress.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNInetAddress.m; sourceTree = ""; }; 4551E56524D0065100447285 /* NSData+QNMD5.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSData+QNMD5.h"; sourceTree = ""; }; 4551E56624D0065100447285 /* NSData+QNMD5.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSData+QNMD5.m"; sourceTree = ""; }; - 45CFDAF9292370720077890F /* QNApiType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNApiType.h; sourceTree = ""; }; - 45CFDAFA292370720077890F /* QNApiType.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNApiType.m; sourceTree = ""; }; 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 = ""; }; 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 = ""; }; 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 = ""; }; @@ -983,8 +977,6 @@ 31494475244852BA00386F16 /* QNFixedZone.m */, 31D84468254017BD005C0222 /* QNErrorCode.h */, 31D84469254017BD005C0222 /* QNErrorCode.m */, - 45CFDAF9292370720077890F /* QNApiType.h */, - 45CFDAFA292370720077890F /* QNApiType.m */, ); path = Common; sourceTree = ""; @@ -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 */, @@ -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 */, @@ -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 */, @@ -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 */, diff --git a/QiniuSDK/Common/QNApiType.h b/QiniuSDK/Common/QNApiType.h deleted file mode 100644 index d5ae0a06..00000000 --- a/QiniuSDK/Common/QNApiType.h +++ /dev/null @@ -1,28 +0,0 @@ -// -// QNApiType.h -// QiniuSDK -// -// Created by yangsen on 2022/11/15. -// Copyright © 2022 Qiniu. All rights reserved. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -typedef NS_ENUM(NSUInteger, QNActionType) { - QNActionTypeNone, - QNActionTypeUploadByForm, - QNActionTypeUploadByResumeV1, - QNActionTypeUploadByResumeV2, -}; - -@interface QNApiType : NSObject - -+ (NSString *)actionTypeString:(QNActionType)actionType; - -+ (NSArray *)apisWithActionType:(QNActionType)actionType; - -@end - -NS_ASSUME_NONNULL_END diff --git a/QiniuSDK/Common/QNApiType.m b/QiniuSDK/Common/QNApiType.m deleted file mode 100644 index 61af2661..00000000 --- a/QiniuSDK/Common/QNApiType.m +++ /dev/null @@ -1,49 +0,0 @@ -// -// QNApiType.m -// QiniuSDK -// -// Created by yangsen on 2022/11/15. -// Copyright © 2022 Qiniu. All rights reserved. -// - -#import "QNApiType.h" - -@implementation QNApiType - -+ (NSString *)actionTypeString:(QNActionType)actionType { - NSString *type = @""; - switch (actionType) { - case QNActionTypeUploadByForm: - type = @"form"; - break; - case QNActionTypeUploadByResumeV1: - type = @"resume-v1"; - break; - case QNActionTypeUploadByResumeV2: - type = @"resume-v2"; - break; - default: - break; - } - return type; -} - -+ (NSArray *)apisWithActionType:(QNActionType)actionType { - NSArray *apis = nil; - switch (actionType) { - case QNActionTypeUploadByForm: - apis = @[@"up.formupload"]; - break; - case QNActionTypeUploadByResumeV1: - apis = @[@"up.mkblk", @"up.bput", @"up.mkfile"]; - break; - case QNActionTypeUploadByResumeV2: - apis = @[@"up.initparts", @"up.uploadpart", @"up.completeparts"]; - break; - default: - break; - } - return apis; -} - -@end diff --git a/QiniuSDK/Common/QNAutoZone.m b/QiniuSDK/Common/QNAutoZone.m index c225f4ea..384404bb 100644 --- a/QiniuSDK/Common/QNAutoZone.m +++ b/QiniuSDK/Common/QNAutoZone.m @@ -133,17 +133,16 @@ - (void)setDefaultZones:(NSArray *)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); @@ -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 仅能使用一次 @@ -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); @@ -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; diff --git a/QiniuSDK/Common/QNFixedZone.m b/QiniuSDK/Common/QNFixedZone.m index e09ad183..e76145fe 100644 --- a/QiniuSDK/Common/QNFixedZone.m +++ b/QiniuSDK/Common/QNFixedZone.m @@ -171,7 +171,7 @@ - (instancetype)initWithUpDomainList:(NSArray *)upList return self; } -- (QNZonesInfo *)getZonesInfoWithToken:(QNUpToken *)token actionType:(QNActionType)actionType { +- (QNZonesInfo *)getZonesInfoWithToken:(QNUpToken *)token { return self.zonesInfo; } diff --git a/QiniuSDK/Common/QNZone.h b/QiniuSDK/Common/QNZone.h index bec4a27d..ed73bc2e 100644 --- a/QiniuSDK/Common/QNZone.h +++ b/QiniuSDK/Common/QNZone.h @@ -6,7 +6,7 @@ // Copyright © 2020 Qiniu. All rights reserved. // -#import "QNApiType.h" +#import NS_ASSUME_NONNULL_BEGIN @@ -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 diff --git a/QiniuSDK/Common/QNZone.m b/QiniuSDK/Common/QNZone.m index b181c205..f973130d 100644 --- a/QiniuSDK/Common/QNZone.m +++ b/QiniuSDK/Common/QNZone.m @@ -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); } diff --git a/QiniuSDK/Common/QNZoneInfo.h b/QiniuSDK/Common/QNZoneInfo.h index 8dbe81a3..a81be416 100644 --- a/QiniuSDK/Common/QNZoneInfo.h +++ b/QiniuSDK/Common/QNZoneInfo.h @@ -6,7 +6,7 @@ // Copyright © 2020 Qiniu. All rights reserved. // -#import "QNApiType.h" +#import NS_ASSUME_NONNULL_BEGIN @@ -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 *)zonesInfo; // 转成临时 zones, 临时 Zones,不建议长期使用 diff --git a/QiniuSDK/Common/QNZoneInfo.m b/QiniuSDK/Common/QNZoneInfo.m index 3931d042..a585198f 100644 --- a/QiniuSDK/Common/QNZoneInfo.m +++ b/QiniuSDK/Common/QNZoneInfo.m @@ -139,40 +139,7 @@ - (instancetype)initWithZonesInfo:(NSArray *)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++) { diff --git a/QiniuSDK/Storage/QNBaseUpload.m b/QiniuSDK/Storage/QNBaseUpload.m index c7916af5..27c3e090 100644 --- a/QiniuSDK/Storage/QNBaseUpload.m +++ b/QiniuSDK/Storage/QNBaseUpload.m @@ -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; @@ -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];