pull/83/head
Niels Andriesse 6 years ago
parent 5bd69ea6ed
commit 37377c32df

@ -74,20 +74,23 @@ public class LokiDotNetAPI : NSObject {
throw error
}
// Send the request
let isProxyingRequired = (server == LokiStorageAPI.server)
func parseResponse(_ response: Any) {
// Parse the server ID & download URL
guard let json = response as? JSON, let data = json["data"] as? JSON, let serverID = data["id"] as? UInt64, let downloadURL = data["url"] as? String else {
print("[Loki] Couldn't parse attachment from: \(response).")
return seal.reject(Error.parsingFailed)
}
// Update the attachment
attachment.serverId = serverID
attachment.isUploaded = true
attachment.downloadURL = downloadURL
attachment.save()
seal.fulfill(())
}
let isProxyingRequired = (server == LokiStorageAPI.server) // Don't proxy open group requests for now
if isProxyingRequired {
let _ = LokiFileServerProxy(for: server).performLokiFileServerNSURLRequest(request as NSURLRequest).done { responseObject in
// Parse the server ID & download URL
guard let json = responseObject as? JSON, let data = json["data"] as? JSON, let serverID = data["id"] as? UInt64, let downloadURL = data["url"] as? String else {
print("[Loki] Couldn't parse attachment from: \(responseObject).")
return seal.reject(Error.parsingFailed)
}
// Update the attachment
attachment.serverId = serverID
attachment.isUploaded = true
attachment.downloadURL = downloadURL
attachment.save()
seal.fulfill(())
parseResponse(responseObject)
}.catch { error in
seal.reject(error)
}
@ -110,17 +113,7 @@ public class LokiDotNetAPI : NSObject {
print("[Loki] Couldn't upload attachment.")
return seal.reject(Error.generic)
}
// Parse the server ID & download URL
guard let json = responseObject as? JSON, let data = json["data"] as? JSON, let serverID = data["id"] as? UInt64, let downloadURL = data["url"] as? String else {
print("[Loki] Couldn't parse attachment from: \(responseObject).")
return seal.reject(Error.parsingFailed)
}
// Update the attachment
attachment.serverId = serverID
attachment.isUploaded = true
attachment.downloadURL = downloadURL
attachment.save()
return seal.fulfill(())
parseResponse(responseObject)
})
task.resume()
}

@ -37,7 +37,7 @@ internal class LokiFileServerProxy : LokiHTTPClient {
// MARK: Proxying
override internal func perform(_ request: TSRequest, withCompletionQueue queue: DispatchQueue = DispatchQueue.main) -> LokiAPI.RawResponsePromise {
let isLokiFileServer = server.contains("file.lokinet.org") || server.contains("file-dev.lokinet.org")
let isLokiFileServer = (server == LokiStorageAPI.server)
guard isLokiFileServer else { return super.perform(request, withCompletionQueue: queue) } // Don't proxy open group requests for now
return performLokiFileServerNSURLRequest(request, withCompletionQueue: queue)
}

Loading…
Cancel
Save