Skip to content

Commit 9183fad

Browse files
committed
format
1 parent 871ef57 commit 9183fad

File tree

11 files changed

+182
-147
lines changed

11 files changed

+182
-147
lines changed

QiniuSDK/Common/QNAsyncRun.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#import <Foundation/Foundation.h>
1010
#import "QNAsyncRun.h"
1111

12-
void QNAsyncRun(QNRun run){
13-
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
14-
run();
15-
});
16-
}
12+
void QNAsyncRun(QNRun run) {
13+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
14+
run();
15+
});
16+
}

QiniuSDK/Common/QNConfig.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88

99
#import <Foundation/Foundation.h>
1010

11-
extern NSString *const kQNUndefinedKey;
1211
extern NSString *const kQNUpHost;
12+
1313
extern NSString *const kQNUpHostBackup;
14+
1415
extern const UInt32 kQNChunkSize;
16+
1517
extern const UInt32 kQNBlockSize;
16-
extern const UInt32 kQNRetryMax;
17-
extern const UInt32 kQNPutThreshold;
1818

19-
@interface QNConfig : NSObject
19+
extern const UInt32 kQNRetryMax;
2020

21-
@end
21+
extern const UInt32 kQNPutThreshold;

QiniuSDK/Common/QNConfig.m

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,10 @@
88

99
#import "QNConfig.h"
1010

11-
NSString *const kQNUndefinedKey = @"?";
1211
NSString *const kQNUpHost = @"upload.qiniu.com";
1312
NSString *const kQNUpHostBackup = @"up.qiniu.com";
1413
const UInt32 kQNChunkSize = 256 * 1024;
1514
const UInt32 kQNBlockSize = 4 * 1024 * 1024;
1615
const UInt32 kQNPutThreshold = 512 * 1024;
1716

1817
const UInt32 kQNRetryMax = 3;
19-
20-
@implementation QNConfig
21-
22-
@end

QiniuSDK/Common/QNUrlSafeBase64.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010
@interface QNUrlSafeBase64 : NSObject
1111

1212
+ (NSString *)encodeString:(NSString *)source;
13+
1314
+ (NSString *)encodeData:(NSData *)source;
15+
1416
@end

QiniuSDK/Common/QNVersion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88

99
#import <Foundation/Foundation.h>
1010

11-
static const NSString *kQiniuVersion = @"7.0.3";
11+
static const NSString *kQiniuVersion = @"7.0.4";

QiniuSDK/Http/QNHttpManager.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ + (QNResponseInfo *)buildResponseInfo:(AFHTTPRequestOperation *)operation
3939
info = [[QNResponseInfo alloc] init:status withReqId:reqId withXLog:xlog withBody:responseObject];
4040
}
4141
else {
42-
info = [QNResponseInfo responseInfoWithNetError:error];
42+
info = [QNResponseInfo responseInfoWithNetError:error];
4343
}
4444
return info;
4545
}

QiniuSDK/Http/QNResponseInfo.m

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,38 @@
2020
@implementation QNResponseInfo
2121

2222
+ (instancetype)cancel {
23-
return [[QNResponseInfo alloc] initWithCancelled];
23+
return [[QNResponseInfo alloc] initWithCancelled];
2424
}
2525

26-
+ (instancetype)responseInfoWithInvalidArgument:(NSString *)text{
27-
return [[QNResponseInfo alloc] initWithStatus:kQNInvalidArgument errorDescription:text];
26+
+ (instancetype)responseInfoWithInvalidArgument:(NSString *)text {
27+
return [[QNResponseInfo alloc] initWithStatus:kQNInvalidArgument errorDescription:text];
2828
}
2929

3030
+ (instancetype)responseInfoWithNetError:(NSError *)error {
31-
return [[QNResponseInfo alloc] initWithStatus:kQNNetworkError error:error];
31+
return [[QNResponseInfo alloc] initWithStatus:kQNNetworkError error:error];
3232
}
3333

3434
+ (instancetype)responseInfoWithFileError:(NSError *)error {
35-
return [[QNResponseInfo alloc] initWithStatus:kQNFileError error:error];
35+
return [[QNResponseInfo alloc] initWithStatus:kQNFileError error:error];
3636
}
3737

3838
- (instancetype)initWithCancelled {
39-
return [self initWithStatus:kQNRequestCancelled errorDescription:@"cancelled by user"];
39+
return [self initWithStatus:kQNRequestCancelled errorDescription:@"cancelled by user"];
4040
}
4141

4242
- (instancetype)initWithStatus:(int)status
43-
error:(NSError*)error{
44-
if (self = [super init]) {
45-
_statusCode = status;
46-
_error = error;
47-
}
48-
return self;
43+
error:(NSError *)error {
44+
if (self = [super init]) {
45+
_statusCode = status;
46+
_error = error;
47+
}
48+
return self;
4949
}
5050

5151
- (instancetype)initWithStatus:(int)status
52-
errorDescription:(NSString*)text{
53-
NSError *error = [[NSError alloc] initWithDomain:@"qiniu" code:status userInfo:@{ @"error":text}];
54-
return [self initWithStatus:status error:error];
52+
errorDescription:(NSString *)text {
53+
NSError *error = [[NSError alloc] initWithDomain:@"qiniu" code:status userInfo:@{ @"error":text }];
54+
return [self initWithStatus:status error:error];
5555
}
5656

5757
- (instancetype)init:(int)status
@@ -84,22 +84,19 @@ - (NSString *)description {
8484
}
8585

8686
- (BOOL)isCancelled {
87-
return _statusCode == kQNRequestCancelled;
87+
return _statusCode == kQNRequestCancelled;
8888
}
8989

9090
- (BOOL)isOK {
91-
return _statusCode == 200;
91+
return _statusCode == 200;
9292
}
9393

9494
- (BOOL)isConnectionBroken {
95-
return _statusCode == kQNNetworkError;
95+
return _statusCode == kQNNetworkError;
9696
}
9797

9898
- (BOOL)couldRetry {
99-
return (_statusCode >= 500 && _statusCode < 600 && _statusCode != 579) || _statusCode == kQNNetworkError || _statusCode == 996 || _statusCode == 406;
99+
return (_statusCode >= 500 && _statusCode < 600 && _statusCode != 579) || _statusCode == kQNNetworkError || _statusCode == 996 || _statusCode == 406;
100100
}
101101

102-
103-
104-
105102
@end

QiniuSDK/Storage/QNUploadManager.m

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -55,49 +55,48 @@ + (instancetype)sharedInstanceWithRecorder:(id <QNRecorderDelegate> )recorder
5555
return sharedInstance;
5656
}
5757

58-
+ (BOOL)checkAndNotifyError:(NSString*)key
59-
token:(NSString*)token
60-
data:(NSData*)data
58+
+ (BOOL)checkAndNotifyError:(NSString *)key
59+
token:(NSString *)token
60+
data:(NSData *)data
6161
file:(NSString *)file
62-
complete:(QNUpCompletionHandler)completionHandler {
63-
NSString *desc = nil;
64-
if (completionHandler == nil) {
65-
@throw [NSException exceptionWithName:NSInvalidArgumentException
66-
reason:@"no completionHandler" userInfo:nil];
67-
return YES;
68-
}
69-
if (data == nil && file == nil) {
70-
desc = @"no input data";
71-
}else if (token == nil || [token isEqualToString:@""] ){
72-
desc = @"no token";
73-
}
74-
if (desc != nil) {
75-
QNAsyncRun(^{
76-
completionHandler([QNResponseInfo responseInfoWithInvalidArgument:desc], key, nil);
77-
});
78-
return YES;
79-
}
80-
return NO;
62+
complete:(QNUpCompletionHandler)completionHandler {
63+
NSString *desc = nil;
64+
if (completionHandler == nil) {
65+
@throw [NSException exceptionWithName:NSInvalidArgumentException
66+
reason:@"no completionHandler" userInfo:nil];
67+
return YES;
68+
}
69+
if (data == nil && file == nil) {
70+
desc = @"no input data";
71+
}
72+
else if (token == nil || [token isEqualToString:@""]) {
73+
desc = @"no token";
74+
}
75+
if (desc != nil) {
76+
QNAsyncRun ( ^{
77+
completionHandler([QNResponseInfo responseInfoWithInvalidArgument:desc], key, nil);
78+
});
79+
return YES;
80+
}
81+
return NO;
8182
}
8283

83-
8484
- (void)putData:(NSData *)data
8585
key:(NSString *)key
8686
token:(NSString *)token
8787
complete:(QNUpCompletionHandler)completionHandler
8888
option:(QNUploadOption *)option {
8989
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
90-
91-
if ([QNUploadManager checkAndNotifyError:key token:token data:data file:nil complete:completionHandler]){
92-
return;
93-
}
9490

95-
if (key && ![key isEqualToString:kQNUndefinedKey]) {
91+
if ([QNUploadManager checkAndNotifyError:key token:token data:data file:nil complete:completionHandler]) {
92+
return;
93+
}
94+
NSString *fileName = key;
95+
if (key) {
9696
parameters[@"key"] = key;
9797
}
98-
99-
if (!key) {
100-
key = kQNUndefinedKey;
98+
else {
99+
fileName = @"?";
101100
}
102101

103102
parameters[@"token"] = token;
@@ -152,7 +151,7 @@ - (void)putData:(NSData *)data
152151
[_httpManager multipartPost:[NSString stringWithFormat:@"http://%@", nextHost]
153152
withData:data
154153
withParams:parameters
155-
withFileName:key
154+
withFileName:fileName
156155
withMimeType:mimeType
157156
withCompleteBlock:retriedComplete
158157
withProgressBlock:p
@@ -162,7 +161,7 @@ - (void)putData:(NSData *)data
162161
[_httpManager multipartPost:[NSString stringWithFormat:@"http://%@", kQNUpHost]
163162
withData:data
164163
withParams:parameters
165-
withFileName:key
164+
withFileName:fileName
166165
withMimeType:mimeType
167166
withCompleteBlock:complete
168167
withProgressBlock:p
@@ -174,17 +173,17 @@ - (void)putFile:(NSString *)filePath
174173
token:(NSString *)token
175174
complete:(QNUpCompletionHandler)completionHandler
176175
option:(QNUploadOption *)option {
177-
if ([QNUploadManager checkAndNotifyError:key token:token data:nil file:filePath complete:completionHandler]){
178-
return;
179-
}
176+
if ([QNUploadManager checkAndNotifyError:key token:token data:nil file:filePath complete:completionHandler]) {
177+
return;
178+
}
180179

181180
@autoreleasepool {
182181
NSError *error = nil;
183182
NSDictionary *fileAttr = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:&error];
184183

185184
if (error) {
186-
QNAsyncRun(^{
187-
QNResponseInfo *info = [QNResponseInfo responseInfoWithFileError:error];
185+
QNAsyncRun ( ^{
186+
QNResponseInfo *info = [QNResponseInfo responseInfoWithFileError:error];
188187
completionHandler(info, key, nil);
189188
});
190189
return;
@@ -194,7 +193,7 @@ - (void)putFile:(NSString *)filePath
194193
UInt32 fileSize = [fileSizeNumber intValue];
195194
NSData *data = [NSData dataWithContentsOfFile:filePath options:NSDataReadingMappedIfSafe error:&error];
196195
if (error) {
197-
QNAsyncRun(^{
196+
QNAsyncRun ( ^{
198197
QNResponseInfo *info = [QNResponseInfo responseInfoWithFileError:error];
199198
completionHandler(info, key, nil);
200199
});
@@ -227,9 +226,9 @@ - (void)putFile:(NSString *)filePath
227226
withRecorder:_recorder
228227
withRecorderKey:recorderKey
229228
withHttpManager:_httpManager];
230-
QNAsyncRun(^{
231-
[up run];
232-
});
229+
QNAsyncRun ( ^{
230+
[up run];
231+
});
233232
}
234233
}
235234

QiniuSDK/Storage/QNUploadOption.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ + (NSDictionary *)filteParam:(NSDictionary *)params {
2727
NSEnumerator *e = [params keyEnumerator];
2828
for (NSString *key = [e nextObject]; key != nil; key = [e nextObject]) {
2929
if ([key hasPrefix:@"x:"]) {
30-
ret[key] = params[key];
30+
id val = params[key];
31+
if (val != nil) {
32+
ret[key] = params[key];
33+
}
3134
}
3235
}
3336
}

0 commit comments

Comments
 (0)