Remove a redundant defer
This commit is contained in:
parent
3e2282cb03
commit
2a66afc52c
|
@ -133,38 +133,36 @@ final public class AttachmentViewModel: NSObject, ObservableObject, Identifiable
|
||||||
.receive(on: DispatchQueue.main)
|
.receive(on: DispatchQueue.main)
|
||||||
.assign(to: &$thumbnail)
|
.assign(to: &$thumbnail)
|
||||||
|
|
||||||
defer {
|
let uploadTask = Task { @MainActor in
|
||||||
let uploadTask = Task { @MainActor in
|
do {
|
||||||
do {
|
var output = try await load(input: input)
|
||||||
var output = try await load(input: input)
|
|
||||||
|
switch output {
|
||||||
switch output {
|
case .image(let data, _):
|
||||||
case .image(let data, _):
|
|
||||||
self.output = output
|
|
||||||
self.update(uploadState: .compressing)
|
|
||||||
let compressedOutput = try await compressImage(data: data, sizeLimit: sizeLimit)
|
|
||||||
output = compressedOutput
|
|
||||||
case .video(let fileURL, let mimeType):
|
|
||||||
self.output = output
|
|
||||||
self.update(uploadState: .compressing)
|
|
||||||
let compressedFileURL = try await compressVideo(url: fileURL)
|
|
||||||
output = .video(compressedFileURL, mimeType: mimeType)
|
|
||||||
try? FileManager.default.removeItem(at: fileURL) // remove old file
|
|
||||||
}
|
|
||||||
|
|
||||||
self.outputSizeInByte = output.asAttachment.sizeInByte.flatMap { Int64($0) } ?? 0
|
|
||||||
self.output = output
|
self.output = output
|
||||||
|
self.update(uploadState: .compressing)
|
||||||
self.update(uploadState: .ready)
|
let compressedOutput = try await compressImage(data: data, sizeLimit: sizeLimit)
|
||||||
self.delegate?.attachmentViewModel(self, uploadStateValueDidChange: self.uploadState)
|
output = compressedOutput
|
||||||
} catch {
|
case .video(let fileURL, let mimeType):
|
||||||
self.error = error
|
self.output = output
|
||||||
|
self.update(uploadState: .compressing)
|
||||||
|
let compressedFileURL = try await compressVideo(url: fileURL)
|
||||||
|
output = .video(compressedFileURL, mimeType: mimeType)
|
||||||
|
try? FileManager.default.removeItem(at: fileURL) // remove old file
|
||||||
}
|
}
|
||||||
} // end Task
|
|
||||||
self.uploadTask = uploadTask
|
self.outputSizeInByte = output.asAttachment.sizeInByte.flatMap { Int64($0) } ?? 0
|
||||||
Task {
|
self.output = output
|
||||||
await uploadTask.value
|
|
||||||
|
self.update(uploadState: .ready)
|
||||||
|
self.delegate?.attachmentViewModel(self, uploadStateValueDidChange: self.uploadState)
|
||||||
|
} catch {
|
||||||
|
self.error = error
|
||||||
}
|
}
|
||||||
|
} // end Task
|
||||||
|
self.uploadTask = uploadTask
|
||||||
|
Task {
|
||||||
|
await uploadTask.value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue