forked from qiniu/objc-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ef0c1d5
commit 42357ea
Showing
75 changed files
with
4,733 additions
and
616 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
QiniuSDK.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// QNAutoZone.h | ||
// QiniuSDK | ||
// | ||
// Created by yangsen on 2020/4/16. | ||
// Copyright © 2020 Qiniu. All rights reserved. | ||
// | ||
|
||
#import "QNZone.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface QNAutoZone : QNZone | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
// | ||
// QNAutoZone.m | ||
// QiniuSDK | ||
// | ||
// Created by yangsen on 2020/4/16. | ||
// Copyright © 2020 Qiniu. All rights reserved. | ||
// | ||
|
||
#import "QNAutoZone.h" | ||
#import "QNSessionManager.h" | ||
#import "QNZoneInfo.h" | ||
#import "QNUpToken.h" | ||
#import "QNResponseInfo.h" | ||
|
||
@interface QNAutoZoneCache : NSObject | ||
@property(nonatomic, strong)NSMutableDictionary *cache; | ||
@end | ||
@implementation QNAutoZoneCache | ||
|
||
+ (instancetype)share{ | ||
static QNAutoZoneCache *cache = nil; | ||
static dispatch_once_t onceToken; | ||
dispatch_once(&onceToken, ^{ | ||
cache = [[QNAutoZoneCache alloc] init]; | ||
[cache setupData]; | ||
}); | ||
return cache; | ||
} | ||
|
||
- (void)setupData{ | ||
self.cache = [NSMutableDictionary dictionary]; | ||
} | ||
|
||
- (void)cache:(NSDictionary *)zonesInfo | ||
forToken:(QNUpToken *)token{ | ||
|
||
NSString *cacheKey = token.index; | ||
if (!cacheKey || [cacheKey isEqualToString:@""]) { | ||
return; | ||
} | ||
|
||
@synchronized (self) { | ||
if (zonesInfo) { | ||
self.cache[cacheKey] = zonesInfo; | ||
} else { | ||
[self.cache removeObjectForKey:cacheKey]; | ||
} | ||
} | ||
} | ||
|
||
- (QNZonesInfo *)zonesInfoForToken:(QNUpToken *)token{ | ||
|
||
NSString *cacheKey = token.index; | ||
if (!cacheKey || [cacheKey isEqualToString:@""]) { | ||
return nil; | ||
} | ||
|
||
NSDictionary *zonesInfoDic = nil; | ||
@synchronized (self) { | ||
zonesInfoDic = self.cache[cacheKey]; | ||
} | ||
|
||
if (zonesInfoDic == nil) { | ||
return nil; | ||
} | ||
|
||
QNZonesInfo *zonesInfo = [QNZonesInfo buildZonesInfoWithResp:zonesInfoDic]; | ||
NSMutableArray *zonesInfoArray = [NSMutableArray array]; | ||
for (QNZoneInfo *zoneInfo in zonesInfo.zonesInfo) { | ||
if ([zoneInfo isValid]) { | ||
[zonesInfoArray addObject:zoneInfo]; | ||
} | ||
} | ||
zonesInfo.zonesInfo = [zonesInfoArray copy]; | ||
return zonesInfo; | ||
} | ||
|
||
@end | ||
|
||
@implementation QNAutoZone { | ||
NSString *server; | ||
NSMutableDictionary *cache; | ||
NSLock *lock; | ||
QNSessionManager *sesionManager; | ||
} | ||
|
||
- (instancetype)init{ | ||
if (self = [super init]) { | ||
server = @"https://uc.qbox.me"; | ||
cache = [NSMutableDictionary new]; | ||
lock = [NSLock new]; | ||
sesionManager = [[QNSessionManager alloc] initWithProxy:nil timeout:10 urlConverter:nil]; | ||
} | ||
return self; | ||
} | ||
|
||
- (NSString *)up:(QNUpToken *)token | ||
zoneInfoType:(QNZoneInfoType)zoneInfoType | ||
isHttps:(BOOL)isHttps | ||
frozenDomain:(NSString *)frozenDomain { | ||
|
||
NSString *index = [token index]; | ||
[lock lock]; | ||
QNZonesInfo *zonesInfo = [cache objectForKey:index]; | ||
[lock unlock]; | ||
if (zonesInfo == nil) { | ||
return nil; | ||
} | ||
return [self upHost:[zonesInfo getZoneInfoWithType:zoneInfoType] isHttps:isHttps lastUpHost:frozenDomain]; | ||
} | ||
|
||
- (QNZonesInfo *)getZonesInfoWithToken:(QNUpToken *)token { | ||
if (token == nil) return nil; | ||
[lock lock]; | ||
QNZonesInfo *zonesInfo = [cache objectForKey:[token index]]; | ||
[lock unlock]; | ||
return zonesInfo; | ||
} | ||
|
||
- (void)preQuery:(QNUpToken *)token | ||
on:(QNPrequeryReturn)ret { | ||
|
||
if (token == nil) { | ||
ret(-1, nil); | ||
return; | ||
} | ||
|
||
[lock lock]; | ||
QNZonesInfo *zonesInfo = [cache objectForKey:[token index]]; | ||
[lock unlock]; | ||
|
||
if (zonesInfo == nil) { | ||
zonesInfo = [[QNAutoZoneCache share] zonesInfoForToken:token]; | ||
[self->lock lock]; | ||
[self->cache setValue:zonesInfo forKey:[token index]]; | ||
[self->lock unlock]; | ||
} | ||
|
||
if (zonesInfo != nil) { | ||
ret(0, nil); | ||
return; | ||
} | ||
|
||
//https://uc.qbox.me/v3/query?ak=T3sAzrwItclPGkbuV4pwmszxK7Ki46qRXXGBBQz3&bucket=if-pbl | ||
NSString *url = [NSString stringWithFormat:@"%@/v3/query?ak=%@&bucket=%@", server, token.access, token.bucket]; | ||
[sesionManager get:url withHeaders:nil withCompleteBlock:^(QNHttpResponseInfo *httpResponseInfo, NSDictionary *respBody) { | ||
if (!httpResponseInfo.error) { | ||
|
||
QNZonesInfo *zonesInfo = [QNZonesInfo buildZonesInfoWithResp:respBody]; | ||
if (httpResponseInfo == nil) { | ||
ret(kQNInvalidToken, httpResponseInfo); | ||
} else { | ||
[self->lock lock]; | ||
[self->cache setValue:zonesInfo forKey:[token index]]; | ||
[self->lock unlock]; | ||
[[QNAutoZoneCache share] cache:respBody forToken:token]; | ||
ret(0, httpResponseInfo); | ||
} | ||
} else { | ||
ret(kQNNetworkError, httpResponseInfo); | ||
} | ||
}]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// | ||
// QNConfig.h | ||
// QiniuSDK | ||
// | ||
// Created by yangsen on 2020/3/26. | ||
// Copyright © 2020 Qiniu. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
//MArk: -- 内部布置 尽量不要修改 | ||
#define kQNPreQueryHost @"uc.qbox.me" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// | ||
// QNFixZone.h | ||
// QiniuSDK | ||
// | ||
// Created by yangsen on 2020/4/16. | ||
// Copyright © 2020 Qiniu. All rights reserved. | ||
// | ||
|
||
#import "QNZone.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface QNFixedZone : QNZone | ||
|
||
/** | ||
* zone 0 华东 | ||
* | ||
* @return 实例 | ||
*/ | ||
+ (instancetype)zone0; | ||
|
||
/** | ||
* zone 1 华北 | ||
* | ||
* @return 实例 | ||
*/ | ||
+ (instancetype)zone1; | ||
|
||
/** | ||
* zone 2 华南 | ||
* | ||
* @return 实例 | ||
*/ | ||
+ (instancetype)zone2; | ||
|
||
/** | ||
* zone Na0 北美 | ||
* | ||
* @return 实例 | ||
*/ | ||
+ (instancetype)zoneNa0; | ||
|
||
/** | ||
* zone As0 新加坡 | ||
* | ||
* @return 实例 | ||
*/ | ||
+ (instancetype)zoneAs0; | ||
|
||
/** | ||
* Zone初始化方法 | ||
* | ||
* @param upList 默认上传服务器地址列表 | ||
* @param zoneRegion 区域 | ||
* @return Zone实例 | ||
*/ | ||
- (instancetype)initWithupDomainList:(NSArray<NSString *> *)upList; | ||
|
||
/** | ||
* Zone初始化方法 | ||
* | ||
* @param upList 默认上传服务器地址列表 | ||
* | ||
* @return Zone实例 | ||
*/ | ||
+ (instancetype)createWithHost:(NSArray<NSString *> *)upList; | ||
|
||
/** | ||
* 获取本地所有固定zone信息 | ||
*/ | ||
+ (NSArray <QNFixedZone *> *)localsZoneInfo; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
Oops, something went wrong.