addressed upload issue in pr feedback
This commit is contained in:
@@ -319,33 +319,35 @@ struct PostView: View {
|
|||||||
.padding(.top, 15)
|
.padding(.top, 15)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handle_upload(media: MediaUpload) {
|
@discardableResult
|
||||||
|
func handle_upload(media: MediaUpload) async -> Bool {
|
||||||
let uploader = damus_state.settings.default_media_uploader
|
let uploader = damus_state.settings.default_media_uploader
|
||||||
Task {
|
|
||||||
let img = getImage(media: media)
|
|
||||||
print("img size w:\(img.size.width) h:\(img.size.height)")
|
|
||||||
async let blurhash = calculate_blurhash(img: img)
|
|
||||||
let res = await image_upload.start(media: media, uploader: uploader, keypair: damus_state.keypair)
|
|
||||||
|
|
||||||
switch res {
|
let img = getImage(media: media)
|
||||||
case .success(let url):
|
print("img size w:\(img.size.width) h:\(img.size.height)")
|
||||||
guard let url = URL(string: url) else {
|
|
||||||
self.error = "Error uploading image :("
|
|
||||||
return
|
|
||||||
}
|
|
||||||
let blurhash = await blurhash
|
|
||||||
let meta = blurhash.map { bh in calculate_image_metadata(url: url, img: img, blurhash: bh) }
|
|
||||||
let uploadedMedia = UploadedMedia(localURL: media.localURL, uploadedURL: url, representingImage: img, metadata: meta)
|
|
||||||
uploadedMedias.append(uploadedMedia)
|
|
||||||
|
|
||||||
case .failed(let error):
|
async let blurhash = calculate_blurhash(img: img)
|
||||||
if let error {
|
let res = await image_upload.start(media: media, uploader: uploader, keypair: damus_state.keypair)
|
||||||
self.error = error.localizedDescription
|
|
||||||
} else {
|
switch res {
|
||||||
self.error = "Error uploading image :("
|
case .success(let url):
|
||||||
}
|
guard let url = URL(string: url) else {
|
||||||
|
self.error = "Error uploading image :("
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
let blurhash = await blurhash
|
||||||
|
let meta = blurhash.map { bh in calculate_image_metadata(url: url, img: img, blurhash: bh) }
|
||||||
|
let uploadedMedia = UploadedMedia(localURL: media.localURL, uploadedURL: url, representingImage: img, metadata: meta)
|
||||||
|
uploadedMedias.append(uploadedMedia)
|
||||||
|
return true
|
||||||
|
|
||||||
|
case .failed(let error):
|
||||||
|
if let error {
|
||||||
|
self.error = error.localizedDescription
|
||||||
|
} else {
|
||||||
|
self.error = "Error uploading image :("
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -450,9 +452,11 @@ struct PostView: View {
|
|||||||
}
|
}
|
||||||
.alert(NSLocalizedString("Are you sure you want to upload the selected media?", comment: "Alert message asking if the user wants to upload media."), isPresented: $image_upload_confirm) {
|
.alert(NSLocalizedString("Are you sure you want to upload the selected media?", comment: "Alert message asking if the user wants to upload media."), isPresented: $image_upload_confirm) {
|
||||||
Button(NSLocalizedString("Upload", comment: "Button to proceed with uploading."), role: .none) {
|
Button(NSLocalizedString("Upload", comment: "Button to proceed with uploading."), role: .none) {
|
||||||
for media in preUploadedMedia {
|
Task {
|
||||||
if let mediaToUpload = generateMediaUpload(media) {
|
for media in preUploadedMedia {
|
||||||
self.handle_upload(media: mediaToUpload)
|
if let mediaToUpload = generateMediaUpload(media) {
|
||||||
|
await self.handle_upload(media: mediaToUpload)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.attach_media = false
|
self.attach_media = false
|
||||||
|
|||||||
Reference in New Issue
Block a user