Skip to content

Commit 608a159

Browse files
committed
v2.0.7(127)
fix login bug on pCloud
1 parent 73c2f16 commit 608a159

File tree

3 files changed

+41
-17
lines changed

3 files changed

+41
-17
lines changed

CryptCloudViewer/CryptCloudViewer.xcodeproj/project.pbxproj

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
4949
membershipExceptions = (
5050
Info.plist,
51+
Secret.xcconfig,
5152
);
5253
target = BE64E9962EA4044800BD4A7E /* CryptCloudViewer */;
5354
};
@@ -142,7 +143,7 @@
142143
attributes = {
143144
BuildIndependentTargetsInParallel = 1;
144145
LastSwiftUpdateCheck = 2600;
145-
LastUpgradeCheck = 2610;
146+
LastUpgradeCheck = 2620;
146147
TargetAttributes = {
147148
BE64E9962EA4044800BD4A7E = {
148149
CreatedOnToolsVersion = 26.0.1;
@@ -198,6 +199,7 @@
198199
buildSettings = {
199200
ALWAYS_SEARCH_USER_PATHS = NO;
200201
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
202+
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
201203
CLANG_ANALYZER_NONNULL = YES;
202204
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
203205
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
@@ -263,6 +265,7 @@
263265
buildSettings = {
264266
ALWAYS_SEARCH_USER_PATHS = NO;
265267
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
268+
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
266269
CLANG_ANALYZER_NONNULL = YES;
267270
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
268271
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
@@ -325,7 +328,7 @@
325328
CLANG_ENABLE_MODULES = YES;
326329
CODE_SIGN_ENTITLEMENTS = CryptCloudViewer/CryptCloudViewer.entitlements;
327330
CODE_SIGN_STYLE = Automatic;
328-
CURRENT_PROJECT_VERSION = 126;
331+
CURRENT_PROJECT_VERSION = 127;
329332
DEAD_CODE_STRIPPING = YES;
330333
DEVELOPMENT_TEAM = 7A9X38B4YU;
331334
ENABLE_APP_SANDBOX = YES;
@@ -354,7 +357,7 @@
354357
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
355358
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
356359
MACOSX_DEPLOYMENT_TARGET = 26.0;
357-
MARKETING_VERSION = 2.0.6;
360+
MARKETING_VERSION = 2.0.7;
358361
PRODUCT_BUNDLE_IDENTIFIER = info.lithium03.ccViewer;
359362
PRODUCT_NAME = "$(TARGET_NAME)";
360363
REGISTER_APP_GROUPS = YES;
@@ -384,7 +387,7 @@
384387
CLANG_ENABLE_MODULES = YES;
385388
CODE_SIGN_ENTITLEMENTS = CryptCloudViewer/CryptCloudViewer.entitlements;
386389
CODE_SIGN_STYLE = Automatic;
387-
CURRENT_PROJECT_VERSION = 126;
390+
CURRENT_PROJECT_VERSION = 127;
388391
DEAD_CODE_STRIPPING = YES;
389392
DEVELOPMENT_TEAM = 7A9X38B4YU;
390393
ENABLE_APP_SANDBOX = YES;
@@ -413,7 +416,7 @@
413416
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
414417
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
415418
MACOSX_DEPLOYMENT_TARGET = 26.0;
416-
MARKETING_VERSION = 2.0.6;
419+
MARKETING_VERSION = 2.0.7;
417420
PRODUCT_BUNDLE_IDENTIFIER = info.lithium03.ccViewer;
418421
PRODUCT_NAME = "$(TARGET_NAME)";
419422
REGISTER_APP_GROUPS = YES;

RemoteCloud/RemoteCloud/NetworkStorage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct WebLoginView: View {
2727
try? await Task.sleep(for: .seconds(1))
2828
do {
2929
// Perform the authentication and await the result.
30-
let urlWithToken = try await webAuthenticationSession.authenticate(using: url, callback: callback, additionalHeaderFields: additionalHeaderFields)
30+
let urlWithToken = try await webAuthenticationSession.authenticate(using: url, callback: callback, preferredBrowserSession: .ephemeral, additionalHeaderFields: additionalHeaderFields)
3131
// Call the method that completes the authentication using the
3232
// returned URL.
3333
guard try await signIn(urlWithToken) else {

RemoteCloud/RemoteCloud/Storages/pCloudStorage.swift

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,28 @@ public class pCloudStorage: NetworkStorage, URLSessionDataDelegate {
4141
return [:]
4242
}
4343

44+
var cache_hostname: String = ""
45+
func hostname() async -> String {
46+
if cache_hostname != "" {
47+
return cache_hostname
48+
}
49+
if let name = storageName {
50+
if let host = await getKeyChain(key: "\(name)_hostname") {
51+
cache_hostname = host
52+
}
53+
return cache_hostname
54+
}
55+
else {
56+
return "api.pcloud.com"
57+
}
58+
}
59+
4460
override func signIn(_ successURL: URL) async throws -> Bool {
4561
let oauthToken = NSURLComponents(string: (successURL.absoluteString))?.queryItems?.filter({$0.name == "code"}).first
62+
let hostname = NSURLComponents(string: (successURL.absoluteString))?.queryItems?.filter({$0.name == "hostname"}).first
63+
if let hostnameString = hostname?.value {
64+
_ = await setKeyChain(key: "\(storageName!)_hostname", value: hostnameString)
65+
}
4666

4767
if let oauthTokenString = oauthToken?.value {
4868
return await getToken(oauthToken: oauthTokenString)
@@ -53,7 +73,7 @@ public class pCloudStorage: NetworkStorage, URLSessionDataDelegate {
5373
override func getToken(oauthToken: String) async -> Bool {
5474
os_log("%{public}@", log: log, type: .debug, "getToken(pCloud:\(storageName ?? ""))")
5575

56-
var request: URLRequest = URLRequest(url: URL(string: "https://api.pcloud.com/oauth2_token")!)
76+
var request: URLRequest = URLRequest(url: URL(string: "https://\(await hostname())/oauth2_token")!)
5777
request.httpMethod = "POST"
5878
request.setValue("application/x-www-form-urlencoded; charset=UTF-8", forHTTPHeaderField: "Content-Type")
5979

@@ -105,14 +125,15 @@ public class pCloudStorage: NetworkStorage, URLSessionDataDelegate {
105125
public override func logout() async {
106126
if let name = storageName {
107127
let _ = await delKeyChain(key: "\(name)_accountId")
128+
let _ = await delKeyChain(key: "\(name)_hostname")
108129
}
109130
await super.logout()
110131
}
111132

112133
override func revokeToken(token: String) async -> Bool {
113134
os_log("%{public}@", log: log, type: .debug, "revokeToken(pCloud:\(storageName ?? ""))")
114135

115-
var request: URLRequest = URLRequest(url: URL(string: "https://api.pcloud.com/logout")!)
136+
var request: URLRequest = URLRequest(url: URL(string: "https://\(await hostname())/logout")!)
116137
request.httpMethod = "POST"
117138
request.setValue("Bearer \(await accessToken())", forHTTPHeaderField: "Authorization")
118139

@@ -135,7 +156,7 @@ public class pCloudStorage: NetworkStorage, URLSessionDataDelegate {
135156
}
136157

137158
override func isAuthorized() async -> Bool {
138-
var request: URLRequest = URLRequest(url: URL(string: "https://api.pcloud.com/userinfo")!)
159+
var request: URLRequest = URLRequest(url: URL(string: "https://\(await hostname())/userinfo")!)
139160
request.httpMethod = "GET"
140161
request.setValue("Bearer \(await accessToken())", forHTTPHeaderField: "Authorization")
141162

@@ -160,7 +181,7 @@ public class pCloudStorage: NetworkStorage, URLSessionDataDelegate {
160181
return try await callWithRetry(action: { [self] in
161182
os_log("%{public}@", log: log, type: .debug, "listFolder(pCloud:\(storageName ?? ""))")
162183

163-
let url = "https://api.pcloud.com/listfolder?folderid=\(folderId)&timeformat=timestamp"
184+
let url = "https://\(await hostname())/listfolder?folderid=\(folderId)&timeformat=timestamp"
164185

165186
var request: URLRequest = URLRequest(url: URL(string: url)!)
166187
request.httpMethod = "GET"
@@ -307,7 +328,7 @@ public class pCloudStorage: NetworkStorage, URLSessionDataDelegate {
307328
return try await callWithRetry(action: { [self] in
308329
os_log("%{public}@", log: log, type: .debug, "readFile(pCloud:\(storageName ?? "") \(fileId) \(start ?? -1) \(length ?? -1) \((start ?? 0) + (length ?? 0))")
309330

310-
var request: URLRequest = URLRequest(url: URL(string: "https://api.pcloud.com/getfilelink?fileid=\(id)")!)
331+
var request: URLRequest = URLRequest(url: URL(string: "https://\(await hostname())/getfilelink?fileid=\(id)")!)
311332
request.httpMethod = "GET"
312333
request.setValue("Bearer \(await accessToken())", forHTTPHeaderField: "Authorization")
313334

@@ -368,7 +389,7 @@ public class pCloudStorage: NetworkStorage, URLSessionDataDelegate {
368389
do {
369390
return try await callWithRetry(action: { [self] in
370391
let body = "folderid=\(folderid)&name=\(name)&timeformat=timestamp"
371-
var request: URLRequest = URLRequest(url: URL(string: "https://api.pcloud.com/createfolder")!)
392+
var request: URLRequest = URLRequest(url: URL(string: "https://\(await hostname())/createfolder")!)
372393
request.httpMethod = "POST"
373394
request.setValue("Bearer \(await accessToken())", forHTTPHeaderField: "Authorization")
374395
request.httpBody = body.data(using: .utf8)
@@ -421,7 +442,7 @@ public class pCloudStorage: NetworkStorage, URLSessionDataDelegate {
421442
do {
422443
return try await callWithRetry(action: { [self] in
423444
let body = "folderid=\(folderId)"
424-
var request: URLRequest = URLRequest(url: URL(string: "https://api.pcloud.com/deletefolderrecursive")!)
445+
var request: URLRequest = URLRequest(url: URL(string: "https://\(await hostname())/deletefolderrecursive")!)
425446
request.httpMethod = "POST"
426447
request.setValue("Bearer \(await accessToken())", forHTTPHeaderField: "Authorization")
427448
request.httpBody = body.data(using: .utf8)
@@ -449,7 +470,7 @@ public class pCloudStorage: NetworkStorage, URLSessionDataDelegate {
449470
do {
450471
return try await callWithRetry(action: { [self] in
451472
let body = "fileid=\(fileId)"
452-
var request: URLRequest = URLRequest(url: URL(string: "https://api.pcloud.com/deletefile")!)
473+
var request: URLRequest = URLRequest(url: URL(string: "https://\(await hostname())/deletefile")!)
453474
request.httpMethod = "POST"
454475
request.setValue("Bearer \(await accessToken())", forHTTPHeaderField: "Authorization")
455476
request.httpBody = body.data(using: .utf8)
@@ -537,7 +558,7 @@ public class pCloudStorage: NetworkStorage, URLSessionDataDelegate {
537558
if let toName = toName {
538559
rename += "&toname=\(toName)"
539560
}
540-
var request: URLRequest = URLRequest(url: URL(string: "https://api.pcloud.com/renamefile")!)
561+
var request: URLRequest = URLRequest(url: URL(string: "https://\(await hostname())/renamefile")!)
541562
request.httpMethod = "POST"
542563
request.setValue("Bearer \(await accessToken())", forHTTPHeaderField: "Authorization")
543564
request.httpBody = rename.data(using: .utf8)
@@ -578,7 +599,7 @@ public class pCloudStorage: NetworkStorage, URLSessionDataDelegate {
578599
if let toName = toName {
579600
rename += "&toname=\(toName)"
580601
}
581-
var request: URLRequest = URLRequest(url: URL(string: "https://api.pcloud.com/renamefolder")!)
602+
var request: URLRequest = URLRequest(url: URL(string: "https://\(await hostname())/renamefolder")!)
582603
request.httpMethod = "POST"
583604
request.setValue("Bearer \(await accessToken())", forHTTPHeaderField: "Authorization")
584605
request.httpBody = rename.data(using: .utf8)
@@ -710,7 +731,7 @@ public class pCloudStorage: NetworkStorage, URLSessionDataDelegate {
710731
}
711732
let tmpurl = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("\(Int.random(in: 0...0xffffffff))")
712733

713-
var request: URLRequest = URLRequest(url: URL(string: "https://api.pcloud.com/uploadfile")!)
734+
var request: URLRequest = URLRequest(url: URL(string: "https://\(await hostname())/uploadfile")!)
714735
request.httpMethod = "POST"
715736
request.setValue("Bearer \(await accessToken())", forHTTPHeaderField: "Authorization")
716737
let boundary = "Boundary-\(UUID().uuidString)"

0 commit comments

Comments
 (0)