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
|
||||
public func execute() {
|
||||
SNLog("Attachment upload failure count: \(failureCount).")
|
||||
guard let stream = TSAttachmentStream.fetch(uniqueId: attachmentID) else {
|
||||
return handleFailure(error: Error.noAttachment)
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ public extension VisibleMessage {
|
|||
|
||||
public var isValid: Bool {
|
||||
// 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 {
|
||||
|
|
|
@ -7,7 +7,7 @@ extension TSAttachmentPointer {
|
|||
case .generic: kind = .default
|
||||
case .voiceMessage: kind = .voiceMessage
|
||||
}
|
||||
return TSAttachmentPointer(
|
||||
let result = TSAttachmentPointer(
|
||||
serverId: 0,
|
||||
key: attachment.key,
|
||||
digest: attachment.digest,
|
||||
|
@ -18,5 +18,7 @@ extension TSAttachmentPointer {
|
|||
albumMessageId: nil,
|
||||
attachmentType: kind,
|
||||
mediaSize: attachment.size!)
|
||||
result.downloadURL = attachment.url!
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ public class DotNetAPI : NSObject {
|
|||
// MARK: Error
|
||||
public enum Error : LocalizedError {
|
||||
case generic
|
||||
case invalidURL
|
||||
case parsingFailed
|
||||
case signingFailed
|
||||
case encryptionFailed
|
||||
|
@ -29,6 +30,7 @@ public class DotNetAPI : NSObject {
|
|||
public var errorDescription: String? {
|
||||
switch self {
|
||||
case .generic: return "An error occurred."
|
||||
case .invalidURL: return "Invalid URL."
|
||||
case .parsingFailed: return "Invalid file server response."
|
||||
case .signingFailed: return "Couldn't sign message."
|
||||
case .encryptionFailed: return "Couldn't encrypt file."
|
||||
|
@ -105,14 +107,15 @@ public class DotNetAPI : NSObject {
|
|||
return AnyPromise.from(downloadAttachment(from: url))
|
||||
}
|
||||
|
||||
public static func downloadAttachment(from url: String) -> Promise<Data> {
|
||||
var host = "https://\(URL(string: url)!.host!)"
|
||||
public static func downloadAttachment(from urlAsString: String) -> Promise<Data> {
|
||||
guard let url = URL(string: urlAsString) else { return Promise(error: Error.invalidURL) }
|
||||
var host = "https://\(url.host!)"
|
||||
let sanitizedURL: String
|
||||
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
|
||||
} else {
|
||||
sanitizedURL = url.replacingOccurrences(of: host, with: "\(host)/loki/v1")
|
||||
sanitizedURL = urlAsString.replacingOccurrences(of: host, with: "\(host)/loki/v1")
|
||||
}
|
||||
let request: NSMutableURLRequest
|
||||
do {
|
||||
|
|
Loading…
Reference in New Issue