解决了语音上传到问题,接下来要解决下载播放问题
This commit is contained in:
27
Pods/Qiniu/QiniuSDK/Common/QNAutoZone.h
generated
Normal file
27
Pods/Qiniu/QiniuSDK/Common/QNAutoZone.h
generated
Normal file
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// QNAutoZone.h
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2020/4/16.
|
||||
// Copyright © 2020 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QNZone.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class QNFixedZone;
|
||||
@interface QNAutoZone : QNZone
|
||||
|
||||
+ (instancetype)zoneWithUcHosts:(NSArray *)ucHosts;
|
||||
|
||||
+ (void)clearCache;
|
||||
|
||||
/**
|
||||
* 当 查询失败时,会使用 zones 进行上传,默认不配置。
|
||||
*/
|
||||
- (void)setDefaultZones:(NSArray <QNFixedZone *> *)zones;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
254
Pods/Qiniu/QiniuSDK/Common/QNAutoZone.m
generated
Normal file
254
Pods/Qiniu/QiniuSDK/Common/QNAutoZone.m
generated
Normal file
@@ -0,0 +1,254 @@
|
||||
//
|
||||
// QNAutoZone.m
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2020/4/16.
|
||||
// Copyright © 2020 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QNDefine.h"
|
||||
#import "QNCache.h"
|
||||
#import "QNUtils.h"
|
||||
#import "QNAutoZone.h"
|
||||
#import "QNConfig.h"
|
||||
#import "QNRequestTransaction.h"
|
||||
#import "QNZoneInfo.h"
|
||||
#import "QNUpToken.h"
|
||||
#import "QNUploadOption.h"
|
||||
#import "QNConfiguration.h"
|
||||
#import "QNResponseInfo.h"
|
||||
#import "QNFixedZone.h"
|
||||
#import "QNSingleFlight.h"
|
||||
#import "QNFileRecorder.h"
|
||||
#import "QNUrlSafeBase64.h"
|
||||
#import "QNUploadRequestMetrics.h"
|
||||
|
||||
@interface QNUCQuerySingleFlightValue : NSObject
|
||||
|
||||
@property(nonatomic, strong) QNResponseInfo *responseInfo;
|
||||
@property(nonatomic, strong) NSDictionary *response;
|
||||
@property(nonatomic, strong) QNUploadRegionRequestMetrics *metrics;
|
||||
|
||||
@end
|
||||
|
||||
@implementation QNUCQuerySingleFlightValue
|
||||
@end
|
||||
|
||||
@interface QNAutoZone ()
|
||||
|
||||
@property(nonatomic, strong) NSArray *ucHosts;
|
||||
@property(nonatomic, strong) QNFixedZone *defaultZone;
|
||||
// 已经查询到的区域信息
|
||||
@property(nonatomic, strong) NSMutableDictionary <NSString *, QNZonesInfo *> *zonesDic;
|
||||
@property(nonatomic, strong) NSMutableArray <QNRequestTransaction *> *transactions;
|
||||
|
||||
@end
|
||||
|
||||
@implementation QNAutoZone
|
||||
|
||||
+ (QNSingleFlight *)UCQuerySingleFlight {
|
||||
static QNSingleFlight *singleFlight = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
singleFlight = [[QNSingleFlight alloc] init];
|
||||
});
|
||||
return singleFlight;
|
||||
}
|
||||
|
||||
+ (instancetype)zoneWithUcHosts:(NSArray *)ucHosts {
|
||||
QNAutoZone *zone = [[self alloc] init];
|
||||
zone.ucHosts = [ucHosts copy];
|
||||
return zone;
|
||||
}
|
||||
|
||||
+ (QNCache *)zoneShareCache {
|
||||
static QNCache *queryCache;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
QNCacheOption *option = [[QNCacheOption alloc] init];
|
||||
option.version = @"v2";
|
||||
queryCache = [QNCache cache:[QNZonesInfo class] option:option];
|
||||
});
|
||||
return queryCache;
|
||||
}
|
||||
|
||||
+ (void)clearCache {
|
||||
[[QNAutoZone zoneShareCache] clearMemoryCache];
|
||||
[[QNAutoZone zoneShareCache] clearDiskCache];
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
if (self = [super init]) {
|
||||
_zonesDic = [NSMutableDictionary dictionary];
|
||||
_transactions = [NSMutableArray array];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setDefaultZones:(NSArray <QNFixedZone *> *)zones {
|
||||
self.defaultZone = [QNFixedZone combineZones:zones];
|
||||
}
|
||||
|
||||
- (QNZonesInfo *)getZonesInfoWithToken:(QNUpToken *_Nullable)token {
|
||||
|
||||
if (token == nil) return nil;
|
||||
NSString *cacheKey = [self makeCacheKey:[QNConfiguration defaultConfiguration] akAndBucket:token.index];
|
||||
QNZonesInfo *zonesInfo = nil;
|
||||
@synchronized (self) {
|
||||
zonesInfo = self.zonesDic[cacheKey];
|
||||
}
|
||||
zonesInfo = [zonesInfo copy];
|
||||
return zonesInfo;
|
||||
}
|
||||
|
||||
- (void)setZonesInfo:(QNZonesInfo *)info forKey:(NSString *)key {
|
||||
if (info == nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
@synchronized (self) {
|
||||
self.zonesDic[key] = info;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)preQuery:(QNUpToken *)token on:(QNPrequeryReturn)ret {
|
||||
[self query:[QNConfiguration defaultConfiguration] token:token on:^(QNResponseInfo * _Nullable responseInfo, QNUploadRegionRequestMetrics * _Nullable metrics, QNZonesInfo * _Nullable zonesInfo) {
|
||||
if (!ret) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (responseInfo.isOK) {
|
||||
ret(0, responseInfo, metrics);
|
||||
} else {
|
||||
ret(responseInfo.statusCode, responseInfo, metrics);
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)query:(QNConfiguration *)config token:(QNUpToken *)token on:(QNQueryReturn)ret {
|
||||
if (token == nil || ![token isValid]) {
|
||||
ret([QNResponseInfo responseInfoWithInvalidToken:@"invalid token"], nil, nil);
|
||||
return;
|
||||
}
|
||||
|
||||
QNUploadRegionRequestMetrics *cacheMetrics = [QNUploadRegionRequestMetrics emptyMetrics];
|
||||
[cacheMetrics start];
|
||||
|
||||
|
||||
NSString *cacheKey = [self makeCacheKey:config akAndBucket:token.index];
|
||||
QNZonesInfo *zonesInfo = [[QNAutoZone zoneShareCache] cacheForKey:cacheKey];
|
||||
|
||||
// 临时的 zonesInfo 仅能使用一次
|
||||
if (zonesInfo != nil && zonesInfo.isValid && !zonesInfo.isTemporary) {
|
||||
[cacheMetrics end];
|
||||
[self setZonesInfo:zonesInfo forKey:cacheKey];
|
||||
ret([QNResponseInfo successResponse], cacheMetrics, zonesInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
kQNWeakSelf;
|
||||
QNSingleFlight *singleFlight = [QNAutoZone UCQuerySingleFlight];
|
||||
[singleFlight perform:token.index action:^(QNSingleFlightComplete _Nonnull complete) {
|
||||
kQNStrongSelf;
|
||||
QNRequestTransaction *transaction = [self createUploadRequestTransaction:config token:token];
|
||||
|
||||
kQNWeakSelf;
|
||||
kQNWeakObj(transaction);
|
||||
[transaction queryUploadHosts:^(QNResponseInfo *_Nullable responseInfo, QNUploadRegionRequestMetrics *_Nullable metrics, NSDictionary *_Nullable response) {
|
||||
kQNStrongSelf;
|
||||
kQNStrongObj(transaction);
|
||||
|
||||
QNUCQuerySingleFlightValue *value = [[QNUCQuerySingleFlightValue alloc] init];
|
||||
value.responseInfo = responseInfo;
|
||||
value.response = response;
|
||||
value.metrics = metrics;
|
||||
complete(value, nil);
|
||||
|
||||
[self destroyUploadRequestTransaction:transaction];
|
||||
}];
|
||||
|
||||
} complete:^(id _Nullable value, NSError *_Nullable error) {
|
||||
kQNStrongSelf;
|
||||
|
||||
QNResponseInfo *responseInfo = [(QNUCQuerySingleFlightValue *) value responseInfo];
|
||||
NSDictionary *response = [(QNUCQuerySingleFlightValue *) value response];
|
||||
QNUploadRegionRequestMetrics *metrics = [(QNUCQuerySingleFlightValue *) value metrics];
|
||||
|
||||
if (responseInfo && responseInfo.isOK) {
|
||||
QNZonesInfo *zonesInfo = [QNZonesInfo infoWithDictionary:response];
|
||||
if ([zonesInfo isValid]) {
|
||||
[self setZonesInfo:zonesInfo forKey:cacheKey];
|
||||
[[QNAutoZone zoneShareCache] cache:zonesInfo forKey:cacheKey atomically:false];
|
||||
ret(responseInfo, metrics, zonesInfo);
|
||||
} else {
|
||||
responseInfo = [QNResponseInfo errorResponseInfo:NSURLErrorCannotDecodeRawData errorDesc:[NSString stringWithFormat:@"origin response:%@", responseInfo]];
|
||||
ret(responseInfo, metrics, nil);
|
||||
}
|
||||
} else {
|
||||
if (self.defaultZone != nil) {
|
||||
// 备用只能用一次
|
||||
QNZonesInfo *info = [self.defaultZone getZonesInfoWithToken:token];
|
||||
[self setZonesInfo:info forKey:cacheKey];
|
||||
responseInfo = [QNResponseInfo successResponseWithDesc:[NSString stringWithFormat:@"origin response:%@", responseInfo]];
|
||||
ret(responseInfo, metrics, info);
|
||||
} else if (zonesInfo != nil) {
|
||||
// 缓存有,但是失效也可使用
|
||||
[self setZonesInfo:zonesInfo forKey:cacheKey];
|
||||
responseInfo = [QNResponseInfo successResponseWithDesc:[NSString stringWithFormat:@"origin response:%@", responseInfo]];
|
||||
ret(responseInfo, metrics, zonesInfo);
|
||||
} else {
|
||||
ret(responseInfo, metrics, nil);
|
||||
}
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (QNRequestTransaction *)createUploadRequestTransaction:(QNConfiguration *)config token:(QNUpToken *)token {
|
||||
if (config == nil) {
|
||||
config = [QNConfiguration defaultConfiguration];
|
||||
}
|
||||
|
||||
NSArray *hosts = nil;
|
||||
if (self.ucHosts && self.ucHosts.count > 0) {
|
||||
hosts = [self.ucHosts copy];
|
||||
} else {
|
||||
hosts = kQNPreQueryHosts;
|
||||
}
|
||||
QNRequestTransaction *transaction = [[QNRequestTransaction alloc] initWithConfig:config
|
||||
uploadOption:[QNUploadOption defaultOptions]
|
||||
hosts:hosts
|
||||
regionId:QNZoneInfoEmptyRegionId
|
||||
key:@""
|
||||
token:token];
|
||||
@synchronized (self) {
|
||||
[self.transactions addObject:transaction];
|
||||
}
|
||||
return transaction;
|
||||
}
|
||||
|
||||
- (void)destroyUploadRequestTransaction:(QNRequestTransaction *)transaction {
|
||||
if (transaction) {
|
||||
@synchronized (self) {
|
||||
[self.transactions removeObject:transaction];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)makeCacheKey:(QNConfiguration *)config akAndBucket:(NSString *)akAndBucket {
|
||||
NSString *key = akAndBucket;
|
||||
if (config != nil) {
|
||||
key = [NSString stringWithFormat:@"%@:%d",key, config.accelerateUploading];
|
||||
}
|
||||
|
||||
NSString *hosts = @"";
|
||||
for (NSString *host in self.ucHosts) {
|
||||
if (!host) {
|
||||
continue;
|
||||
}
|
||||
hosts = [NSString stringWithFormat:@"%@:%@", hosts, host];
|
||||
}
|
||||
NSString *cacheKey = [NSString stringWithFormat:@"%@:%@", hosts, key];
|
||||
return [QNUrlSafeBase64 encodeString:cacheKey];
|
||||
}
|
||||
|
||||
@end
|
||||
18
Pods/Qiniu/QiniuSDK/Common/QNConfig.h
generated
Normal file
18
Pods/Qiniu/QiniuSDK/Common/QNConfig.h
generated
Normal file
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// QNConfig.h
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2020/3/26.
|
||||
// Copyright © 2020 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
//MARK: -- 内部布置 尽量不要修改
|
||||
#define kQNPreQueryHost00 @"uc.qiniuapi.com"
|
||||
#define kQNPreQueryHost01 @"kodo-config.qiniuapi.com"
|
||||
#define kQNPreQueryHost02 @"uc.qbox.me"
|
||||
#define kQNPreQueryHost03 @"api.qiniu.com"
|
||||
#define kQNPreQueryHosts @[kQNPreQueryHost00, kQNPreQueryHost01, kQNPreQueryHost02]
|
||||
|
||||
#define kQNUpLogHost @"uplog.qbox.me"
|
||||
68
Pods/Qiniu/QiniuSDK/Common/QNErrorCode.h
generated
Normal file
68
Pods/Qiniu/QiniuSDK/Common/QNErrorCode.h
generated
Normal file
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// QNErrorCode.h
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2020/10/21.
|
||||
// Copyright © 2020 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
/**
|
||||
* StatusCode >= 100 见:https://developer.qiniu.com/kodo/3928/error-responses
|
||||
* 除上述链接及下面定义外的状态码依据 iOS 标准库定义
|
||||
*/
|
||||
|
||||
/**
|
||||
* 中途取消的状态码
|
||||
*/
|
||||
extern const int kQNRequestCancelled;
|
||||
|
||||
/**
|
||||
* 网络错误状态码
|
||||
*/
|
||||
extern const int kQNNetworkError;
|
||||
|
||||
/**
|
||||
* 错误参数状态码
|
||||
*/
|
||||
extern const int kQNInvalidArgument;
|
||||
|
||||
/**
|
||||
* 0 字节文件或数据
|
||||
*/
|
||||
extern const int kQNZeroDataSize;
|
||||
|
||||
/**
|
||||
* 错误token状态码
|
||||
*/
|
||||
extern const int kQNInvalidToken;
|
||||
|
||||
/**
|
||||
* 读取文件错误状态码
|
||||
*/
|
||||
extern const int kQNFileError;
|
||||
|
||||
/**
|
||||
* 本地 I/O 错误
|
||||
*/
|
||||
extern const int kQNLocalIOError;
|
||||
|
||||
/**
|
||||
* ⽤户劫持错误 错误
|
||||
*/
|
||||
extern const int kQNMaliciousResponseError;
|
||||
|
||||
/**
|
||||
* 没有可用的Host 错误【废弃】
|
||||
*/
|
||||
extern const int kQNNoUsableHostError NS_UNAVAILABLE;
|
||||
|
||||
/**
|
||||
* SDK 内部错误
|
||||
*/
|
||||
extern const int kQNSDKInteriorError;
|
||||
|
||||
/**
|
||||
* 非预期的系统调用 错误
|
||||
*/
|
||||
extern const int kQNUnexpectedSysCallError;
|
||||
25
Pods/Qiniu/QiniuSDK/Common/QNErrorCode.m
generated
Normal file
25
Pods/Qiniu/QiniuSDK/Common/QNErrorCode.m
generated
Normal file
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// QNErrorCode.m
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2020/10/21.
|
||||
// Copyright © 2020 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QNErrorCode.h"
|
||||
|
||||
const int kQNUnexpectedSysCallError = -10;
|
||||
const int kQNNoUsableHostError = -9;
|
||||
const int kQNSDKInteriorError = -9;
|
||||
const int kQNMaliciousResponseError = -8;
|
||||
const int kQNLocalIOError = -7;
|
||||
const int kQNZeroDataSize = -6;
|
||||
const int kQNInvalidToken = -5;
|
||||
const int kQNFileError = -4;
|
||||
const int kQNInvalidArgument = -3;
|
||||
const int kQNRequestCancelled = -2;
|
||||
const int kQNNetworkError = -1;
|
||||
|
||||
|
||||
|
||||
|
||||
112
Pods/Qiniu/QiniuSDK/Common/QNFixedZone.h
generated
Normal file
112
Pods/Qiniu/QiniuSDK/Common/QNFixedZone.h
generated
Normal file
@@ -0,0 +1,112 @@
|
||||
//
|
||||
// QNFixZone.h
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2020/4/16.
|
||||
// Copyright © 2020 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QNZone.h"
|
||||
#import "QNDefine.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface QNFixedZone : QNZone
|
||||
|
||||
/**
|
||||
* zone 0 华东
|
||||
*
|
||||
* @return 实例
|
||||
*/
|
||||
+ (instancetype)zone0 kQNDeprecated("use createWithRegionId instead");
|
||||
|
||||
/**
|
||||
* zoneCnEast2 华东-浙江2
|
||||
*
|
||||
* @return 实例
|
||||
*/
|
||||
+ (instancetype)zoneCnEast2 kQNDeprecated("use createWithRegionId instead");
|
||||
|
||||
/**
|
||||
* zone 1 华北
|
||||
*
|
||||
* @return 实例
|
||||
*/
|
||||
+ (instancetype)zone1 kQNDeprecated("use createWithRegionId instead");
|
||||
|
||||
/**
|
||||
* zone 2 华南
|
||||
*
|
||||
* @return 实例
|
||||
*/
|
||||
+ (instancetype)zone2 kQNDeprecated("use createWithRegionId instead");
|
||||
|
||||
/**
|
||||
* zone Na0 北美
|
||||
*
|
||||
* @return 实例
|
||||
*/
|
||||
+ (instancetype)zoneNa0 kQNDeprecated("use createWithRegionId instead");
|
||||
|
||||
/**
|
||||
* zone As0 新加坡
|
||||
*
|
||||
* @return 实例
|
||||
*/
|
||||
+ (instancetype)zoneAs0 kQNDeprecated("use createWithRegionId instead");
|
||||
|
||||
/**
|
||||
* Zone初始化方法
|
||||
*
|
||||
* @param upList 默认上传服务器地址列表
|
||||
* @return Zone实例
|
||||
*/
|
||||
- (instancetype)initWithUpDomainList:(NSArray<NSString *> *)upList;
|
||||
|
||||
|
||||
/**
|
||||
* Zone初始化方法
|
||||
*
|
||||
* @param accUpList 加速上传服务器地址列表
|
||||
* @param upList 默认上传服务器地址列表
|
||||
* @param oldUpList 支持 SNI 的上传服务器地址列表
|
||||
* @param regionId 区域 ID
|
||||
* @return Zone实例
|
||||
*/
|
||||
- (instancetype)initWithAccUpDomainList:(NSArray<NSString *> *)accUpList
|
||||
upList:(NSArray<NSString *> *)upList
|
||||
oldUpList:(NSArray<NSString *> *)oldUpList
|
||||
regionId:(NSString *)regionId;
|
||||
|
||||
/**
|
||||
* Zone初始化方法
|
||||
*
|
||||
* @param upList 默认上传服务器地址列表
|
||||
*
|
||||
* @return Zone实例
|
||||
*/
|
||||
+ (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 DEPRECATED_ATTRIBUTE;
|
||||
|
||||
/**
|
||||
* 合并区域
|
||||
*/
|
||||
+ (QNFixedZone *)combineZones:(NSArray<QNFixedZone *> *)zones;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
199
Pods/Qiniu/QiniuSDK/Common/QNFixedZone.m
generated
Normal file
199
Pods/Qiniu/QiniuSDK/Common/QNFixedZone.m
generated
Normal file
@@ -0,0 +1,199 @@
|
||||
//
|
||||
// QNFixZone.m
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2020/4/16.
|
||||
// Copyright © 2020 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QNFixedZone.h"
|
||||
#import "QNZoneInfo.h"
|
||||
#import "QNResponseInfo.h"
|
||||
|
||||
@interface QNFixedZone ()
|
||||
|
||||
@property (nonatomic, strong) QNZonesInfo *zonesInfo;
|
||||
|
||||
@end
|
||||
|
||||
@implementation QNFixedZone
|
||||
|
||||
+ (instancetype)zone0 {
|
||||
static QNFixedZone *z0 = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
z0 = [[QNFixedZone alloc] initWithUpDomainList:@[@"upload.qiniup.com", @"up.qiniup.com"]
|
||||
oldUpList:@[@"upload.qbox.me", @"up.qbox.me"]
|
||||
regionId:@"z0"];
|
||||
});
|
||||
return z0;
|
||||
}
|
||||
|
||||
+ (instancetype)zoneCnEast2 {
|
||||
static QNFixedZone *zoneCnEast2 = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
zoneCnEast2 = [[QNFixedZone alloc] initWithUpDomainList:@[@"upload-cn-east-2.qiniup.com", @"up-cn-east-2.qiniup.com"]
|
||||
oldUpList:nil
|
||||
regionId:@"cn-east-2"];
|
||||
});
|
||||
return zoneCnEast2;
|
||||
}
|
||||
|
||||
+ (instancetype)zone1 {
|
||||
static QNFixedZone *z1 = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
z1 = [[QNFixedZone alloc] initWithUpDomainList:@[@"upload-z1.qiniup.com", @"up-z1.qiniup.com"]
|
||||
oldUpList:@[@"upload-z1.qbox.me", @"up-z1.qbox.me"]
|
||||
regionId:@"z1"];
|
||||
});
|
||||
return z1;
|
||||
}
|
||||
|
||||
+ (instancetype)zone2 {
|
||||
static QNFixedZone *z2 = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
z2 = [[QNFixedZone alloc] initWithUpDomainList:@[@"upload-z2.qiniup.com", @"up-z2.qiniup.com"]
|
||||
oldUpList:@[@"upload-z2.qbox.me", @"up-z2.qbox.me"]
|
||||
regionId:@"z2"];
|
||||
});
|
||||
return z2;
|
||||
}
|
||||
|
||||
+ (instancetype)zoneNa0 {
|
||||
static QNFixedZone *zNa0 = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
zNa0 = [[QNFixedZone alloc] initWithUpDomainList:@[@"upload-na0.qiniup.com", @"up-na0.qiniup.com"]
|
||||
oldUpList:@[@"upload-na0.qbox.me", @"up-na0.qbox.me"]
|
||||
regionId:@"na0"];
|
||||
});
|
||||
return zNa0;
|
||||
}
|
||||
|
||||
+ (instancetype)zoneAs0 {
|
||||
static QNFixedZone *zAs0 = nil;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
zAs0 = [[QNFixedZone alloc] initWithUpDomainList:@[@"upload-as0.qiniup.com", @"up-as0.qiniup.com"]
|
||||
oldUpList:@[@"upload-as0.qbox.me", @"up-as0.qbox.me"]
|
||||
regionId:@"as0"];;
|
||||
});
|
||||
return zAs0;
|
||||
}
|
||||
|
||||
+ (QNFixedZone *)localsZoneInfo{
|
||||
|
||||
NSArray *zones = @[[QNFixedZone zone0],
|
||||
[QNFixedZone zone1],
|
||||
[QNFixedZone zone2],
|
||||
[QNFixedZone zoneCnEast2],
|
||||
[QNFixedZone zoneNa0],
|
||||
[QNFixedZone zoneAs0]];
|
||||
QNFixedZone *zone = [self combineZones:zones];
|
||||
if (zone) {
|
||||
[zone.zonesInfo toTemporary];
|
||||
}
|
||||
return zone;
|
||||
}
|
||||
|
||||
+ (QNFixedZone *)combineZones:(NSArray<QNFixedZone *> *)zones {
|
||||
if (zones == nil || zones.count == 0) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSMutableArray <QNZoneInfo *> *zoneInfoArray = [NSMutableArray array];
|
||||
for (QNFixedZone *zone in zones) {
|
||||
if (zone.zonesInfo.zonesInfo) {
|
||||
[zoneInfoArray addObjectsFromArray:zone.zonesInfo.zonesInfo];
|
||||
}
|
||||
}
|
||||
|
||||
QNFixedZone *fixedZone = [[QNFixedZone alloc] init];
|
||||
fixedZone.zonesInfo = [[QNZonesInfo alloc] initWithZonesInfo:[zoneInfoArray copy]];
|
||||
[fixedZone.zonesInfo toTemporary];
|
||||
return fixedZone;
|
||||
}
|
||||
|
||||
+ (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];
|
||||
}
|
||||
|
||||
- (QNZonesInfo *)createZonesInfo:(NSArray <NSString *> *)upDomains
|
||||
oldUpDomains:(NSArray <NSString *> *)oldUpDomains
|
||||
regionId:(NSString *)regionId {
|
||||
return [self createZonesInfo:nil domains:upDomains oldDomains:oldUpDomains regionId:regionId];
|
||||
}
|
||||
|
||||
- (QNZonesInfo *)createZonesInfo:(NSArray <NSString *> *)accDomains
|
||||
domains:(NSArray <NSString *> *)domains
|
||||
oldDomains:(NSArray <NSString *> *)oldDomains
|
||||
regionId:(NSString *)regionId {
|
||||
if ((!accDomains || accDomains.count == 0) && (!domains || domains.count == 0)) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
QNZoneInfo *zoneInfo = [QNZoneInfo zoneInfoWithAccHosts:accDomains
|
||||
mainHosts:domains
|
||||
oldHosts:oldDomains
|
||||
regionId:regionId];
|
||||
QNZonesInfo *zonesInfo = [[QNZonesInfo alloc] initWithZonesInfo:@[zoneInfo]];
|
||||
return zonesInfo;
|
||||
}
|
||||
|
||||
- (instancetype)initWithUpDomainList:(NSArray<NSString *> *)upList {
|
||||
if (self = [super init]) {
|
||||
self.zonesInfo = [self createZonesInfo:upList regionId:nil];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
- (instancetype)initWithUpDomainList:(NSArray<NSString *> *)upList
|
||||
regionId:(NSString *)regionId {
|
||||
if (self = [super init]) {
|
||||
self.zonesInfo = [self createZonesInfo:upList regionId:regionId];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
- (instancetype)initWithUpDomainList:(NSArray<NSString *> *)upList
|
||||
oldUpList:(NSArray<NSString *> *)oldUpList
|
||||
regionId:(NSString *)regionId {
|
||||
if (self = [super init]) {
|
||||
self.zonesInfo = [self createZonesInfo:upList oldUpDomains:oldUpList regionId:regionId];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
- (instancetype)initWithAccUpDomainList:(NSArray<NSString *> *)accUpList
|
||||
upList:(NSArray<NSString *> *)upList
|
||||
oldUpList:(NSArray<NSString *> *)oldUpList
|
||||
regionId:(NSString *)regionId {
|
||||
if (self = [super init]) {
|
||||
self.zonesInfo = [self createZonesInfo:accUpList domains:upList oldDomains:oldUpList regionId:regionId];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (QNZonesInfo *)getZonesInfoWithToken:(QNUpToken *)token {
|
||||
return self.zonesInfo;
|
||||
}
|
||||
|
||||
- (void)query:(QNConfiguration * _Nullable)config token:(QNUpToken * _Nullable)token on:(QNQueryReturn _Nullable)ret {
|
||||
ret([QNResponseInfo successResponse], nil, self.zonesInfo);
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
38
Pods/Qiniu/QiniuSDK/Common/QNZone.h
generated
Normal file
38
Pods/Qiniu/QiniuSDK/Common/QNZone.h
generated
Normal file
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// QNZone.h
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2020/4/16.
|
||||
// Copyright © 2020 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class QNConfiguration, QNResponseInfo, QNUpToken, QNZonesInfo, QNUploadRegionRequestMetrics;
|
||||
|
||||
typedef void (^QNPrequeryReturn)(int code, QNResponseInfo * _Nullable httpResponseInfo, QNUploadRegionRequestMetrics * _Nullable metrics);
|
||||
typedef void (^QNQueryReturn)(QNResponseInfo * _Nullable httpResponseInfo, QNUploadRegionRequestMetrics * _Nullable metrics, QNZonesInfo * _Nullable zonesInfo);
|
||||
|
||||
@interface QNZone : NSObject
|
||||
|
||||
/// 根据token查询相关 Zone 信息【内部使用】
|
||||
/// @param token token 信息
|
||||
/// @param ret 查询回调
|
||||
- (void)preQuery:(QNUpToken * _Nullable)token on:(QNPrequeryReturn _Nullable)ret;
|
||||
|
||||
/// 根据token获取ZonesInfo 【内部使用】
|
||||
/// @param token token信息
|
||||
- (QNZonesInfo *)getZonesInfoWithToken:(QNUpToken * _Nullable)token;
|
||||
|
||||
|
||||
/// 根据token查询相关 Zone 信息【内部使用】
|
||||
/// @param config 配置信息
|
||||
/// @param token token 信息
|
||||
/// @param ret 查询回调
|
||||
- (void)query:(QNConfiguration * _Nullable)config token:(QNUpToken * _Nullable)token on:(QNQueryReturn _Nullable)ret;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
30
Pods/Qiniu/QiniuSDK/Common/QNZone.m
generated
Normal file
30
Pods/Qiniu/QiniuSDK/Common/QNZone.m
generated
Normal file
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// QNZone.m
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2020/4/16.
|
||||
// Copyright © 2020 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QNZone.h"
|
||||
#import "QNUpToken.h"
|
||||
#import "QNZoneInfo.h"
|
||||
#import "QNConfiguration.h"
|
||||
#import "QNResponseInfo.h"
|
||||
|
||||
@implementation QNZone
|
||||
|
||||
- (QNZonesInfo *)getZonesInfoWithToken:(QNUpToken *)token {
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)preQuery:(QNUpToken *)token
|
||||
on:(QNPrequeryReturn)ret {
|
||||
ret(0, nil, nil);
|
||||
}
|
||||
|
||||
- (void)query:(QNConfiguration * _Nullable)config token:(QNUpToken * _Nullable)token on:(QNQueryReturn _Nullable)ret {
|
||||
ret([QNResponseInfo responseInfoWithSDKInteriorError:@"impl query"], nil, nil);
|
||||
}
|
||||
|
||||
@end
|
||||
68
Pods/Qiniu/QiniuSDK/Common/QNZoneInfo.h
generated
Normal file
68
Pods/Qiniu/QiniuSDK/Common/QNZoneInfo.h
generated
Normal file
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// QNZoneInfo.h
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2020/4/16.
|
||||
// Copyright © 2020 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QNCache.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
extern NSString *const QNZoneInfoSDKDefaultIOHost;
|
||||
extern NSString *const QNZoneInfoEmptyRegionId;
|
||||
|
||||
@interface QNZoneInfo : NSObject
|
||||
|
||||
@property(nonatomic, assign, readonly)long ttl;
|
||||
@property(nonatomic, assign, readonly)BOOL http3Enabled;
|
||||
@property(nonatomic, strong, readonly)NSArray<NSString *> *domains;
|
||||
@property(nonatomic, strong, readonly)NSArray<NSString *> *acc_domains;
|
||||
@property(nonatomic, strong, readonly)NSArray<NSString *> *old_domains;
|
||||
|
||||
@property(nonatomic, copy, readonly)NSString *regionId;
|
||||
@property(nonatomic, strong, readonly)NSArray <NSString *> *allHosts;
|
||||
@property(nonatomic, strong, readonly)NSDictionary *detailInfo;
|
||||
|
||||
+ (QNZoneInfo *)zoneInfoWithMainHosts:(NSArray <NSString *> *)mainHosts
|
||||
regionId:(NSString * _Nullable)regionId;
|
||||
|
||||
|
||||
+ (QNZoneInfo *)zoneInfoWithMainHosts:(NSArray <NSString *> *)mainHosts
|
||||
oldHosts:(NSArray <NSString *> * _Nullable)oldHosts
|
||||
regionId:(NSString * _Nullable)regionId;
|
||||
|
||||
+ (QNZoneInfo *)zoneInfoWithAccHosts:(NSArray <NSString *> *)accHosts
|
||||
mainHosts:(NSArray <NSString *> *)mainHosts
|
||||
oldHosts:(NSArray <NSString *> * _Nullable)oldHosts
|
||||
regionId:(NSString * _Nullable)regionId;
|
||||
|
||||
/// 根据键值对构造对象 【内部使用】
|
||||
/// @param detailInfo 键值对信息
|
||||
+ (QNZoneInfo *)zoneInfoFromDictionary:(NSDictionary *)detailInfo;
|
||||
|
||||
- (BOOL)isValid;
|
||||
|
||||
@end
|
||||
|
||||
@interface QNZonesInfo : NSObject <QNCacheObject>
|
||||
|
||||
@property (nonatomic, strong, readonly) NSDate *buildDate;
|
||||
@property (nonatomic, assign, readonly) BOOL isTemporary;
|
||||
@property (nonatomic, assign, readonly) BOOL isValid;
|
||||
@property (nonatomic, strong, readonly) NSArray<QNZoneInfo *> *zonesInfo;
|
||||
|
||||
/// 根据键值对构造对象 【内部使用】
|
||||
/// @param dictionary 键值对信息
|
||||
+ (instancetype)infoWithDictionary:(NSDictionary *)dictionary;
|
||||
|
||||
- (instancetype)initWithZonesInfo:(NSArray<QNZoneInfo *> *)zonesInfo;
|
||||
|
||||
// 转成临时 zones, 临时 Zones,不建议长期使用
|
||||
- (void)toTemporary;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
250
Pods/Qiniu/QiniuSDK/Common/QNZoneInfo.m
generated
Normal file
250
Pods/Qiniu/QiniuSDK/Common/QNZoneInfo.m
generated
Normal file
@@ -0,0 +1,250 @@
|
||||
//
|
||||
// QNZoneInfo.m
|
||||
// QiniuSDK
|
||||
//
|
||||
// Created by yangsen on 2020/4/16.
|
||||
// Copyright © 2020 Qiniu. All rights reserved.
|
||||
//
|
||||
|
||||
#import "QNZoneInfo.h"
|
||||
#import "QNUtils.h"
|
||||
|
||||
NSString * const QNZoneInfoSDKDefaultIOHost = @"default_io_host";
|
||||
NSString * const QNZoneInfoEmptyRegionId = @"none";
|
||||
|
||||
@interface QNZoneInfo()
|
||||
|
||||
@property(nonatomic, strong) NSDate *buildDate;
|
||||
|
||||
@property(nonatomic, copy) NSString *regionId;
|
||||
@property(nonatomic, assign) long ttl;
|
||||
@property(nonatomic, assign) BOOL http3Enabled;
|
||||
@property(nonatomic, strong) NSArray<NSString *> *domains;
|
||||
@property(nonatomic, strong) NSArray<NSString *> *acc_domains;
|
||||
@property(nonatomic, strong) NSArray<NSString *> *old_domains;
|
||||
|
||||
@property(nonatomic, strong) NSArray <NSString *> *allHosts;
|
||||
@property(nonatomic, strong) NSDictionary *detailInfo;
|
||||
|
||||
@end
|
||||
@implementation QNZoneInfo
|
||||
|
||||
+ (QNZoneInfo *)zoneInfoWithMainHosts:(NSArray <NSString *> *)mainHosts
|
||||
regionId:(NSString * _Nullable)regionId{
|
||||
return [self zoneInfoWithMainHosts:mainHosts oldHosts:nil regionId:regionId];
|
||||
}
|
||||
|
||||
+ (QNZoneInfo *)zoneInfoWithMainHosts:(NSArray <NSString *> *)mainHosts
|
||||
oldHosts:(NSArray <NSString *> * _Nullable)oldHosts
|
||||
regionId:(NSString * _Nullable)regionId{
|
||||
|
||||
if (!mainHosts || ![mainHosts isKindOfClass:[NSArray class]] || mainHosts.count == 0) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (mainHosts && ![mainHosts isKindOfClass:[NSArray class]]) {
|
||||
mainHosts = nil;
|
||||
}
|
||||
|
||||
QNZoneInfo *zoneInfo = [QNZoneInfo zoneInfoFromDictionary:@{@"ttl" : @(-1),
|
||||
@"region" : regionId ?: QNZoneInfoEmptyRegionId,
|
||||
@"up" : @{@"domains" : mainHosts ?: @[],
|
||||
@"old" : oldHosts ?: @[]},
|
||||
}];
|
||||
return zoneInfo;
|
||||
}
|
||||
|
||||
+ (QNZoneInfo *)zoneInfoWithAccHosts:(NSArray <NSString *> *)accHosts
|
||||
mainHosts:(NSArray <NSString *> *)mainHosts
|
||||
oldHosts:(NSArray <NSString *> * _Nullable)oldHosts
|
||||
regionId:(NSString * _Nullable)regionId {
|
||||
if ((!accHosts || ![accHosts isKindOfClass:[NSArray class]] || accHosts.count == 0) &&
|
||||
(!mainHosts || ![mainHosts isKindOfClass:[NSArray class]] || mainHosts.count == 0)) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (accHosts && ![accHosts isKindOfClass:[NSArray class]]) {
|
||||
accHosts = nil;
|
||||
}
|
||||
|
||||
if (mainHosts && ![mainHosts isKindOfClass:[NSArray class]]) {
|
||||
mainHosts = nil;
|
||||
}
|
||||
|
||||
QNZoneInfo *zoneInfo = [QNZoneInfo zoneInfoFromDictionary:@{@"ttl" : @(-1),
|
||||
@"region" : regionId ?: QNZoneInfoEmptyRegionId,
|
||||
@"up" : @{@"acc_domains" : accHosts ?: @[],
|
||||
@"domains" : mainHosts ?: @[],
|
||||
@"old" : oldHosts ?: @[]},
|
||||
}];
|
||||
return zoneInfo;
|
||||
}
|
||||
|
||||
+ (QNZoneInfo *)zoneInfoFromDictionary:(NSDictionary *)detail {
|
||||
if (![detail isKindOfClass:[NSDictionary class]]) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSMutableDictionary *detailInfo = [detail mutableCopy];
|
||||
if (detailInfo[@"timestamp"] == nil) {
|
||||
detailInfo[@"timestamp"] = @([QNUtils currentTimestamp]/1000);
|
||||
}
|
||||
long timestamp = [detailInfo[@"timestamp"] longValue];
|
||||
|
||||
NSString *regionId = [detailInfo objectForKey:@"region"];
|
||||
if (regionId == nil) {
|
||||
regionId = QNZoneInfoEmptyRegionId;
|
||||
}
|
||||
long ttl = [[detailInfo objectForKey:@"ttl"] longValue];
|
||||
BOOL http3Enabled = false;
|
||||
if ([detailInfo[@"features"] isKindOfClass:[NSDictionary class]] &&
|
||||
[detailInfo[@"features"][@"http3"] isKindOfClass:[NSDictionary class]]) {
|
||||
http3Enabled = [detailInfo[@"features"][@"http3"][@"enabled"] boolValue];
|
||||
}
|
||||
NSDictionary *up = [detailInfo objectForKey:@"up"];
|
||||
NSArray *acc_domains = [up objectForKey:@"acc_domains"];
|
||||
NSArray *domains = [up objectForKey:@"domains"];
|
||||
NSArray *old_domains = [up objectForKey:@"old"];
|
||||
|
||||
NSMutableArray *allHosts = [NSMutableArray array];
|
||||
QNZoneInfo *zoneInfo = [[QNZoneInfo alloc] init:ttl regionId:regionId];
|
||||
zoneInfo.buildDate = [NSDate dateWithTimeIntervalSince1970:timestamp];
|
||||
zoneInfo.http3Enabled = http3Enabled;
|
||||
if ([acc_domains isKindOfClass:[NSArray class]]) {
|
||||
zoneInfo.acc_domains = acc_domains;
|
||||
[allHosts addObjectsFromArray:domains];
|
||||
}
|
||||
if ([domains isKindOfClass:[NSArray class]]) {
|
||||
zoneInfo.domains = domains;
|
||||
[allHosts addObjectsFromArray:domains];
|
||||
}
|
||||
if ([old_domains isKindOfClass:[NSArray class]]) {
|
||||
zoneInfo.old_domains = old_domains;
|
||||
[allHosts addObjectsFromArray:old_domains];
|
||||
}
|
||||
zoneInfo.allHosts = [allHosts copy];
|
||||
|
||||
zoneInfo.detailInfo = [detailInfo copy];
|
||||
|
||||
return zoneInfo;
|
||||
}
|
||||
|
||||
- (instancetype)init:(long)ttl
|
||||
regionId:(NSString *)regionId {
|
||||
if (self = [super init]) {
|
||||
_ttl = ttl;
|
||||
_buildDate = [NSDate date];
|
||||
_regionId = regionId;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)isValid{
|
||||
if (self.allHosts == nil || self.allHosts.count == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (self.ttl < 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
NSDate *currentDate = [NSDate date];
|
||||
return self.ttl > [currentDate timeIntervalSinceDate:self.buildDate];
|
||||
}
|
||||
|
||||
- (id)copyWithZone:(NSZone *)zone {
|
||||
QNZoneInfo *zoneInfo = [[QNZoneInfo allocWithZone:zone] init];
|
||||
zoneInfo.ttl = self.ttl;
|
||||
zoneInfo.buildDate = self.buildDate;
|
||||
zoneInfo.http3Enabled = self.http3Enabled;
|
||||
zoneInfo.regionId = self.regionId;
|
||||
zoneInfo.domains = [self.domains copy];
|
||||
zoneInfo.old_domains = [self.old_domains copy];
|
||||
zoneInfo.allHosts = [self.allHosts copy];
|
||||
zoneInfo.detailInfo = [self.detailInfo copy];
|
||||
return zoneInfo;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@interface QNZonesInfo()
|
||||
@property (nonatomic, strong) NSDate *buildDate;
|
||||
@property (nonatomic, assign) BOOL isTemporary;
|
||||
@property (nonatomic, strong) NSArray<QNZoneInfo *> *zonesInfo;
|
||||
@property (nonatomic, strong) NSDictionary *detailInfo;
|
||||
@end
|
||||
@implementation QNZonesInfo
|
||||
|
||||
+ (instancetype)infoWithDictionary:(NSDictionary *)dictionary {
|
||||
return [[self alloc] initWithDictionary:dictionary];
|
||||
}
|
||||
|
||||
- (nonnull id<QNCacheObject>)initWithDictionary:(nullable NSDictionary *)dictionary {
|
||||
NSMutableArray *zonesInfo = [NSMutableArray array];
|
||||
NSArray *hosts = dictionary[@"hosts"];
|
||||
if ([hosts isKindOfClass:[NSArray class]]) {
|
||||
for (NSInteger i = 0; i < hosts.count; i++) {
|
||||
QNZoneInfo *zoneInfo = [QNZoneInfo zoneInfoFromDictionary:hosts[i]];
|
||||
if (zoneInfo && [zoneInfo allHosts].count > 0) {
|
||||
[zonesInfo addObject:zoneInfo];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [self initWithZonesInfo:zonesInfo];
|
||||
}
|
||||
|
||||
- (instancetype)initWithZonesInfo:(NSArray<QNZoneInfo *> *)zonesInfo{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_buildDate = [NSDate date];
|
||||
_zonesInfo = zonesInfo;
|
||||
NSMutableArray *zoneInfos = [NSMutableArray array];
|
||||
if (zonesInfo != nil) {
|
||||
for (NSInteger i = 0; i < zonesInfo.count; i++) {
|
||||
if (zonesInfo[i].detailInfo != nil) {
|
||||
[zoneInfos addObject:zonesInfo[i].detailInfo];
|
||||
}
|
||||
}
|
||||
}
|
||||
self.detailInfo = @{@"hosts": [zoneInfos copy]};
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)toTemporary {
|
||||
_isTemporary = true;
|
||||
}
|
||||
|
||||
- (BOOL)isValid {
|
||||
if ([self.zonesInfo count] == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
BOOL valid = true;
|
||||
for (QNZoneInfo *info in self.zonesInfo) {
|
||||
if (![info isValid]) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
- (id)copyWithZone:(NSZone *)zone {
|
||||
NSMutableArray *zonesInfoArray = [NSMutableArray array];
|
||||
for (QNZoneInfo *info in self.zonesInfo) {
|
||||
[zonesInfoArray addObject:[info copy]];
|
||||
}
|
||||
QNZonesInfo *zonesInfo = [[QNZonesInfo allocWithZone:zone] init];
|
||||
zonesInfo.zonesInfo = [zonesInfoArray copy];
|
||||
zonesInfo.isTemporary = self.isTemporary;
|
||||
return zonesInfo;
|
||||
}
|
||||
|
||||
- (nullable NSDictionary *)toDictionary {
|
||||
return [self.detailInfo copy];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user