fix: banner image upload
There was a nostr.build auth issue when uploading banner images. This fixes that. Closes: #2614 Changelog-Fixed: Fix banner image uploa Signed-off-by: Swift Coder <scoder1747@gmail.com>
This commit is contained in:
committed by
William Casarin
parent
8c6bee3d90
commit
a2b0620175
@@ -31,7 +31,7 @@ struct EditBannerImageView: View {
|
|||||||
.onFailureImage(defaultImage)
|
.onFailureImage(defaultImage)
|
||||||
.kfClickable()
|
.kfClickable()
|
||||||
|
|
||||||
EditPictureControl(uploader: damus_state.settings.default_media_uploader, pubkey: damus_state.pubkey, image_url: $banner_image, uploadObserver: viewModel, callback: callback)
|
EditPictureControl(uploader: damus_state.settings.default_media_uploader, keypair: damus_state.keypair, pubkey: damus_state.pubkey, image_url: $banner_image, uploadObserver: viewModel, callback: callback)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ struct CreateAccountView: View {
|
|||||||
Spacer()
|
Spacer()
|
||||||
VStack(alignment: .center) {
|
VStack(alignment: .center) {
|
||||||
|
|
||||||
EditPictureControl(uploader: .nostrBuild, pubkey: account.pubkey, size: 75, setup: true, image_url: $account.profile_image , uploadObserver: profileUploadObserver, callback: uploadedProfilePicture)
|
EditPictureControl(uploader: .nostrBuild, keypair: account.keypair, pubkey: account.pubkey, size: 75, setup: true, image_url: $account.profile_image , uploadObserver: profileUploadObserver, callback: uploadedProfilePicture)
|
||||||
.shadow(radius: 2)
|
.shadow(radius: 2)
|
||||||
.padding(.top, 100)
|
.padding(.top, 100)
|
||||||
|
|
||||||
|
|||||||
@@ -9,15 +9,19 @@ import UIKit
|
|||||||
import SwiftUI
|
import SwiftUI
|
||||||
import PhotosUI
|
import PhotosUI
|
||||||
|
|
||||||
|
enum MediaPickerEntry {
|
||||||
|
case editPictureControl
|
||||||
|
case postView
|
||||||
|
}
|
||||||
|
|
||||||
struct MediaPicker: UIViewControllerRepresentable {
|
struct MediaPicker: UIViewControllerRepresentable {
|
||||||
|
|
||||||
@Environment(\.presentationMode)
|
@Environment(\.presentationMode)
|
||||||
@Binding private var presentationMode
|
@Binding private var presentationMode
|
||||||
|
let mediaPickerEntry: MediaPickerEntry
|
||||||
|
|
||||||
@Binding var image_upload_confirm: Bool
|
@Binding var image_upload_confirm: Bool
|
||||||
var imagesOnly: Bool = false
|
|
||||||
let onMediaPicked: (PreUploadedMedia) -> Void
|
let onMediaPicked: (PreUploadedMedia) -> Void
|
||||||
|
|
||||||
|
|
||||||
final class Coordinator: NSObject, PHPickerViewControllerDelegate {
|
final class Coordinator: NSObject, PHPickerViewControllerDelegate {
|
||||||
var parent: MediaPicker
|
var parent: MediaPicker
|
||||||
@@ -138,9 +142,15 @@ struct MediaPicker: UIViewControllerRepresentable {
|
|||||||
|
|
||||||
func makeUIViewController(context: Context) -> PHPickerViewController {
|
func makeUIViewController(context: Context) -> PHPickerViewController {
|
||||||
var configuration = PHPickerConfiguration(photoLibrary: .shared())
|
var configuration = PHPickerConfiguration(photoLibrary: .shared())
|
||||||
configuration.selectionLimit = 0 // Allows multiple media selection
|
switch mediaPickerEntry {
|
||||||
configuration.filter = imagesOnly ? .images : .any(of: [.images, .videos])
|
case .postView:
|
||||||
configuration.selection = .ordered // images are returned in the order they were selected + numbered badge displayed
|
configuration.selectionLimit = 0 // allows multiple media selection
|
||||||
|
configuration.filter = .any(of: [.images, .videos])
|
||||||
|
configuration.selection = .ordered // images are returned in the order they were selected + numbered badge displayed
|
||||||
|
case .editPictureControl:
|
||||||
|
configuration.selectionLimit = 1 // allows one media selection
|
||||||
|
configuration.filter = .images // allows image only
|
||||||
|
}
|
||||||
let picker = PHPickerViewController(configuration: configuration)
|
let picker = PHPickerViewController(configuration: configuration)
|
||||||
picker.delegate = context.coordinator as any PHPickerViewControllerDelegate
|
picker.delegate = context.coordinator as any PHPickerViewControllerDelegate
|
||||||
return picker
|
return picker
|
||||||
|
|||||||
@@ -437,7 +437,7 @@ struct PostView: View {
|
|||||||
}
|
}
|
||||||
.background(DamusColors.adaptableWhite.edgesIgnoringSafeArea(.all))
|
.background(DamusColors.adaptableWhite.edgesIgnoringSafeArea(.all))
|
||||||
.sheet(isPresented: $attach_media) {
|
.sheet(isPresented: $attach_media) {
|
||||||
MediaPicker(image_upload_confirm: $image_upload_confirm){ media in
|
MediaPicker(mediaPickerEntry: .postView, image_upload_confirm: $image_upload_confirm){ media in
|
||||||
self.preUploadedMedia.append(media)
|
self.preUploadedMedia.append(media)
|
||||||
}
|
}
|
||||||
.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) {
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ class ImageUploadingObserver: ObservableObject {
|
|||||||
|
|
||||||
struct EditPictureControl: View {
|
struct EditPictureControl: View {
|
||||||
let uploader: MediaUploader
|
let uploader: MediaUploader
|
||||||
|
let keypair: Keypair?
|
||||||
let pubkey: Pubkey
|
let pubkey: Pubkey
|
||||||
var size: CGFloat? = 25
|
var size: CGFloat? = 25
|
||||||
var setup: Bool? = false
|
var setup: Bool? = false
|
||||||
@@ -113,7 +114,7 @@ struct EditPictureControl: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.sheet(isPresented: $show_library) {
|
.sheet(isPresented: $show_library) {
|
||||||
MediaPicker(image_upload_confirm: $image_upload_confirm, imagesOnly: true) { media in
|
MediaPicker(mediaPickerEntry: .editPictureControl, image_upload_confirm: $image_upload_confirm) { media in
|
||||||
self.preUploadedMedia = media
|
self.preUploadedMedia = media
|
||||||
}
|
}
|
||||||
.alert(NSLocalizedString("Are you sure you want to upload this image?", comment: "Alert message asking if the user wants to upload an image."), isPresented: $image_upload_confirm) {
|
.alert(NSLocalizedString("Are you sure you want to upload this image?", comment: "Alert message asking if the user wants to upload an image."), isPresented: $image_upload_confirm) {
|
||||||
@@ -195,7 +196,7 @@ struct EditPictureControl: View {
|
|||||||
private func handle_upload(media: MediaUpload) {
|
private func handle_upload(media: MediaUpload) {
|
||||||
uploadObserver.isLoading = true
|
uploadObserver.isLoading = true
|
||||||
Task {
|
Task {
|
||||||
let res = await image_upload.start(media: media, uploader: uploader)
|
let res = await image_upload.start(media: media, uploader: uploader, keypair: keypair)
|
||||||
|
|
||||||
switch res {
|
switch res {
|
||||||
case .success(let urlString):
|
case .success(let urlString):
|
||||||
@@ -221,7 +222,7 @@ struct EditPictureControl_Previews: PreviewProvider {
|
|||||||
let observer = ImageUploadingObserver()
|
let observer = ImageUploadingObserver()
|
||||||
ZStack {
|
ZStack {
|
||||||
Color.gray
|
Color.gray
|
||||||
EditPictureControl(uploader: .nostrBuild, pubkey: test_pubkey, size: 100, setup: false, image_url: url, uploadObserver: observer) { _ in
|
EditPictureControl(uploader: .nostrBuild, keypair: test_keypair, pubkey: test_pubkey, size: 100, setup: false, image_url: url, uploadObserver: observer) { _ in
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ struct EditProfilePictureView: View {
|
|||||||
.scaledToFill()
|
.scaledToFill()
|
||||||
.kfClickable()
|
.kfClickable()
|
||||||
|
|
||||||
EditPictureControl(uploader: damus_state?.settings.default_media_uploader ?? .nostrBuild, pubkey: pubkey, image_url: $profile_url, uploadObserver: uploadObserver, callback: callback)
|
EditPictureControl(uploader: damus_state?.settings.default_media_uploader ?? .nostrBuild, keypair: damus_state?.keypair, pubkey: pubkey, image_url: $profile_url, uploadObserver: uploadObserver, callback: callback)
|
||||||
}
|
}
|
||||||
.frame(width: size, height: size)
|
.frame(width: size, height: size)
|
||||||
.clipShape(Circle())
|
.clipShape(Circle())
|
||||||
|
|||||||
Reference in New Issue
Block a user