Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes alerts when uploading big files and suggests users subscribe to nostr.build #1321

Merged
merged 30 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b17ed98
non-functional update of layout for upload alerts
rabble Jul 20, 2024
fde083b
fixed one problem with localization strings, still stuck on calling t…
rabble Jul 23, 2024
4564fbf
fixed one problem with localization strings, still stuck on calling t…
rabble Jul 23, 2024
e66b0b7
added fix to help users with suggestion to pay for nostr.build to upl…
rabble Jul 23, 2024
f477447
Merge branch 'main' into large_file_upload_error
rabble Jul 23, 2024
c9f73fb
fixes error message when file size is too big by adding error to File…
rabble Jul 24, 2024
b74027b
fixes error message when file size is too big by adding error to File…
rabble Jul 24, 2024
877edd5
Update Nos/Assets/Localization/ImagePicker.xcstrings
rabble Jul 25, 2024
6f61dea
Update Nos/Assets/Localization/ImagePicker.xcstrings
rabble Jul 25, 2024
37d18a3
Update Nos/Assets/Localization/ImagePicker.xcstrings
rabble Jul 25, 2024
25cc94b
Update Nos/Assets/Localization/ImagePicker.xcstrings
rabble Jul 25, 2024
dc1dd5b
reverting package.resolved file
rabble Jul 25, 2024
862c384
adding changelog for file upload error screen
rabble Jul 30, 2024
b3f88fd
Update Nos/Views/New Note/ComposerActionBar.swift
rabble Jul 30, 2024
b4c64f1
Update Nos/Views/New Note/ComposerActionBar.swift
rabble Jul 30, 2024
e6cd12e
Merge branch 'main' into large_file_upload_error
mplorentz Jul 31, 2024
c74b82a
Fix swiftlint errors
mplorentz Jul 31, 2024
ac9c72f
Merge branch 'main' into large_file_upload_error
mplorentz Jul 31, 2024
e1eb233
Merge remote-tracking branch 'origin/main' into large_file_upload_error
pelumy Sep 11, 2024
19ede8b
differentiate buttons to show on alert for large files from other errors
pelumy Sep 11, 2024
781ab37
fix minor swiftlint warnings
pelumy Sep 11, 2024
cd298aa
make function body length shorter to fix swiftlint error
pelumy Sep 11, 2024
a3129c1
fix more swiftlint warnings
pelumy Sep 11, 2024
8276f18
Merge branch 'main' into large_file_upload_error
pelumy Sep 11, 2024
a24d659
Merge branch 'main' into large_file_upload_error
pelumy Sep 12, 2024
4be1b8c
check for error code 413
pelumy Sep 12, 2024
0b5eef9
Merge branch 'main' into large_file_upload_error
pelumy Sep 12, 2024
d9d357a
refactored regular expression for file size limit
joshuatbrown Sep 13, 2024
2aeab85
refactor createAlert function
pelumy Sep 13, 2024
d15cdf4
Update premium nostr url string
pelumy Sep 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
rabble marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"originHash" : "73986e8614e86bc198acf108f9214c158dd0475e95a9469983fe7e59ac1890a1",
"pins" : [
{
"identity" : "bech32",
Expand Down Expand Up @@ -216,5 +217,5 @@
}
}
],
"version": 2
"version" : 3
}
117 changes: 117 additions & 0 deletions Nos/Assets/Localization/ImagePicker.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
"value" : "Camera"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Cámera"
rabble marked this conversation as resolved.
Show resolved Hide resolved
}
},
"fa" : {
"stringUnit" : {
"state" : "translated",
Expand Down Expand Up @@ -57,6 +63,12 @@
"value" : "Camera is not available on this device"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "La cámara no esta disponible en este aparato"
}
},
"fa" : {
"stringUnit" : {
"state" : "translated",
Expand Down Expand Up @@ -98,6 +110,12 @@
"value" : "Error uploading the file"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Error subiendo el archivo"
}
},
"fa" : {
"stringUnit" : {
"state" : "translated",
Expand All @@ -124,6 +142,40 @@
}
}
},
"errorUploadingFileExceedsLimit" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "The max file size for free media uploads is of %@. To upload large files, upgrade to a Nostr.build Professional account."
rabble marked this conversation as resolved.
Show resolved Hide resolved
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "El maximo tamaño para publicacion de achivos gratis es $@. Para subir archives mas grande puedes pagar para subscribir a una cuenta Nostr.build pro."
rabble marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
},
"errorUploadingFileExceedsSizeLimit" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Get a Nostr.build account to upload larger files"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Registarse para una cuenta pro de Nostr.build para la abilidad de subir archivos mas grande"
}
}
}
},
"errorUploadingFileMessage" : {
"extractionState" : "manual",
"localizations" : {
Expand All @@ -139,6 +191,12 @@
"value" : "An error was encountered when uploading the file you provided. Please try again."
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Hubo un error en el intento de subir archivos. Porfavor intenta de vuelta."
}
},
"fa" : {
"stringUnit" : {
"state" : "translated",
Expand Down Expand Up @@ -173,6 +231,29 @@
"state" : "translated",
"value" : "An error was encountered when uploading the file you provided. The message was: \"%@\""
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Hubo un error en el intento de subir el archivo. El mensaje de error era\"%@\""
}
}
}
},
"getAccount" : {
"extractionState" : "manual",
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Get Account"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Registar una Cuenta"
}
}
}
},
Expand All @@ -191,6 +272,12 @@
"value" : "You can allow camera permissions by opening the Settings app."
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Puedes dar permiso a aceder la cámera en el app de configuraciones."
rabble marked this conversation as resolved.
Show resolved Hide resolved
}
},
"fa" : {
"stringUnit" : {
"state" : "translated",
Expand Down Expand Up @@ -232,6 +319,12 @@
"value" : "Permissions required for %@"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Prescisa permiso para %@"
}
},
"fa" : {
"stringUnit" : {
"state" : "translated",
Expand Down Expand Up @@ -273,6 +366,12 @@
"value" : "Photo Library"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Bibiloteca de Fotos"
}
},
"fa" : {
"stringUnit" : {
"state" : "translated",
Expand Down Expand Up @@ -314,6 +413,12 @@
"value" : "Select from Photo Library"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Elijir fotos en la biblioteca"
}
},
"fa" : {
"stringUnit" : {
"state" : "translated",
Expand Down Expand Up @@ -355,6 +460,12 @@
"value" : "Take photo or video"
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Sacar un foto o video"
}
},
"fa" : {
"stringUnit" : {
"state" : "needs_review",
Expand Down Expand Up @@ -396,6 +507,12 @@
"value" : "Uploading..."
}
},
"es" : {
"stringUnit" : {
"state" : "translated",
"value" : "Subiendo... "
}
},
"fa" : {
"stringUnit" : {
"state" : "translated",
Expand Down
20 changes: 19 additions & 1 deletion Nos/Service/FileStorage/FileStorageAPIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ enum FileStorageAPIClientError: Error {
case invalidResponseURL(String)
case invalidURLRequest
case missingKeyPair
case fileTooBig(String?)
case uploadFailed(String?)
}

Expand Down Expand Up @@ -59,9 +60,26 @@ class NostrBuildAPIClient: FileStorageAPIClient {
let (responseData, _) = try await URLSession.shared.upload(for: request, from: data)

let response = try decoder.decode(FileStorageUploadResponseJSON.self, from: responseData)

guard let urlString = response.nip94Event?.urlString else {
throw FileStorageAPIClientError.uploadFailed(response.message)
// Ensure there's a message in the response, use an empty string if not
let message = response.message ?? ""

// Check to see if the error message mentions the file size
rabble marked this conversation as resolved.
Show resolved Hide resolved
if let regex = try? NSRegularExpression(
pattern: "File size exceeds the limit of (\\d*\\.\\d* [MKGT]B)",
options: []
),
let match = regex.firstMatch(in: message, options: [], range: NSRange(location: 0, length: message.utf16.count)),
let range = Range(match.range(at: 1), in: message) {
let fileSizeLimit = String(message[range])
throw FileStorageAPIClientError.fileTooBig(fileSizeLimit)
} else {
// The error is something else.
throw FileStorageAPIClientError.uploadFailed(message)
}
}

guard let url = URL(string: urlString) else {
throw FileStorageAPIClientError.invalidResponseURL(urlString)
}
Expand Down
59 changes: 48 additions & 11 deletions Nos/Views/New Note/ComposerActionBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ struct ComposerActionBar: View {
@State private var alert: AlertState<AlertAction>?

fileprivate enum AlertAction {
case cancel
case getAccount
}

var backArrow: some View {
Expand Down Expand Up @@ -53,16 +55,40 @@ struct ComposerActionBar: View {
endUploadingImage()
print("error uploading: \(error)")

alert = AlertState(title: {
TextState(String(localized: .imagePicker.errorUploadingFile))
}, message: {
if case let FileStorageAPIClientError.uploadFailed(message) = error,
let message {
TextState(String(localized: .imagePicker.errorUploadingFileWithMessage(message)))
} else {
TextState(String(localized: .imagePicker.errorUploadingFileMessage))
}
})
alert = AlertState<ComposerActionBar.AlertAction>(
title: {
if case FileStorageAPIClientError.fileTooBig = error {
return TextState(
String(localized: .imagePicker.errorUploadingFileExceedsSizeLimit)
)
} else {
return TextState(String(localized: .imagePicker.errorUploadingFile))
}
}(),
message: {
if case let FileStorageAPIClientError.fileTooBig(message) = error, let message = message {
rabble marked this conversation as resolved.
Show resolved Hide resolved
return TextState(
String(localized: .imagePicker.errorUploadingFileExceedsLimit(message))
)
} else if case let FileStorageAPIClientError.uploadFailed(message) = error, let message = message {
rabble marked this conversation as resolved.
Show resolved Hide resolved
return TextState(
String(localized: .imagePicker.errorUploadingFileWithMessage(message))
)
} else {
return TextState(String(localized: .imagePicker.errorUploadingFileMessage))
}
}(),
buttons: [
.cancel(
TextState(
String(localized: .localizable.cancel)), action: .send(.cancel)
),
.default(
TextState(
String(localized: .imagePicker.getAccount)), action: .send(.getAccount)
)
]
)
}
}
} label: {
Expand Down Expand Up @@ -118,7 +144,18 @@ struct ComposerActionBar: View {
.onChange(of: expirationTime) { _, _ in
subMenu = .none
}
.alert(unwrapping: $alert) { (_: AlertAction?) in
.alert(unwrapping: $alert) { action in
switch action {
case .cancel:
// Handle cancel action if needed
break
case .getAccount:
if let url = URL(string: "https://nostr.build") {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
default:
break
}
}
.background(
LinearGradient(
Expand Down
Loading