Localize IPFS upload and attach messages
Give IpfsUploadConfigException a reason enum mapped to l10n strings in the attach flow, and show a localized empty-file message and generic upload-failed message instead of raw English exception text.
This commit is contained in:
1 parent
34db64d7af
commit
c111835bd0
24 files changed
+536
-13
No files matched your search
@@ -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<void> attachIpfsLinkToDraft({
|
||||
if (!context.mounted) return;
|
||||
showDismissibleSnackBar(
|
||||
context,
|
||||
content: Text(l10n.chat_ipfsUploadFailed('$error')),
|
||||
content: Text(ipfsUploadErrorText(l10n, error)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -69,7 +70,10 @@ Future<void> 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<void> 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({
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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.';
|
||||
|
||||
@@ -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.';
|
||||
|
||||
@@ -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.';
|
||||
|
||||
@@ -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.';
|
||||
|
||||
@@ -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.';
|
||||
|
||||
@@ -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.';
|
||||
|
||||
@@ -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.';
|
||||
|
||||
@@ -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.';
|
||||
|
||||
@@ -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.';
|
||||
|
||||
@@ -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.';
|
||||
|
||||
@@ -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.';
|
||||
|
||||
@@ -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.';
|
||||
|
||||
@@ -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.';
|
||||
|
||||
@@ -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.';
|
||||
|
||||
@@ -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.';
|
||||
|
||||
@@ -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.';
|
||||
|
||||
@@ -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.';
|
||||
|
||||
@@ -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.';
|
||||
|
||||
@@ -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'),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -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",
|
||||
|
||||
Reference in new issue
Block a user