diff --git a/lib/helpers/ipfs_link_attach_flow.dart b/lib/helpers/ipfs_link_attach_flow.dart index 98bfa828..e1cb6530 100644 --- a/lib/helpers/ipfs_link_attach_flow.dart +++ b/lib/helpers/ipfs_link_attach_flow.dart @@ -4,6 +4,7 @@ import 'package:file_selector/file_selector.dart' as file_selector; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; +import '../l10n/app_localizations.dart'; import '../l10n/l10n.dart'; import '../services/app_settings_service.dart'; import 'ipfs_upload_helper.dart'; @@ -58,7 +59,7 @@ Future attachIpfsLinkToDraft({ if (!context.mounted) return; showDismissibleSnackBar( context, - content: Text(l10n.chat_ipfsUploadFailed('$error')), + content: Text(ipfsUploadErrorText(l10n, error)), ); } @@ -69,7 +70,10 @@ Future attachIpfsLinkToDraft({ final bytes = await file.readAsBytes(); if (!context.mounted) return; if (bytes.isEmpty) { - showFailure('The selected file is empty.'); + showDismissibleSnackBar( + context, + content: Text(l10n.chat_ipfsSelectedFileEmpty), + ); return; } messageUrl = await IpfsUploadHelper.uploadImageWithSettings( @@ -108,6 +112,25 @@ Future attachIpfsLinkToDraft({ } } +/// The localized snackbar text for an upload [error]: config problems get a +/// specific message, anything else a generic one with technical details. +@visibleForTesting +String ipfsUploadErrorText(AppLocalizations l10n, Object error) { + if (error is IpfsUploadConfigException) { + return switch (error.reason) { + IpfsUploadConfigError.emptyEndpoint => l10n.chat_ipfsUploadNotConfigured, + IpfsUploadConfigError.invalidEndpoint => l10n.chat_ipfsEndpointInvalid, + IpfsUploadConfigError.pinataTokenMissing => + l10n.chat_ipfsPinataTokenMissing, + IpfsUploadConfigError.filebaseTokenMissing => + l10n.chat_ipfsFilebaseTokenMissing, + IpfsUploadConfigError.kuboPathInvalid => l10n.chat_ipfsKuboPathInvalid, + }; + } + final details = '$error'.replaceFirst(RegExp(r'^Exception: '), ''); + return l10n.chat_ipfsUploadFailed(details); +} + /// Puts [messageUrl] in front of [existingText], leaving the text intact. @visibleForTesting String composeIpfsLinkDraft({ diff --git a/lib/helpers/ipfs_upload_helper.dart b/lib/helpers/ipfs_upload_helper.dart index 84c32e9d..7f6e36e1 100644 --- a/lib/helpers/ipfs_upload_helper.dart +++ b/lib/helpers/ipfs_upload_helper.dart @@ -5,15 +5,24 @@ import 'package:http/http.dart' as http; import '../models/app_settings.dart'; -/// Thrown when the IPFS upload settings can't be used, before or instead of -/// a network failure. -class IpfsUploadConfigException implements Exception { - const IpfsUploadConfigException(this.message); +/// Why the IPFS upload settings can't be used. +enum IpfsUploadConfigError { + emptyEndpoint, + invalidEndpoint, + pinataTokenMissing, + filebaseTokenMissing, + kuboPathInvalid, +} - final String message; +/// Thrown when the IPFS upload settings can't be used, before or instead of +/// a network failure. The UI maps [reason] to a localized message. +class IpfsUploadConfigException implements Exception { + const IpfsUploadConfigException(this.reason); + + final IpfsUploadConfigError reason; @override - String toString() => message; + String toString() => 'IpfsUploadConfigException(${reason.name})'; } class IpfsUploadHelper { @@ -80,7 +89,7 @@ class IpfsUploadHelper { final endpoint = uploadEndpoint.trim(); if (endpoint.isEmpty) { throw const IpfsUploadConfigException( - 'Configure an IPFS upload endpoint first.', + IpfsUploadConfigError.emptyEndpoint, ); } @@ -89,7 +98,7 @@ class IpfsUploadHelper { !(endpointUri.isScheme('http') || endpointUri.isScheme('https')) || endpointUri.host.isEmpty) { throw const IpfsUploadConfigException( - 'The IPFS upload endpoint must be an http(s) URL.', + IpfsUploadConfigError.invalidEndpoint, ); } @@ -103,17 +112,17 @@ class IpfsUploadHelper { final safeFileName = _sanitizeUploadFileName(fileName); if (isPinata && token.isEmpty) { throw const IpfsUploadConfigException( - 'Pinata requires an API key or JWT.', + IpfsUploadConfigError.pinataTokenMissing, ); } if (isFilebase && token.isEmpty) { throw const IpfsUploadConfigException( - 'Filebase RPC requires an API token.', + IpfsUploadConfigError.filebaseTokenMissing, ); } if (isKubo && !_kuboAddPath.hasMatch(endpointUri.path)) { throw const IpfsUploadConfigException( - 'Custom (Kubo) upload endpoint must end with /api/v0/add.', + IpfsUploadConfigError.kuboPathInvalid, ); } diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index dc636bb3..a983cd68 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -953,6 +953,11 @@ } }, "chat_ipfsUploadNotConfigured": "Configure an IPFS upload provider in App Settings first.", + "chat_ipfsSelectedFileEmpty": "The selected file is empty.", + "chat_ipfsEndpointInvalid": "The IPFS upload endpoint must be a full http:// or https:// address. Check it in App Settings.", + "chat_ipfsPinataTokenMissing": "Pinata needs an API key or JWT. Add it in App Settings.", + "chat_ipfsFilebaseTokenMissing": "Filebase needs an API token. Add it in App Settings.", + "chat_ipfsKuboPathInvalid": "The Kubo upload endpoint must end with /api/v0/add. Check it in App Settings.", "chat_ipfsLinkNoRoom": "Not enough room for the image link. Shorten your message, then try again.", "@chat_ipfsLinkNoRoom": { "description": "Shown before an IPFS upload when the link would push the draft over the message size limit" diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart index f0ef56b2..ddf5d278 100644 --- a/lib/l10n/app_localizations.dart +++ b/lib/l10n/app_localizations.dart @@ -3286,6 +3286,36 @@ abstract class AppLocalizations { /// **'Configure an IPFS upload provider in App Settings first.'** String get chat_ipfsUploadNotConfigured; + /// No description provided for @chat_ipfsSelectedFileEmpty. + /// + /// In en, this message translates to: + /// **'The selected file is empty.'** + String get chat_ipfsSelectedFileEmpty; + + /// No description provided for @chat_ipfsEndpointInvalid. + /// + /// In en, this message translates to: + /// **'The IPFS upload endpoint must be a full http:// or https:// address. Check it in App Settings.'** + String get chat_ipfsEndpointInvalid; + + /// No description provided for @chat_ipfsPinataTokenMissing. + /// + /// In en, this message translates to: + /// **'Pinata needs an API key or JWT. Add it in App Settings.'** + String get chat_ipfsPinataTokenMissing; + + /// No description provided for @chat_ipfsFilebaseTokenMissing. + /// + /// In en, this message translates to: + /// **'Filebase needs an API token. Add it in App Settings.'** + String get chat_ipfsFilebaseTokenMissing; + + /// No description provided for @chat_ipfsKuboPathInvalid. + /// + /// In en, this message translates to: + /// **'The Kubo upload endpoint must end with /api/v0/add. Check it in App Settings.'** + String get chat_ipfsKuboPathInvalid; + /// Shown before an IPFS upload when the link would push the draft over the message size limit /// /// In en, this message translates to: diff --git a/lib/l10n/app_localizations_bg.dart b/lib/l10n/app_localizations_bg.dart index 8d8f2062..07d5a4b4 100644 --- a/lib/l10n/app_localizations_bg.dart +++ b/lib/l10n/app_localizations_bg.dart @@ -1850,6 +1850,25 @@ class AppLocalizationsBg extends AppLocalizations { String get chat_ipfsUploadNotConfigured => 'Configure an IPFS upload provider in App Settings first.'; + @override + String get chat_ipfsSelectedFileEmpty => 'The selected file is empty.'; + + @override + String get chat_ipfsEndpointInvalid => + 'The IPFS upload endpoint must be a full http:// or https:// address. Check it in App Settings.'; + + @override + String get chat_ipfsPinataTokenMissing => + 'Pinata needs an API key or JWT. Add it in App Settings.'; + + @override + String get chat_ipfsFilebaseTokenMissing => + 'Filebase needs an API token. Add it in App Settings.'; + + @override + String get chat_ipfsKuboPathInvalid => + 'The Kubo upload endpoint must end with /api/v0/add. Check it in App Settings.'; + @override String get chat_ipfsLinkNoRoom => 'Not enough room for the image link. Shorten your message, then try again.'; diff --git a/lib/l10n/app_localizations_de.dart b/lib/l10n/app_localizations_de.dart index 66d31e7c..029d73b0 100644 --- a/lib/l10n/app_localizations_de.dart +++ b/lib/l10n/app_localizations_de.dart @@ -1849,6 +1849,25 @@ class AppLocalizationsDe extends AppLocalizations { String get chat_ipfsUploadNotConfigured => 'Configure an IPFS upload provider in App Settings first.'; + @override + String get chat_ipfsSelectedFileEmpty => 'The selected file is empty.'; + + @override + String get chat_ipfsEndpointInvalid => + 'The IPFS upload endpoint must be a full http:// or https:// address. Check it in App Settings.'; + + @override + String get chat_ipfsPinataTokenMissing => + 'Pinata needs an API key or JWT. Add it in App Settings.'; + + @override + String get chat_ipfsFilebaseTokenMissing => + 'Filebase needs an API token. Add it in App Settings.'; + + @override + String get chat_ipfsKuboPathInvalid => + 'The Kubo upload endpoint must end with /api/v0/add. Check it in App Settings.'; + @override String get chat_ipfsLinkNoRoom => 'Not enough room for the image link. Shorten your message, then try again.'; diff --git a/lib/l10n/app_localizations_en.dart b/lib/l10n/app_localizations_en.dart index eec87fe4..9a3ad0e1 100644 --- a/lib/l10n/app_localizations_en.dart +++ b/lib/l10n/app_localizations_en.dart @@ -1818,6 +1818,25 @@ class AppLocalizationsEn extends AppLocalizations { String get chat_ipfsUploadNotConfigured => 'Configure an IPFS upload provider in App Settings first.'; + @override + String get chat_ipfsSelectedFileEmpty => 'The selected file is empty.'; + + @override + String get chat_ipfsEndpointInvalid => + 'The IPFS upload endpoint must be a full http:// or https:// address. Check it in App Settings.'; + + @override + String get chat_ipfsPinataTokenMissing => + 'Pinata needs an API key or JWT. Add it in App Settings.'; + + @override + String get chat_ipfsFilebaseTokenMissing => + 'Filebase needs an API token. Add it in App Settings.'; + + @override + String get chat_ipfsKuboPathInvalid => + 'The Kubo upload endpoint must end with /api/v0/add. Check it in App Settings.'; + @override String get chat_ipfsLinkNoRoom => 'Not enough room for the image link. Shorten your message, then try again.'; diff --git a/lib/l10n/app_localizations_es.dart b/lib/l10n/app_localizations_es.dart index a5941d81..224bcffb 100644 --- a/lib/l10n/app_localizations_es.dart +++ b/lib/l10n/app_localizations_es.dart @@ -1845,6 +1845,25 @@ class AppLocalizationsEs extends AppLocalizations { String get chat_ipfsUploadNotConfigured => 'Configure an IPFS upload provider in App Settings first.'; + @override + String get chat_ipfsSelectedFileEmpty => 'The selected file is empty.'; + + @override + String get chat_ipfsEndpointInvalid => + 'The IPFS upload endpoint must be a full http:// or https:// address. Check it in App Settings.'; + + @override + String get chat_ipfsPinataTokenMissing => + 'Pinata needs an API key or JWT. Add it in App Settings.'; + + @override + String get chat_ipfsFilebaseTokenMissing => + 'Filebase needs an API token. Add it in App Settings.'; + + @override + String get chat_ipfsKuboPathInvalid => + 'The Kubo upload endpoint must end with /api/v0/add. Check it in App Settings.'; + @override String get chat_ipfsLinkNoRoom => 'Not enough room for the image link. Shorten your message, then try again.'; diff --git a/lib/l10n/app_localizations_fr.dart b/lib/l10n/app_localizations_fr.dart index 116726ec..dbf6d032 100644 --- a/lib/l10n/app_localizations_fr.dart +++ b/lib/l10n/app_localizations_fr.dart @@ -1849,6 +1849,25 @@ class AppLocalizationsFr extends AppLocalizations { String get chat_ipfsUploadNotConfigured => 'Configure an IPFS upload provider in App Settings first.'; + @override + String get chat_ipfsSelectedFileEmpty => 'The selected file is empty.'; + + @override + String get chat_ipfsEndpointInvalid => + 'The IPFS upload endpoint must be a full http:// or https:// address. Check it in App Settings.'; + + @override + String get chat_ipfsPinataTokenMissing => + 'Pinata needs an API key or JWT. Add it in App Settings.'; + + @override + String get chat_ipfsFilebaseTokenMissing => + 'Filebase needs an API token. Add it in App Settings.'; + + @override + String get chat_ipfsKuboPathInvalid => + 'The Kubo upload endpoint must end with /api/v0/add. Check it in App Settings.'; + @override String get chat_ipfsLinkNoRoom => 'Not enough room for the image link. Shorten your message, then try again.'; diff --git a/lib/l10n/app_localizations_hu.dart b/lib/l10n/app_localizations_hu.dart index 2ffb5823..99c64638 100644 --- a/lib/l10n/app_localizations_hu.dart +++ b/lib/l10n/app_localizations_hu.dart @@ -1839,6 +1839,25 @@ class AppLocalizationsHu extends AppLocalizations { String get chat_ipfsUploadNotConfigured => 'Configure an IPFS upload provider in App Settings first.'; + @override + String get chat_ipfsSelectedFileEmpty => 'The selected file is empty.'; + + @override + String get chat_ipfsEndpointInvalid => + 'The IPFS upload endpoint must be a full http:// or https:// address. Check it in App Settings.'; + + @override + String get chat_ipfsPinataTokenMissing => + 'Pinata needs an API key or JWT. Add it in App Settings.'; + + @override + String get chat_ipfsFilebaseTokenMissing => + 'Filebase needs an API token. Add it in App Settings.'; + + @override + String get chat_ipfsKuboPathInvalid => + 'The Kubo upload endpoint must end with /api/v0/add. Check it in App Settings.'; + @override String get chat_ipfsLinkNoRoom => 'Not enough room for the image link. Shorten your message, then try again.'; diff --git a/lib/l10n/app_localizations_it.dart b/lib/l10n/app_localizations_it.dart index 50025be5..664fcfeb 100644 --- a/lib/l10n/app_localizations_it.dart +++ b/lib/l10n/app_localizations_it.dart @@ -1849,6 +1849,25 @@ class AppLocalizationsIt extends AppLocalizations { String get chat_ipfsUploadNotConfigured => 'Configure an IPFS upload provider in App Settings first.'; + @override + String get chat_ipfsSelectedFileEmpty => 'The selected file is empty.'; + + @override + String get chat_ipfsEndpointInvalid => + 'The IPFS upload endpoint must be a full http:// or https:// address. Check it in App Settings.'; + + @override + String get chat_ipfsPinataTokenMissing => + 'Pinata needs an API key or JWT. Add it in App Settings.'; + + @override + String get chat_ipfsFilebaseTokenMissing => + 'Filebase needs an API token. Add it in App Settings.'; + + @override + String get chat_ipfsKuboPathInvalid => + 'The Kubo upload endpoint must end with /api/v0/add. Check it in App Settings.'; + @override String get chat_ipfsLinkNoRoom => 'Not enough room for the image link. Shorten your message, then try again.'; diff --git a/lib/l10n/app_localizations_ja.dart b/lib/l10n/app_localizations_ja.dart index e62ca29b..a13697ac 100644 --- a/lib/l10n/app_localizations_ja.dart +++ b/lib/l10n/app_localizations_ja.dart @@ -1762,6 +1762,25 @@ class AppLocalizationsJa extends AppLocalizations { String get chat_ipfsUploadNotConfigured => 'Configure an IPFS upload provider in App Settings first.'; + @override + String get chat_ipfsSelectedFileEmpty => 'The selected file is empty.'; + + @override + String get chat_ipfsEndpointInvalid => + 'The IPFS upload endpoint must be a full http:// or https:// address. Check it in App Settings.'; + + @override + String get chat_ipfsPinataTokenMissing => + 'Pinata needs an API key or JWT. Add it in App Settings.'; + + @override + String get chat_ipfsFilebaseTokenMissing => + 'Filebase needs an API token. Add it in App Settings.'; + + @override + String get chat_ipfsKuboPathInvalid => + 'The Kubo upload endpoint must end with /api/v0/add. Check it in App Settings.'; + @override String get chat_ipfsLinkNoRoom => 'Not enough room for the image link. Shorten your message, then try again.'; diff --git a/lib/l10n/app_localizations_ko.dart b/lib/l10n/app_localizations_ko.dart index e2968f56..877eef52 100644 --- a/lib/l10n/app_localizations_ko.dart +++ b/lib/l10n/app_localizations_ko.dart @@ -1767,6 +1767,25 @@ class AppLocalizationsKo extends AppLocalizations { String get chat_ipfsUploadNotConfigured => 'Configure an IPFS upload provider in App Settings first.'; + @override + String get chat_ipfsSelectedFileEmpty => 'The selected file is empty.'; + + @override + String get chat_ipfsEndpointInvalid => + 'The IPFS upload endpoint must be a full http:// or https:// address. Check it in App Settings.'; + + @override + String get chat_ipfsPinataTokenMissing => + 'Pinata needs an API key or JWT. Add it in App Settings.'; + + @override + String get chat_ipfsFilebaseTokenMissing => + 'Filebase needs an API token. Add it in App Settings.'; + + @override + String get chat_ipfsKuboPathInvalid => + 'The Kubo upload endpoint must end with /api/v0/add. Check it in App Settings.'; + @override String get chat_ipfsLinkNoRoom => 'Not enough room for the image link. Shorten your message, then try again.'; diff --git a/lib/l10n/app_localizations_nl.dart b/lib/l10n/app_localizations_nl.dart index 4b64c5f5..a976169b 100644 --- a/lib/l10n/app_localizations_nl.dart +++ b/lib/l10n/app_localizations_nl.dart @@ -1835,6 +1835,25 @@ class AppLocalizationsNl extends AppLocalizations { String get chat_ipfsUploadNotConfigured => 'Configure an IPFS upload provider in App Settings first.'; + @override + String get chat_ipfsSelectedFileEmpty => 'The selected file is empty.'; + + @override + String get chat_ipfsEndpointInvalid => + 'The IPFS upload endpoint must be a full http:// or https:// address. Check it in App Settings.'; + + @override + String get chat_ipfsPinataTokenMissing => + 'Pinata needs an API key or JWT. Add it in App Settings.'; + + @override + String get chat_ipfsFilebaseTokenMissing => + 'Filebase needs an API token. Add it in App Settings.'; + + @override + String get chat_ipfsKuboPathInvalid => + 'The Kubo upload endpoint must end with /api/v0/add. Check it in App Settings.'; + @override String get chat_ipfsLinkNoRoom => 'Not enough room for the image link. Shorten your message, then try again.'; diff --git a/lib/l10n/app_localizations_pl.dart b/lib/l10n/app_localizations_pl.dart index 6fc4644f..86a88110 100644 --- a/lib/l10n/app_localizations_pl.dart +++ b/lib/l10n/app_localizations_pl.dart @@ -1864,6 +1864,25 @@ class AppLocalizationsPl extends AppLocalizations { String get chat_ipfsUploadNotConfigured => 'Configure an IPFS upload provider in App Settings first.'; + @override + String get chat_ipfsSelectedFileEmpty => 'The selected file is empty.'; + + @override + String get chat_ipfsEndpointInvalid => + 'The IPFS upload endpoint must be a full http:// or https:// address. Check it in App Settings.'; + + @override + String get chat_ipfsPinataTokenMissing => + 'Pinata needs an API key or JWT. Add it in App Settings.'; + + @override + String get chat_ipfsFilebaseTokenMissing => + 'Filebase needs an API token. Add it in App Settings.'; + + @override + String get chat_ipfsKuboPathInvalid => + 'The Kubo upload endpoint must end with /api/v0/add. Check it in App Settings.'; + @override String get chat_ipfsLinkNoRoom => 'Not enough room for the image link. Shorten your message, then try again.'; diff --git a/lib/l10n/app_localizations_pt.dart b/lib/l10n/app_localizations_pt.dart index bc7b746e..3eab9ac0 100644 --- a/lib/l10n/app_localizations_pt.dart +++ b/lib/l10n/app_localizations_pt.dart @@ -1845,6 +1845,25 @@ class AppLocalizationsPt extends AppLocalizations { String get chat_ipfsUploadNotConfigured => 'Configure an IPFS upload provider in App Settings first.'; + @override + String get chat_ipfsSelectedFileEmpty => 'The selected file is empty.'; + + @override + String get chat_ipfsEndpointInvalid => + 'The IPFS upload endpoint must be a full http:// or https:// address. Check it in App Settings.'; + + @override + String get chat_ipfsPinataTokenMissing => + 'Pinata needs an API key or JWT. Add it in App Settings.'; + + @override + String get chat_ipfsFilebaseTokenMissing => + 'Filebase needs an API token. Add it in App Settings.'; + + @override + String get chat_ipfsKuboPathInvalid => + 'The Kubo upload endpoint must end with /api/v0/add. Check it in App Settings.'; + @override String get chat_ipfsLinkNoRoom => 'Not enough room for the image link. Shorten your message, then try again.'; diff --git a/lib/l10n/app_localizations_ru.dart b/lib/l10n/app_localizations_ru.dart index 0793eafe..3c296bfc 100644 --- a/lib/l10n/app_localizations_ru.dart +++ b/lib/l10n/app_localizations_ru.dart @@ -1849,6 +1849,25 @@ class AppLocalizationsRu extends AppLocalizations { String get chat_ipfsUploadNotConfigured => 'Configure an IPFS upload provider in App Settings first.'; + @override + String get chat_ipfsSelectedFileEmpty => 'The selected file is empty.'; + + @override + String get chat_ipfsEndpointInvalid => + 'The IPFS upload endpoint must be a full http:// or https:// address. Check it in App Settings.'; + + @override + String get chat_ipfsPinataTokenMissing => + 'Pinata needs an API key or JWT. Add it in App Settings.'; + + @override + String get chat_ipfsFilebaseTokenMissing => + 'Filebase needs an API token. Add it in App Settings.'; + + @override + String get chat_ipfsKuboPathInvalid => + 'The Kubo upload endpoint must end with /api/v0/add. Check it in App Settings.'; + @override String get chat_ipfsLinkNoRoom => 'Not enough room for the image link. Shorten your message, then try again.'; diff --git a/lib/l10n/app_localizations_sk.dart b/lib/l10n/app_localizations_sk.dart index efa338ae..db844a58 100644 --- a/lib/l10n/app_localizations_sk.dart +++ b/lib/l10n/app_localizations_sk.dart @@ -1837,6 +1837,25 @@ class AppLocalizationsSk extends AppLocalizations { String get chat_ipfsUploadNotConfigured => 'Configure an IPFS upload provider in App Settings first.'; + @override + String get chat_ipfsSelectedFileEmpty => 'The selected file is empty.'; + + @override + String get chat_ipfsEndpointInvalid => + 'The IPFS upload endpoint must be a full http:// or https:// address. Check it in App Settings.'; + + @override + String get chat_ipfsPinataTokenMissing => + 'Pinata needs an API key or JWT. Add it in App Settings.'; + + @override + String get chat_ipfsFilebaseTokenMissing => + 'Filebase needs an API token. Add it in App Settings.'; + + @override + String get chat_ipfsKuboPathInvalid => + 'The Kubo upload endpoint must end with /api/v0/add. Check it in App Settings.'; + @override String get chat_ipfsLinkNoRoom => 'Not enough room for the image link. Shorten your message, then try again.'; diff --git a/lib/l10n/app_localizations_sl.dart b/lib/l10n/app_localizations_sl.dart index 87154737..2cdd59bf 100644 --- a/lib/l10n/app_localizations_sl.dart +++ b/lib/l10n/app_localizations_sl.dart @@ -1836,6 +1836,25 @@ class AppLocalizationsSl extends AppLocalizations { String get chat_ipfsUploadNotConfigured => 'Configure an IPFS upload provider in App Settings first.'; + @override + String get chat_ipfsSelectedFileEmpty => 'The selected file is empty.'; + + @override + String get chat_ipfsEndpointInvalid => + 'The IPFS upload endpoint must be a full http:// or https:// address. Check it in App Settings.'; + + @override + String get chat_ipfsPinataTokenMissing => + 'Pinata needs an API key or JWT. Add it in App Settings.'; + + @override + String get chat_ipfsFilebaseTokenMissing => + 'Filebase needs an API token. Add it in App Settings.'; + + @override + String get chat_ipfsKuboPathInvalid => + 'The Kubo upload endpoint must end with /api/v0/add. Check it in App Settings.'; + @override String get chat_ipfsLinkNoRoom => 'Not enough room for the image link. Shorten your message, then try again.'; diff --git a/lib/l10n/app_localizations_sv.dart b/lib/l10n/app_localizations_sv.dart index acbc7b41..436bdb62 100644 --- a/lib/l10n/app_localizations_sv.dart +++ b/lib/l10n/app_localizations_sv.dart @@ -1824,6 +1824,25 @@ class AppLocalizationsSv extends AppLocalizations { String get chat_ipfsUploadNotConfigured => 'Configure an IPFS upload provider in App Settings first.'; + @override + String get chat_ipfsSelectedFileEmpty => 'The selected file is empty.'; + + @override + String get chat_ipfsEndpointInvalid => + 'The IPFS upload endpoint must be a full http:// or https:// address. Check it in App Settings.'; + + @override + String get chat_ipfsPinataTokenMissing => + 'Pinata needs an API key or JWT. Add it in App Settings.'; + + @override + String get chat_ipfsFilebaseTokenMissing => + 'Filebase needs an API token. Add it in App Settings.'; + + @override + String get chat_ipfsKuboPathInvalid => + 'The Kubo upload endpoint must end with /api/v0/add. Check it in App Settings.'; + @override String get chat_ipfsLinkNoRoom => 'Not enough room for the image link. Shorten your message, then try again.'; diff --git a/lib/l10n/app_localizations_uk.dart b/lib/l10n/app_localizations_uk.dart index 65e1df41..02b3bc27 100644 --- a/lib/l10n/app_localizations_uk.dart +++ b/lib/l10n/app_localizations_uk.dart @@ -1839,6 +1839,25 @@ class AppLocalizationsUk extends AppLocalizations { String get chat_ipfsUploadNotConfigured => 'Configure an IPFS upload provider in App Settings first.'; + @override + String get chat_ipfsSelectedFileEmpty => 'The selected file is empty.'; + + @override + String get chat_ipfsEndpointInvalid => + 'The IPFS upload endpoint must be a full http:// or https:// address. Check it in App Settings.'; + + @override + String get chat_ipfsPinataTokenMissing => + 'Pinata needs an API key or JWT. Add it in App Settings.'; + + @override + String get chat_ipfsFilebaseTokenMissing => + 'Filebase needs an API token. Add it in App Settings.'; + + @override + String get chat_ipfsKuboPathInvalid => + 'The Kubo upload endpoint must end with /api/v0/add. Check it in App Settings.'; + @override String get chat_ipfsLinkNoRoom => 'Not enough room for the image link. Shorten your message, then try again.'; diff --git a/lib/l10n/app_localizations_zh.dart b/lib/l10n/app_localizations_zh.dart index 43354856..4dd1ee28 100644 --- a/lib/l10n/app_localizations_zh.dart +++ b/lib/l10n/app_localizations_zh.dart @@ -1742,6 +1742,25 @@ class AppLocalizationsZh extends AppLocalizations { String get chat_ipfsUploadNotConfigured => 'Configure an IPFS upload provider in App Settings first.'; + @override + String get chat_ipfsSelectedFileEmpty => 'The selected file is empty.'; + + @override + String get chat_ipfsEndpointInvalid => + 'The IPFS upload endpoint must be a full http:// or https:// address. Check it in App Settings.'; + + @override + String get chat_ipfsPinataTokenMissing => + 'Pinata needs an API key or JWT. Add it in App Settings.'; + + @override + String get chat_ipfsFilebaseTokenMissing => + 'Filebase needs an API token. Add it in App Settings.'; + + @override + String get chat_ipfsKuboPathInvalid => + 'The Kubo upload endpoint must end with /api/v0/add. Check it in App Settings.'; + @override String get chat_ipfsLinkNoRoom => 'Not enough room for the image link. Shorten your message, then try again.'; diff --git a/test/helpers/ipfs_link_attach_flow_test.dart b/test/helpers/ipfs_link_attach_flow_test.dart index b07d537d..2859752e 100644 --- a/test/helpers/ipfs_link_attach_flow_test.dart +++ b/test/helpers/ipfs_link_attach_flow_test.dart @@ -1,6 +1,8 @@ +import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:meshcore_open/helpers/ipfs_link_attach_flow.dart'; import 'package:meshcore_open/helpers/ipfs_upload_helper.dart'; +import 'package:meshcore_open/l10n/app_localizations.dart'; void main() { const url = 'ipfs://cid'; @@ -68,4 +70,31 @@ void main() { expect(IpfsUploadHelper.sampleCid.length, 59); }); }); + + group('ipfsUploadErrorText', () { + final l10n = lookupAppLocalizations(const Locale('en')); + + test('gives every config reason its own localized message', () { + final texts = { + for (final reason in IpfsUploadConfigError.values) + reason: ipfsUploadErrorText(l10n, IpfsUploadConfigException(reason)), + }; + expect( + texts[IpfsUploadConfigError.emptyEndpoint], + l10n.chat_ipfsUploadNotConfigured, + ); + expect( + texts[IpfsUploadConfigError.kuboPathInvalid], + l10n.chat_ipfsKuboPathInvalid, + ); + expect(texts.values.toSet(), hasLength(texts.length)); + }); + + test('wraps other errors in the generic message without the prefix', () { + expect( + ipfsUploadErrorText(l10n, Exception('IPFS upload failed (500): x')), + l10n.chat_ipfsUploadFailed('IPFS upload failed (500): x'), + ); + }); + }); } diff --git a/untranslated.json b/untranslated.json index bf46ed3d..370fa376 100644 --- a/untranslated.json +++ b/untranslated.json @@ -21,6 +21,11 @@ "chat_sendImageIpfs", "chat_ipfsUploadFailed", "chat_ipfsUploadNotConfigured", + "chat_ipfsSelectedFileEmpty", + "chat_ipfsEndpointInvalid", + "chat_ipfsPinataTokenMissing", + "chat_ipfsFilebaseTokenMissing", + "chat_ipfsKuboPathInvalid", "chat_ipfsLinkNoRoom", "chat_ipfsLinkOverLimit", "map_pathTraceAddMoreHint", @@ -66,6 +71,11 @@ "chat_sendImageIpfs", "chat_ipfsUploadFailed", "chat_ipfsUploadNotConfigured", + "chat_ipfsSelectedFileEmpty", + "chat_ipfsEndpointInvalid", + "chat_ipfsPinataTokenMissing", + "chat_ipfsFilebaseTokenMissing", + "chat_ipfsKuboPathInvalid", "chat_ipfsLinkNoRoom", "chat_ipfsLinkOverLimit", "map_pathTraceAddMoreHint", @@ -111,6 +121,11 @@ "chat_sendImageIpfs", "chat_ipfsUploadFailed", "chat_ipfsUploadNotConfigured", + "chat_ipfsSelectedFileEmpty", + "chat_ipfsEndpointInvalid", + "chat_ipfsPinataTokenMissing", + "chat_ipfsFilebaseTokenMissing", + "chat_ipfsKuboPathInvalid", "chat_ipfsLinkNoRoom", "chat_ipfsLinkOverLimit", "map_pathTraceAddMoreHint", @@ -156,6 +171,11 @@ "chat_sendImageIpfs", "chat_ipfsUploadFailed", "chat_ipfsUploadNotConfigured", + "chat_ipfsSelectedFileEmpty", + "chat_ipfsEndpointInvalid", + "chat_ipfsPinataTokenMissing", + "chat_ipfsFilebaseTokenMissing", + "chat_ipfsKuboPathInvalid", "chat_ipfsLinkNoRoom", "chat_ipfsLinkOverLimit", "map_pathTraceAddMoreHint", @@ -201,6 +221,11 @@ "chat_sendImageIpfs", "chat_ipfsUploadFailed", "chat_ipfsUploadNotConfigured", + "chat_ipfsSelectedFileEmpty", + "chat_ipfsEndpointInvalid", + "chat_ipfsPinataTokenMissing", + "chat_ipfsFilebaseTokenMissing", + "chat_ipfsKuboPathInvalid", "chat_ipfsLinkNoRoom", "chat_ipfsLinkOverLimit", "map_pathTraceAddMoreHint", @@ -246,6 +271,11 @@ "chat_sendImageIpfs", "chat_ipfsUploadFailed", "chat_ipfsUploadNotConfigured", + "chat_ipfsSelectedFileEmpty", + "chat_ipfsEndpointInvalid", + "chat_ipfsPinataTokenMissing", + "chat_ipfsFilebaseTokenMissing", + "chat_ipfsKuboPathInvalid", "chat_ipfsLinkNoRoom", "chat_ipfsLinkOverLimit", "map_pathTraceAddMoreHint", @@ -291,6 +321,11 @@ "chat_sendImageIpfs", "chat_ipfsUploadFailed", "chat_ipfsUploadNotConfigured", + "chat_ipfsSelectedFileEmpty", + "chat_ipfsEndpointInvalid", + "chat_ipfsPinataTokenMissing", + "chat_ipfsFilebaseTokenMissing", + "chat_ipfsKuboPathInvalid", "chat_ipfsLinkNoRoom", "chat_ipfsLinkOverLimit", "map_pathTraceAddMoreHint", @@ -336,6 +371,11 @@ "chat_sendImageIpfs", "chat_ipfsUploadFailed", "chat_ipfsUploadNotConfigured", + "chat_ipfsSelectedFileEmpty", + "chat_ipfsEndpointInvalid", + "chat_ipfsPinataTokenMissing", + "chat_ipfsFilebaseTokenMissing", + "chat_ipfsKuboPathInvalid", "chat_ipfsLinkNoRoom", "chat_ipfsLinkOverLimit", "map_pathTraceAddMoreHint", @@ -381,6 +421,11 @@ "chat_sendImageIpfs", "chat_ipfsUploadFailed", "chat_ipfsUploadNotConfigured", + "chat_ipfsSelectedFileEmpty", + "chat_ipfsEndpointInvalid", + "chat_ipfsPinataTokenMissing", + "chat_ipfsFilebaseTokenMissing", + "chat_ipfsKuboPathInvalid", "chat_ipfsLinkNoRoom", "chat_ipfsLinkOverLimit", "map_pathTraceAddMoreHint", @@ -426,6 +471,11 @@ "chat_sendImageIpfs", "chat_ipfsUploadFailed", "chat_ipfsUploadNotConfigured", + "chat_ipfsSelectedFileEmpty", + "chat_ipfsEndpointInvalid", + "chat_ipfsPinataTokenMissing", + "chat_ipfsFilebaseTokenMissing", + "chat_ipfsKuboPathInvalid", "chat_ipfsLinkNoRoom", "chat_ipfsLinkOverLimit", "map_pathTraceAddMoreHint", @@ -471,6 +521,11 @@ "chat_sendImageIpfs", "chat_ipfsUploadFailed", "chat_ipfsUploadNotConfigured", + "chat_ipfsSelectedFileEmpty", + "chat_ipfsEndpointInvalid", + "chat_ipfsPinataTokenMissing", + "chat_ipfsFilebaseTokenMissing", + "chat_ipfsKuboPathInvalid", "chat_ipfsLinkNoRoom", "chat_ipfsLinkOverLimit", "map_pathTraceAddMoreHint", @@ -516,6 +571,11 @@ "chat_sendImageIpfs", "chat_ipfsUploadFailed", "chat_ipfsUploadNotConfigured", + "chat_ipfsSelectedFileEmpty", + "chat_ipfsEndpointInvalid", + "chat_ipfsPinataTokenMissing", + "chat_ipfsFilebaseTokenMissing", + "chat_ipfsKuboPathInvalid", "chat_ipfsLinkNoRoom", "chat_ipfsLinkOverLimit", "map_pathTraceAddMoreHint", @@ -561,6 +621,11 @@ "chat_sendImageIpfs", "chat_ipfsUploadFailed", "chat_ipfsUploadNotConfigured", + "chat_ipfsSelectedFileEmpty", + "chat_ipfsEndpointInvalid", + "chat_ipfsPinataTokenMissing", + "chat_ipfsFilebaseTokenMissing", + "chat_ipfsKuboPathInvalid", "chat_ipfsLinkNoRoom", "chat_ipfsLinkOverLimit", "map_pathTraceAddMoreHint", @@ -606,6 +671,11 @@ "chat_sendImageIpfs", "chat_ipfsUploadFailed", "chat_ipfsUploadNotConfigured", + "chat_ipfsSelectedFileEmpty", + "chat_ipfsEndpointInvalid", + "chat_ipfsPinataTokenMissing", + "chat_ipfsFilebaseTokenMissing", + "chat_ipfsKuboPathInvalid", "chat_ipfsLinkNoRoom", "chat_ipfsLinkOverLimit", "map_pathTraceAddMoreHint", @@ -651,6 +721,11 @@ "chat_sendImageIpfs", "chat_ipfsUploadFailed", "chat_ipfsUploadNotConfigured", + "chat_ipfsSelectedFileEmpty", + "chat_ipfsEndpointInvalid", + "chat_ipfsPinataTokenMissing", + "chat_ipfsFilebaseTokenMissing", + "chat_ipfsKuboPathInvalid", "chat_ipfsLinkNoRoom", "chat_ipfsLinkOverLimit", "map_pathTraceAddMoreHint", @@ -696,6 +771,11 @@ "chat_sendImageIpfs", "chat_ipfsUploadFailed", "chat_ipfsUploadNotConfigured", + "chat_ipfsSelectedFileEmpty", + "chat_ipfsEndpointInvalid", + "chat_ipfsPinataTokenMissing", + "chat_ipfsFilebaseTokenMissing", + "chat_ipfsKuboPathInvalid", "chat_ipfsLinkNoRoom", "chat_ipfsLinkOverLimit", "map_pathTraceAddMoreHint", @@ -741,6 +821,11 @@ "chat_sendImageIpfs", "chat_ipfsUploadFailed", "chat_ipfsUploadNotConfigured", + "chat_ipfsSelectedFileEmpty", + "chat_ipfsEndpointInvalid", + "chat_ipfsPinataTokenMissing", + "chat_ipfsFilebaseTokenMissing", + "chat_ipfsKuboPathInvalid", "chat_ipfsLinkNoRoom", "chat_ipfsLinkOverLimit", "map_pathTraceAddMoreHint",