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
7 changes: 7 additions & 0 deletions AVOS/LeanCloudObjcTests/BaseTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -68,6 +74,7 @@ class BaseTestCase: XCTestCase {

static let appInfoTable = [
cnApp.id : cnApp,
tds1App.id : tds1App,
ceApp.id : ceApp,
usApp.id : usApp,
]
Expand Down
15 changes: 15 additions & 0 deletions AVOS/Sources/Foundation/Request/LCPaasClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
74 changes: 68 additions & 6 deletions AVOS/Sources/Foundation/Request/LCPaasClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down Expand Up @@ -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. */
Expand Down
7 changes: 6 additions & 1 deletion AVOS/Sources/Foundation/Router/LCRouter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
};

Expand Down
2 changes: 2 additions & 0 deletions AVOS/Sources/Foundation/Router/LCRouter_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions AVOS/Sources/Foundation/User/LCUser.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,10 @@ FOUNDATION_EXPORT LeanCloudSocialPlatform const LeanCloudSocialPlatformWeiXin;
+ (void)strictlyFindWithQuery:(LCQuery *)query
callback:(void (^)(NSArray<LCUser *> * _Nullable users, NSError * _Nullable error))callback;

// MARK: Misc

+ (void)retrieveShortTokenWithCallback:(void (^)(NSString * _Nullable jwt, NSError * _Nullable error))callback;

@end

/**
Expand Down
16 changes: 16 additions & 0 deletions AVOS/Sources/Foundation/User/LCUser.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down