Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source 'https://github.com/CocoaPods/Specs.git'

def shared_dependencies
# pod 'HappyDNS', '>= 0.3'
pod 'HappyDNS', '0.3.16'
end

def test_dependencies
Expand Down
1 change: 1 addition & 0 deletions QiniuDemo/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ source 'https://github.com/CocoaPods/Specs.git'
target "QiniuDemo" do
platform :ios, "7.0"
pod 'Qiniu',:path => '../'
pod 'HappyDNS', :path => '../../HappyDns_iOS'
end

target "QiniuDemoTests" do
Expand Down
26 changes: 26 additions & 0 deletions QiniuDemo/QiniuDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

#import "ViewController.h"
#import "QNTransactionManager.h"

@interface ViewController () <UINavigationControllerDelegate, UIImagePickerControllerDelegate>

Expand Down Expand Up @@ -112,6 +113,31 @@ - (NSString *)getImagePath:(UIImage *)Image {
return filePath;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

// QNTransaction *t0 = [QNTransaction transaction:@"0" after:0 action:^{
// NSLog(@"== 0 == %@", [NSThread currentThread]);
// }];
// QNTransaction *t1 = [QNTransaction timeTransaction:@"1" after:0 interval:2 action:^{
// NSLog(@"== 1 == %@", [NSThread currentThread]);
// NSDate *date_from = [NSDate date];
// NSDate *date_current = [NSDate date];
//
// while ([date_current timeIntervalSinceDate:date_from] < 3) {
// date_current = [NSDate date];
// }
// }];
// QNTransactionManager *manager = [QNTransactionManager manager];
//
// [manager destroyResource];
// [manager addTransaction:t0];
// [manager addTransaction:t1];
//
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(20 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// [manager destroyResource];
// });
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
Expand Down
472 changes: 351 additions & 121 deletions QiniuSDK.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

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>
14 changes: 14 additions & 0 deletions QiniuSDK.xcodeproj/xcshareddata/xcschemes/QiniuSDK_Mac.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@
ReferencedContainer = "container:QiniuSDK.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "NO"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DF2CDE0919DAC05500CE01FB"
BuildableName = "QiniuSDK_MacTests.xctest"
BlueprintName = "QiniuSDK_MacTests"
ReferencedContainer = "container:QiniuSDK.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
Expand Down
14 changes: 14 additions & 0 deletions QiniuSDK.xcodeproj/xcshareddata/xcschemes/QiniuSDK_iOS.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@
ReferencedContainer = "container:QiniuSDK.xcodeproj">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "NO"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DF2CDE2319DAC08400CE01FB"
BuildableName = "QiniuSDK_iOSTests.xctest"
BlueprintName = "QiniuSDK_iOSTests"
ReferencedContainer = "container:QiniuSDK.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
Expand Down
17 changes: 17 additions & 0 deletions QiniuSDK/Common/QNAutoZone.h
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
165 changes: 165 additions & 0 deletions QiniuSDK/Common/QNAutoZone.m
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
12 changes: 12 additions & 0 deletions QiniuSDK/Common/QNConfig.h
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"
75 changes: 75 additions & 0 deletions QiniuSDK/Common/QNFixedZone.h
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
Loading