Use new profile picture endpoint

pull/70/head
Niels Andriesse 5 years ago
parent 661795bd00
commit 734835b4ac

@ -211,11 +211,11 @@ public final class LokiStorageAPI : LokiDotNetAPI {
public static func setProfilePicture(_ profilePicture: Data) -> Promise<String> {
return Promise<String>() { seal in
getAuthToken(for: server).done { token in
let url = "\(server)/files"
let url = "\(server)/users/me/avatar"
let parameters: JSON = [ "type" : attachmentType, "Content-Type" : "application/binary" ]
var error: NSError?
var request = AFHTTPRequestSerializer().multipartFormRequest(withMethod: "POST", urlString: url, parameters: parameters, constructingBodyWith: { formData in
formData.appendPart(withFileData: profilePicture, name: "content", fileName: UUID().uuidString, mimeType: "application/binary")
formData.appendPart(withFileData: profilePicture, name: "avatar", fileName: UUID().uuidString, mimeType: "application/binary")
}, error: &error)
request.addValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
if let error = error {
@ -233,7 +233,7 @@ public final class LokiStorageAPI : LokiDotNetAPI {
print("[Loki] Couldn't upload profile picture.")
return seal.reject(Error.generic)
}
guard let json = responseObject as? JSON, let data = json["data"] as? JSON, let downloadURL = data["url"] as? String else {
guard let json = responseObject as? JSON, let data = json["data"] as? JSON, let profilePicture = data["avatar_image"] as? JSON, let downloadURL = profilePicture["url"] as? String else {
print("[Loki] Couldn't parse profile picture from: \(responseObject).")
return seal.reject(Error.parsingFailed)
}

Loading…
Cancel
Save