Skip to content

Commit

Permalink
add createWithRegionId (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSen-qn authored Oct 20, 2023
1 parent 65caed5 commit 3db00f9
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 23 deletions.
25 changes: 9 additions & 16 deletions QiniuSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
/* End PBXAggregateTarget section */

/* Begin PBXBuildFile section */
0CD9B2165D33CBCFF01AAE0B /* libPods-QiniuSDK_MacTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 24BA93FDA4B776A502783C4A /* libPods-QiniuSDK_MacTests.a */; };
12E9CD5CF6B4132A6ED0D7D4 /* libPods-QiniuSDK_Mac.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E98517EE5689BE11EA6791A5 /* libPods-QiniuSDK_Mac.a */; };
3115471D243476CF00D77B8B /* QNTransactionTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 3115471C243476CF00D77B8B /* QNTransactionTest.m */; };
3115471E243476D600D77B8B /* QNTransactionTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 3115471C243476CF00D77B8B /* QNTransactionTest.m */; };
311ADD1F2577482C00A6E15E /* QNUploadBaseTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 311ADD1A2577482200A6E15E /* QNUploadBaseTest.m */; };
Expand Down Expand Up @@ -358,6 +356,8 @@
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 */; };
45CBC6C32AA9B05A00962B47 /* QNFixZoneTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45CBC6C22AA9B05A00962B47 /* QNFixZoneTest.m */; };
45CBC6C42AA9B05A00962B47 /* QNFixZoneTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45CBC6C22AA9B05A00962B47 /* QNFixZoneTest.m */; };
45CBC6D22ABA9FFF00962B47 /* QNCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 45CBC6D02ABA9FFF00962B47 /* QNCache.h */; };
45CBC6D32ABA9FFF00962B47 /* QNCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 45CBC6D02ABA9FFF00962B47 /* QNCache.h */; };
45CBC6D42ABA9FFF00962B47 /* QNCache.m in Sources */ = {isa = PBXBuildFile; fileRef = 45CBC6D12ABA9FFF00962B47 /* QNCache.m */; };
Expand All @@ -366,8 +366,6 @@
45CBC6D82ABAE24900962B47 /* QNCacheTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45CBC6D62ABAE24900962B47 /* QNCacheTest.m */; };
45E0B28A2A1F0596009B1BC7 /* QNConfigurationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45E0B2892A1F0596009B1BC7 /* QNConfigurationTest.m */; };
45E0B28B2A1F0596009B1BC7 /* QNConfigurationTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45E0B2892A1F0596009B1BC7 /* QNConfigurationTest.m */; };
8D0FB78D364BAEE65E20A604 /* libPods-QiniuSDK_iOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = F881668982449FAF2384327E /* libPods-QiniuSDK_iOS.a */; };
C275A64FFBE81B9CE7DDC79E /* libPods-QiniuSDK_iOSTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5F32D114A1227199BEC6DF5C /* libPods-QiniuSDK_iOSTests.a */; };
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 @@ -437,7 +435,6 @@

/* Begin PBXFileReference section */
135958056D8FF4295F3D9AB0 /* Pods-QiniuSDK_iOSTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QiniuSDK_iOSTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-QiniuSDK_iOSTests/Pods-QiniuSDK_iOSTests.release.xcconfig"; sourceTree = "<group>"; };
24BA93FDA4B776A502783C4A /* libPods-QiniuSDK_MacTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-QiniuSDK_MacTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
3115471C243476CF00D77B8B /* QNTransactionTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNTransactionTest.m; sourceTree = "<group>"; };
311ADD192577482200A6E15E /* QNUploadBaseTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNUploadBaseTest.h; sourceTree = "<group>"; };
311ADD1A2577482200A6E15E /* QNUploadBaseTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNUploadBaseTest.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -602,12 +599,12 @@
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>"; };
45CBC6C22AA9B05A00962B47 /* QNFixZoneTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNFixZoneTest.m; sourceTree = "<group>"; };
45CBC6D02ABA9FFF00962B47 /* QNCache.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = QNCache.h; sourceTree = "<group>"; };
45CBC6D12ABA9FFF00962B47 /* QNCache.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNCache.m; sourceTree = "<group>"; };
45CBC6D62ABAE24900962B47 /* QNCacheTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNCacheTest.m; sourceTree = "<group>"; };
45E0B2892A1F0596009B1BC7 /* QNConfigurationTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = QNConfigurationTest.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>"; };
5F32D114A1227199BEC6DF5C /* libPods-QiniuSDK_iOSTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-QiniuSDK_iOSTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
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>"; };
6DD894AA2A19370381AD4201 /* Pods-QiniuSDK_iOSTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QiniuSDK_iOSTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-QiniuSDK_iOSTests/Pods-QiniuSDK_iOSTests.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -660,8 +657,6 @@
DFF525301A6235D100D02BA1 /* QNSessionManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QNSessionManager.m; sourceTree = "<group>"; };
DFF525381A64079B00D02BA1 /* QNSessionTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QNSessionTest.m; sourceTree = "<group>"; };
DFFE0E5F19E6575600D7A0FC /* QNFileRecorderTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QNFileRecorderTest.m; sourceTree = "<group>"; };
E98517EE5689BE11EA6791A5 /* libPods-QiniuSDK_Mac.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-QiniuSDK_Mac.a"; sourceTree = BUILT_PRODUCTS_DIR; };
F881668982449FAF2384327E /* libPods-QiniuSDK_iOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-QiniuSDK_iOS.a"; sourceTree = BUILT_PRODUCTS_DIR; };
FDEA88651DAC10D000D037E5 /* QNAutoZoneTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QNAutoZoneTest.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand All @@ -670,7 +665,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
8D0FB78D364BAEE65E20A604 /* libPods-QiniuSDK_iOS.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -679,7 +673,6 @@
buildActionMask = 2147483647;
files = (
DF293C9119DB85CB00799011 /* libz.dylib in Frameworks */,
12E9CD5CF6B4132A6ED0D7D4 /* libPods-QiniuSDK_Mac.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -689,7 +682,6 @@
files = (
DF0A03231B3BABEC00E3778C /* QiniuSDK_Mac.dylib in Frameworks */,
DF293C9219DB85EB00799011 /* libz.dylib in Frameworks */,
0CD9B2165D33CBCFF01AAE0B /* libPods-QiniuSDK_MacTests.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -698,7 +690,6 @@
buildActionMask = 2147483647;
files = (
DF0A03251B3BAC5700E3778C /* libQiniuSDK_iOS.a in Frameworks */,
C275A64FFBE81B9CE7DDC79E /* libPods-QiniuSDK_iOSTests.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -916,10 +907,6 @@
A955AABD20BF51BFE5032419 /* Frameworks */ = {
isa = PBXGroup;
children = (
E98517EE5689BE11EA6791A5 /* libPods-QiniuSDK_Mac.a */,
24BA93FDA4B776A502783C4A /* libPods-QiniuSDK_MacTests.a */,
F881668982449FAF2384327E /* libPods-QiniuSDK_iOS.a */,
5F32D114A1227199BEC6DF5C /* libPods-QiniuSDK_iOSTests.a */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down Expand Up @@ -1074,6 +1061,7 @@
316A4B822431C8BA007BF564 /* QNDnsPrefetcherTest.m */,
DFA9B63E19DFD8C900A15FD1 /* QNEtagTest.m */,
DFFE0E5F19E6575600D7A0FC /* QNFileRecorderTest.m */,
45CBC6C22AA9B05A00962B47 /* QNFixZoneTest.m */,
DF3C504619DD7BA6000F548F /* QNFormUploadTest.m */,
31259E3524E3D32700CF7531 /* QNGZipTest.m */,
31C30FAB2852EA7900BFD8F7 /* QNNetworkStatusTest.m */,
Expand Down Expand Up @@ -1649,6 +1637,7 @@
311ADD23257748A700A6E15E /* QNUploadFlowTest.m in Sources */,
DF437CDF1B243A2C0099587B /* QNUpTokenTest.m in Sources */,
31DD31D624971BD7004BFDDE /* QNUploadFileNameTest.m in Sources */,
45CBC6C32AA9B05A00962B47 /* QNFixZoneTest.m in Sources */,
31A74BCA26E8A89C001EC948 /* QNUplogTest.m in Sources */,
31A1840E246942E0001D6EEE /* QNComplexUploadSceneTest.m in Sources */,
DF3C504A19DD7D9F000F548F /* QNResumeUploadTest.m in Sources */,
Expand Down Expand Up @@ -1776,6 +1765,7 @@
311ADD24257748A700A6E15E /* QNUploadFlowTest.m in Sources */,
DF0A03281B3BAC6E00E3778C /* QNFormUploadTest.m in Sources */,
31DD31D724971BD7004BFDDE /* QNUploadFileNameTest.m in Sources */,
45CBC6C42AA9B05A00962B47 /* QNFixZoneTest.m in Sources */,
31A74BCB26E8A89C001EC948 /* QNUplogTest.m in Sources */,
31A1840F246942E0001D6EEE /* QNComplexUploadSceneTest.m in Sources */,
DF0A03291B3BAC6E00E3778C /* QNResumeUploadTest.m in Sources */,
Expand Down Expand Up @@ -1948,6 +1938,7 @@
GENERATE_PKGINFO_FILE = YES;
INFOPLIST_FILE = "";
MACOSX_DEPLOYMENT_TARGET = 10.14;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_NAME = QiniuSDK_Mac;
};
name = Release;
Expand Down Expand Up @@ -1984,6 +1975,7 @@
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
GENERATE_PKGINFO_FILE = YES;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_NAME = QiniuSDK_MacTests;
PROVISIONING_PROFILE_SPECIFIER = "";
};
Expand All @@ -2009,6 +2001,7 @@
COPY_PHASE_STRIP = YES;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GENERATE_PKGINFO_FILE = YES;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_NAME = QiniuSDK_iOS;
SDKROOT = iphoneos;
};
Expand Down
25 changes: 18 additions & 7 deletions QiniuSDK/Common/QNFixedZone.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "QNZone.h"
#import "QNDefine.h"

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -17,42 +18,42 @@ NS_ASSUME_NONNULL_BEGIN
*
* @return 实例
*/
+ (instancetype)zone0;
+ (instancetype)zone0 kQNDeprecated("use createWithRegionId instead");

/**
* zoneCnEast2 华东-浙江2
*
* @return 实例
*/
+ (instancetype)zoneCnEast2;
+ (instancetype)zoneCnEast2 kQNDeprecated("use createWithRegionId instead");

/**
* zone 1 华北
*
* @return 实例
*/
+ (instancetype)zone1;
+ (instancetype)zone1 kQNDeprecated("use createWithRegionId instead");

/**
* zone 2 华南
*
* @return 实例
*/
+ (instancetype)zone2;
+ (instancetype)zone2 kQNDeprecated("use createWithRegionId instead");

/**
* zone Na0 北美
*
* @return 实例
*/
+ (instancetype)zoneNa0;
+ (instancetype)zoneNa0 kQNDeprecated("use createWithRegionId instead");

/**
* zone As0 新加坡
*
* @return 实例
*/
+ (instancetype)zoneAs0;
+ (instancetype)zoneAs0 kQNDeprecated("use createWithRegionId instead");

/**
* Zone初始化方法
Expand All @@ -71,10 +72,20 @@ NS_ASSUME_NONNULL_BEGIN
*/
+ (instancetype)createWithHost:(NSArray<NSString *> *)upList;

/**
* Zone初始化方法
* regionId 参考链接:https://developer.qiniu.com/kodo/1671/region-endpoint-fq
*
* @param regionId 根据区域 ID 创建 Zone
*
* @return Zone 实例
*/
+ (instancetype)createWithRegionId:(NSString *)regionId;

/**
* 获取本地所有固定zone信息
*/
+ (QNFixedZone *)localsZoneInfo;
+ (QNFixedZone *)localsZoneInfo DEPRECATED_ATTRIBUTE;

/**
* 合并区域
Expand Down
8 changes: 8 additions & 0 deletions QiniuSDK/Common/QNFixedZone.m
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ + (instancetype)createWithHost:(NSArray<NSString *> *)upList {
return [[QNFixedZone alloc] initWithUpDomainList:upList oldUpList:nil regionId:nil];
}

+ (instancetype)createWithRegionId:(NSString *)regionId {
NSArray *upList = @[
[NSString stringWithFormat:@"upload-%@.qiniup.com", regionId],
[NSString stringWithFormat:@"up-%@.qiniup.com", regionId],
];
return [[QNFixedZone alloc] initWithUpDomainList:upList oldUpList:nil regionId:regionId];
}

- (QNZonesInfo *)createZonesInfo:(NSArray <NSString *> *)upDomains
regionId:(NSString *)regionId {
return [self createZonesInfo:upDomains oldUpDomains:nil regionId:regionId];
Expand Down
3 changes: 3 additions & 0 deletions QiniuSDK/Utils/QNDefine.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@

#define kQNWeakObj(object) __weak typeof(object) weak_##object = object
#define kQNStrongObj(object) __strong typeof(object) object = weak_##object

// 过期
#define kQNDeprecated(instead) NS_DEPRECATED(2_0, 2_0, 2_0, 2_0, instead)
36 changes: 36 additions & 0 deletions QiniuSDKTests/QNFixZoneTest.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// QNFixZoneTest.m
// QiniuSDK
//
// Created by yangsen on 2023/9/7.
// Copyright © 2023 Qiniu. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "QNFixedZone.h"
#import "QNZoneInfo.h"

@interface QNFixZoneTest : XCTestCase

@end

@implementation QNFixZoneTest

- (void)setUp {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

- (void)testCreateByRegionId {
QNFixedZone *zone = [QNFixedZone createWithRegionId:@"na0"];
QNZoneInfo *zoneInfo = [zone getZonesInfoWithToken:nil].zonesInfo[0];

XCTAssert([zoneInfo.regionId isEqualToString:@"na0"], @"regionId:%@", zoneInfo.regionId);
XCTAssert([zoneInfo.domains[0] isEqualToString:@"upload-na0.qiniup.com"], @"domains:%@", zoneInfo.domains);
XCTAssert([zoneInfo.domains[1] isEqualToString:@"up-na0.qiniup.com"], @"domains:%@", zoneInfo.domains);
}

@end

0 comments on commit 3db00f9

Please sign in to comment.