Switch to dedicated server
This commit is contained in:
parent
1d028e5f6c
commit
5e1a33c32e
|
@ -5,8 +5,10 @@ import SessionSnodeKit
|
|||
public final class FileServerAPIV2 : NSObject {
|
||||
|
||||
// MARK: Settings
|
||||
@objc public static let server = "http://88.99.175.227"
|
||||
public static let serverPublicKey = "7cb31905b55cd5580c686911debf672577b3fb0bff81df4ce2d5c4cb3a7aaa69"
|
||||
@objc public static let oldServer = "http://88.99.175.227"
|
||||
public static let oldServerPublicKey = "7cb31905b55cd5580c686911debf672577b3fb0bff81df4ce2d5c4cb3a7aaa69"
|
||||
@objc public static let server = "http://filev2.getsession.org"
|
||||
public static let serverPublicKey = "da21e1d886c6fbaea313f75298bd64aab03a97ce985b46bb2dad9f2089c8ee59"
|
||||
|
||||
// MARK: Initialization
|
||||
private override init() { }
|
||||
|
@ -47,7 +49,9 @@ public final class FileServerAPIV2 : NSObject {
|
|||
}
|
||||
|
||||
// MARK: Convenience
|
||||
private static func send(_ request: Request) -> Promise<JSON> {
|
||||
private static func send(_ request: Request, useOldServer: Bool) -> Promise<JSON> {
|
||||
let server = useOldServer ? oldServer : server
|
||||
let serverPublicKey = useOldServer ? oldServerPublicKey : serverPublicKey
|
||||
let tsRequest: TSRequest
|
||||
switch request.verb {
|
||||
case .get:
|
||||
|
@ -81,21 +85,21 @@ public final class FileServerAPIV2 : NSObject {
|
|||
let base64EncodedFile = file.base64EncodedString()
|
||||
let parameters = [ "file" : base64EncodedFile ]
|
||||
let request = Request(verb: .post, endpoint: "files", parameters: parameters)
|
||||
return send(request).map(on: DispatchQueue.global(qos: .userInitiated)) { json in
|
||||
return send(request, useOldServer: false).map(on: DispatchQueue.global(qos: .userInitiated)) { json in
|
||||
guard let fileID = json["result"] as? UInt64 else { throw Error.parsingFailed }
|
||||
return fileID
|
||||
}
|
||||
}
|
||||
|
||||
@objc(download:)
|
||||
public static func objc_download(file: String) -> AnyPromise {
|
||||
@objc(download:useOldServer:)
|
||||
public static func objc_download(file: String, useOldServer: Bool) -> AnyPromise {
|
||||
guard let id = UInt64(file) else { return AnyPromise.from(Promise<Data>(error: Error.invalidURL)) }
|
||||
return AnyPromise.from(download(id))
|
||||
return AnyPromise.from(download(id, useOldServer: useOldServer))
|
||||
}
|
||||
|
||||
public static func download(_ file: UInt64) -> Promise<Data> {
|
||||
public static func download(_ file: UInt64, useOldServer: Bool) -> Promise<Data> {
|
||||
let request = Request(verb: .get, endpoint: "files/\(file)")
|
||||
return send(request).map(on: DispatchQueue.global(qos: .userInitiated)) { json in
|
||||
return send(request, useOldServer: useOldServer).map(on: DispatchQueue.global(qos: .userInitiated)) { json in
|
||||
guard let base64EncodedFile = json["result"] as? String, let file = Data(base64Encoded: base64EncodedFile) else { throw Error.parsingFailed }
|
||||
return file
|
||||
}
|
||||
|
|
|
@ -100,11 +100,12 @@ public final class AttachmentDownloadJob : NSObject, Job, NSCoding { // NSObject
|
|||
}.catch(on: DispatchQueue.global()) { error in
|
||||
handleFailure(error)
|
||||
}
|
||||
} else if pointer.downloadURL.contains(FileServerAPIV2.server) {
|
||||
} else if pointer.downloadURL.contains(FileServerAPIV2.server) || pointer.downloadURL.contains(FileServerAPIV2.oldServer) {
|
||||
guard let fileAsString = pointer.downloadURL.split(separator: "/").last, let file = UInt64(fileAsString) else {
|
||||
return handleFailure(Error.invalidURL)
|
||||
}
|
||||
FileServerAPIV2.download(file).done(on: DispatchQueue.global(qos: .userInitiated)) { data in
|
||||
let useOldServer = pointer.downloadURL.contains(FileServerAPIV2.oldServer)
|
||||
FileServerAPIV2.download(file, useOldServer: useOldServer).done(on: DispatchQueue.global(qos: .userInitiated)) { data in
|
||||
self.handleDownloadedAttachment(data: data, temporaryFilePath: temporaryFilePath, pointer: pointer, failureHandler: handleFailure)
|
||||
}.catch(on: DispatchQueue.global()) { error in
|
||||
handleFailure(error)
|
||||
|
|
|
@ -806,9 +806,10 @@ typedef void (^ProfileManagerFailureBlock)(NSError *error);
|
|||
NSString *profilePictureURL = userProfile.avatarUrlPath;
|
||||
|
||||
AnyPromise *promise;
|
||||
if ([profilePictureURL containsString:SNFileServerAPIV2.server]) {
|
||||
if ([profilePictureURL containsString:SNFileServerAPIV2.server] || [profilePictureURL containsString:SNFileServerAPIV2.oldServer]) {
|
||||
NSString *file = [profilePictureURL lastPathComponent];
|
||||
promise = [SNFileServerAPIV2 download:file];
|
||||
BOOL useOldServer = [profilePictureURL containsString:SNFileServerAPIV2.oldServer];
|
||||
promise = [SNFileServerAPIV2 download:file useOldServer:useOldServer];
|
||||
} else {
|
||||
promise = [SNFileServerAPI downloadAttachmentFrom:profilePictureURL];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue