Debug attachment receiving
This commit is contained in:
parent
d01f43147a
commit
4dda59b446
|
@ -57,7 +57,6 @@ public final class AttachmentUploadJob : NSObject, Job, NSCoding { // NSObject/N
|
||||||
|
|
||||||
// MARK: Running
|
// MARK: Running
|
||||||
public func execute() {
|
public func execute() {
|
||||||
SNLog("Attachment upload failure count: \(failureCount).")
|
|
||||||
guard let stream = TSAttachmentStream.fetch(uniqueId: attachmentID) else {
|
guard let stream = TSAttachmentStream.fetch(uniqueId: attachmentID) else {
|
||||||
return handleFailure(error: Error.noAttachment)
|
return handleFailure(error: Error.noAttachment)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ public extension VisibleMessage {
|
||||||
|
|
||||||
public var isValid: Bool {
|
public var isValid: Bool {
|
||||||
// key and digest can be nil for open group attachments
|
// key and digest can be nil for open group attachments
|
||||||
fileName != nil && contentType != nil && kind != nil && size != nil && sizeInBytes != nil && url != nil
|
contentType != nil && kind != nil && size != nil && sizeInBytes != nil && url != nil
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Kind : String {
|
public enum Kind : String {
|
||||||
|
|
|
@ -7,7 +7,7 @@ extension TSAttachmentPointer {
|
||||||
case .generic: kind = .default
|
case .generic: kind = .default
|
||||||
case .voiceMessage: kind = .voiceMessage
|
case .voiceMessage: kind = .voiceMessage
|
||||||
}
|
}
|
||||||
return TSAttachmentPointer(
|
let result = TSAttachmentPointer(
|
||||||
serverId: 0,
|
serverId: 0,
|
||||||
key: attachment.key,
|
key: attachment.key,
|
||||||
digest: attachment.digest,
|
digest: attachment.digest,
|
||||||
|
@ -18,5 +18,7 @@ extension TSAttachmentPointer {
|
||||||
albumMessageId: nil,
|
albumMessageId: nil,
|
||||||
attachmentType: kind,
|
attachmentType: kind,
|
||||||
mediaSize: attachment.size!)
|
mediaSize: attachment.size!)
|
||||||
|
result.downloadURL = attachment.url!
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ public class DotNetAPI : NSObject {
|
||||||
// MARK: Error
|
// MARK: Error
|
||||||
public enum Error : LocalizedError {
|
public enum Error : LocalizedError {
|
||||||
case generic
|
case generic
|
||||||
|
case invalidURL
|
||||||
case parsingFailed
|
case parsingFailed
|
||||||
case signingFailed
|
case signingFailed
|
||||||
case encryptionFailed
|
case encryptionFailed
|
||||||
|
@ -29,6 +30,7 @@ public class DotNetAPI : NSObject {
|
||||||
public var errorDescription: String? {
|
public var errorDescription: String? {
|
||||||
switch self {
|
switch self {
|
||||||
case .generic: return "An error occurred."
|
case .generic: return "An error occurred."
|
||||||
|
case .invalidURL: return "Invalid URL."
|
||||||
case .parsingFailed: return "Invalid file server response."
|
case .parsingFailed: return "Invalid file server response."
|
||||||
case .signingFailed: return "Couldn't sign message."
|
case .signingFailed: return "Couldn't sign message."
|
||||||
case .encryptionFailed: return "Couldn't encrypt file."
|
case .encryptionFailed: return "Couldn't encrypt file."
|
||||||
|
@ -105,14 +107,15 @@ public class DotNetAPI : NSObject {
|
||||||
return AnyPromise.from(downloadAttachment(from: url))
|
return AnyPromise.from(downloadAttachment(from: url))
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func downloadAttachment(from url: String) -> Promise<Data> {
|
public static func downloadAttachment(from urlAsString: String) -> Promise<Data> {
|
||||||
var host = "https://\(URL(string: url)!.host!)"
|
guard let url = URL(string: urlAsString) else { return Promise(error: Error.invalidURL) }
|
||||||
|
var host = "https://\(url.host!)"
|
||||||
let sanitizedURL: String
|
let sanitizedURL: String
|
||||||
if FileServerAPI.fileStorageBucketURL.contains(host) {
|
if FileServerAPI.fileStorageBucketURL.contains(host) {
|
||||||
sanitizedURL = url.replacingOccurrences(of: FileServerAPI.fileStorageBucketURL, with: "\(FileServerAPI.server)/loki/v1")
|
sanitizedURL = urlAsString.replacingOccurrences(of: FileServerAPI.fileStorageBucketURL, with: "\(FileServerAPI.server)/loki/v1")
|
||||||
host = FileServerAPI.server
|
host = FileServerAPI.server
|
||||||
} else {
|
} else {
|
||||||
sanitizedURL = url.replacingOccurrences(of: host, with: "\(host)/loki/v1")
|
sanitizedURL = urlAsString.replacingOccurrences(of: host, with: "\(host)/loki/v1")
|
||||||
}
|
}
|
||||||
let request: NSMutableURLRequest
|
let request: NSMutableURLRequest
|
||||||
do {
|
do {
|
||||||
|
|
Loading…
Reference in New Issue