diff --git a/AVOS/LeanCloudObjcTests/BaseTestCase.swift b/AVOS/LeanCloudObjcTests/BaseTestCase.swift index d0c941ef..1ae4f95e 100644 --- a/AVOS/LeanCloudObjcTests/BaseTestCase.swift +++ b/AVOS/LeanCloudObjcTests/BaseTestCase.swift @@ -54,6 +54,12 @@ class BaseTestCase: XCTestCase { // serverURL: "https://beta.leancloud.cn", masterKey: "Q26gTodbyi1Ki7lM9vtncF6U,master") + static let tds1App = AppInfo( + id: "7DY3DVgOQogGnYMMUajgvPRq-TjsS5DXC", + key: "RJOLaAvGiF7mQguXp68W9Mv5", + serverURL: "https://7DY3DVgO.cloud.tds1.tapapis.cn", + masterKey: "3PSWpjByenawCVo0FpnXfNgx") + static let ceApp = AppInfo( id: "skhiVsqIk7NLVdtHaUiWn0No-9Nh9j0Va", key: "T3TEAIcL8Ls5XGPsGz41B1bz", @@ -68,6 +74,7 @@ class BaseTestCase: XCTestCase { static let appInfoTable = [ cnApp.id : cnApp, + tds1App.id : tds1App, ceApp.id : ceApp, usApp.id : usApp, ] diff --git a/AVOS/Sources/Foundation/Request/LCPaasClient.h b/AVOS/Sources/Foundation/Request/LCPaasClient.h index 00178dbb..877166c0 100644 --- a/AVOS/Sources/Foundation/Request/LCPaasClient.h +++ b/AVOS/Sources/Foundation/Request/LCPaasClient.h @@ -59,10 +59,19 @@ FOUNDATION_EXPORT NSString * const LCHeaderFieldNameProduction; - (void)getObject:(NSString *)path withParameters:(NSDictionary *)parameters block:(LCIdResultBlock)block; +- (void)getObject:(NSString *)path + paddingVersion:(BOOL)paddingVersion + withParameters:(NSDictionary *)parameters + block:(LCIdResultBlock)block; - (void)getObject:(NSString *)path withParameters:(NSDictionary *)parameters block:(LCIdResultBlock)block wait:(BOOL)wait; +- (void)getObject:(NSString *)path + paddingVersion:(BOOL)paddingVersion + withParameters:(NSDictionary *)parameters + block:(LCIdResultBlock)block + wait:(BOOL)wait; - (void)getObject:(NSString *)path withParameters:(NSDictionary *)parameters policy:(LCCachePolicy)policy @@ -117,6 +126,12 @@ FOUNDATION_EXPORT NSString * const LCHeaderFieldNameProduction; headers:(NSDictionary *)headers parameters:(id)parameters; +- (NSMutableURLRequest *)requestWithPath:(NSString *)path + method:(NSString *)method + headers:(NSDictionary *)headers + parameters:(id)parameters + paddingVersion:(BOOL)paddingVersion; + - (void)performRequest:(NSURLRequest *)request success:(void (^)(NSHTTPURLResponse *response, id responseObject))successBlock failure:(void (^)(NSHTTPURLResponse *response, id responseObject, NSError *error))failureBlock; diff --git a/AVOS/Sources/Foundation/Request/LCPaasClient.m b/AVOS/Sources/Foundation/Request/LCPaasClient.m index 0c10c90c..f1209a4f 100644 --- a/AVOS/Sources/Foundation/Request/LCPaasClient.m +++ b/AVOS/Sources/Foundation/Request/LCPaasClient.m @@ -214,11 +214,22 @@ - (NSMutableURLRequest *)requestWithPath:(NSString *)path method:(NSString *)method headers:(NSDictionary *)headers parameters:(id)parameters +{ + return [self requestWithPath:path method:method headers:headers parameters:parameters paddingVersion:true]; +} + +- (NSMutableURLRequest *)requestWithPath:(NSString *)path + method:(NSString *)method + headers:(NSDictionary *)headers + parameters:(id)parameters + paddingVersion:(BOOL)paddingVersion { NSURL *URL = [NSURL URLWithString:path]; if (!URL.scheme.length) { - NSString *URLString = [[LCRouter sharedInstance] appURLForPath:path appID:[LCApplication getApplicationId]]; + NSString *URLString = [[LCRouter sharedInstance] appURLForPath:path + appID:[LCApplication getApplicationId] + paddingVersion:paddingVersion]; URL = [NSURL URLWithString:URLString]; } @@ -258,21 +269,72 @@ - (NSMutableURLRequest *)requestWithPath:(NSString *)path return request; } -- (void)getObject:(NSString *)path withParameters:(NSDictionary *)parameters block:(LCIdResultBlock)block { - [self getObject:path withParameters:parameters block:block wait:false]; +- (void)getObject:(NSString *)path + withParameters:(NSDictionary *)parameters + block:(LCIdResultBlock)block { + [self getObject:path + paddingVersion:true + withParameters:parameters + block:block]; +} + +- (void)getObject:(NSString *)path + paddingVersion:(BOOL)paddingVersion + withParameters:(NSDictionary *)parameters + block:(LCIdResultBlock)block { + [self getObject:path + paddingVersion:paddingVersion + withParameters:parameters + block:block + wait:false]; } -- (void)getObject:(NSString *)path withParameters:(NSDictionary *)parameters block:(LCIdResultBlock)block wait:(BOOL)wait { - [self getObjectFromNetworkWithPath:path withParameters:parameters policy:kLCCachePolicyIgnoreCache block:block wait:wait]; +- (void)getObject:(NSString *)path + withParameters:(NSDictionary *)parameters + block:(LCIdResultBlock)block + wait:(BOOL)wait { + [self getObjectFromNetworkWithPath:path + withParameters:parameters + policy:kLCCachePolicyIgnoreCache + block:block + wait:wait]; +} + +- (void)getObject:(NSString *)path + paddingVersion:(BOOL)paddingVersion + withParameters:(NSDictionary *)parameters + block:(LCIdResultBlock)block + wait:(BOOL)wait { + [self getObjectFromNetworkWithPath:path + paddingVersion:paddingVersion + withParameters:parameters + policy:kLCCachePolicyIgnoreCache + block:block + wait:wait]; +} + +- (void)getObjectFromNetworkWithPath:(NSString *)path + withParameters:(NSDictionary *)parameters + policy:(LCCachePolicy)policy + block:(LCIdResultBlock)block + wait:(BOOL)wait +{ + [self getObjectFromNetworkWithPath:path + paddingVersion:true + withParameters:parameters + policy:policy + block:block + wait:wait]; } - (void)getObjectFromNetworkWithPath:(NSString *)path + paddingVersion:(BOOL)paddingVersion withParameters:(NSDictionary *)parameters policy:(LCCachePolicy)policy block:(LCIdResultBlock)block wait:(BOOL)wait { - NSURLRequest *request = [self requestWithPath:path method:@"GET" headers:nil parameters:parameters]; + NSURLRequest *request = [self requestWithPath:path method:@"GET" headers:nil parameters:parameters paddingVersion:paddingVersion]; if (parameters && request.URL.absoluteString.length > 4096) { /* If GET request too heavy, wrap it into a POST request and ignore cache policy. */ diff --git a/AVOS/Sources/Foundation/Router/LCRouter.m b/AVOS/Sources/Foundation/Router/LCRouter.m index c81477f2..8782f532 100644 --- a/AVOS/Sources/Foundation/Router/LCRouter.m +++ b/AVOS/Sources/Foundation/Router/LCRouter.m @@ -228,6 +228,11 @@ - (void)tryUpdateAppRouterWithAppID:(NSString *)appID callback:(void (^)(NSError } - (NSString *)appURLForPath:(NSString *)path appID:(NSString *)appID +{ + return [self appURLForPath:path appID:appID paddingVersion:true]; +} + +- (NSString *)appURLForPath:(NSString *)path appID:(NSString *)appID paddingVersion:(BOOL)paddingVersion { NSParameterAssert(path); NSParameterAssert(appID); @@ -238,7 +243,7 @@ - (NSString *)appURLForPath:(NSString *)path appID:(NSString *)appID if ([serverKey isEqualToString:RouterKeyAppRTMRouterServer]) { return absoluteURLStringWithHostAndPath(host, path); } else { - return absoluteURLStringWithHostAndPath(host, pathWithVersion(path)); + return absoluteURLStringWithHostAndPath(host, paddingVersion ? pathWithVersion(path) : path); } }; diff --git a/AVOS/Sources/Foundation/Router/LCRouter_Internal.h b/AVOS/Sources/Foundation/Router/LCRouter_Internal.h index 76e69aee..f755147e 100644 --- a/AVOS/Sources/Foundation/Router/LCRouter_Internal.h +++ b/AVOS/Sources/Foundation/Router/LCRouter_Internal.h @@ -63,6 +63,8 @@ static RouterKey RouterKeyRTMServer = @"server"; - (NSString *)appURLForPath:(NSString *)path appID:(NSString *)appID; +- (NSString *)appURLForPath:(NSString *)path appID:(NSString *)appID paddingVersion:(BOOL)paddingVersion; + - (void)getRTMURLWithAppID:(NSString *)appID callback:(void (^)(NSDictionary *dictionary, NSError *error))callback; - (NSString *)batchPathForPath:(NSString *)path; diff --git a/AVOS/Sources/Foundation/User/LCUser.h b/AVOS/Sources/Foundation/User/LCUser.h index 94431a8a..e0ce5e0a 100644 --- a/AVOS/Sources/Foundation/User/LCUser.h +++ b/AVOS/Sources/Foundation/User/LCUser.h @@ -509,6 +509,10 @@ FOUNDATION_EXPORT LeanCloudSocialPlatform const LeanCloudSocialPlatformWeiXin; + (void)strictlyFindWithQuery:(LCQuery *)query callback:(void (^)(NSArray * _Nullable users, NSError * _Nullable error))callback; +// MARK: Misc + ++ (void)retrieveShortTokenWithCallback:(void (^)(NSString * _Nullable jwt, NSError * _Nullable error))callback; + @end /** diff --git a/AVOS/Sources/Foundation/User/LCUser.m b/AVOS/Sources/Foundation/User/LCUser.m index 6e410331..f3fc3d51 100644 --- a/AVOS/Sources/Foundation/User/LCUser.m +++ b/AVOS/Sources/Foundation/User/LCUser.m @@ -1215,6 +1215,22 @@ + (void)strictlyFindWithQuery:(LCQuery *)query }]; } +// MARK: Misc + ++ (void)retrieveShortTokenWithCallback:(void (^)(NSString * _Nullable, NSError * _Nullable))callback +{ + [[LCPaasClient sharedInstance] getObject:@"/storage/1.1/users/tap-support/identity" + paddingVersion:false + withParameters:nil + block:^(id _Nullable object, NSError * _Nullable error) { + if (error) { + [LCUtils callStringResultBlock:callback string:nil error:error]; + } else { + [LCUtils callStringResultBlock:callback string:((NSDictionary *)object)[@"identityToken"] error:nil]; + } + }]; +} + #pragma mark - Override from LCObject /**