diff --git a/lib/models/app_settings.dart b/lib/models/app_settings.dart index f8efacec..64ccbfad 100644 --- a/lib/models/app_settings.dart +++ b/lib/models/app_settings.dart @@ -17,18 +17,6 @@ String normalizeIpfsGateway(String value) { return gateway; } -String migratePublicIpfsGateway(String? value) { - final gateway = value?.trim(); - if (gateway == null || - gateway == 'https://ipfs.io/ipfs/' || - gateway == 'https://ipfs.io/ipfs' || - gateway == 'https://dweb.link/ipfs/' || - gateway == 'https://dweb.link/ipfs') { - return AppSettings.defaultPublicIpfsGateway; - } - return gateway; -} - enum ChannelNotificationMode { all, mentionsOnly, muted } extension UnitSystemValue on UnitSystem { @@ -106,7 +94,7 @@ class Cyr2LatProfile { class AppSettings { static const Object _unset = Object(); static const String stadiaDemo = '51bd0381-4685-4666-bae8-48940f6d77c0'; - static const String defaultPublicIpfsGateway = ''; + static const String defaultPublicIpfsGateway = 'https://ipfs.io/ipfs/'; final bool clearPathOnMaxRetry; final bool mapShowRepeaters; @@ -517,9 +505,8 @@ class AppSettings { networkMapUploadEnabled: json['network_map_upload_enabled'] as bool? ?? false, networkMapPromptShown: json['network_map_prompt_shown'] as bool? ?? false, - publicIpfsGateway: migratePublicIpfsGateway( - json['public_ipfs_gateway'] as String?, - ), + publicIpfsGateway: + json['public_ipfs_gateway'] as String? ?? defaultPublicIpfsGateway, uploadIpfsGateway: json['upload_ipfs_gateway'] as String? ?? '', uploadIpfsEndpoint: json['upload_ipfs_endpoint'] as String? ?? '', uploadIpfsApiKey: json['upload_ipfs_api_key'] as String? ?? '', diff --git a/test/helpers/message_url_image_helper_test.dart b/test/helpers/message_url_image_helper_test.dart index c9cce83b..900b0a01 100644 --- a/test/helpers/message_url_image_helper_test.dart +++ b/test/helpers/message_url_image_helper_test.dart @@ -48,23 +48,20 @@ void main() { ); }); - test( - 'does not resolve ipfs cid links with the default gateway deactivated', - () async { - expect( - await MessageUrlImageHelper.parse( - 'my picture: ipfs://bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly text', - ), - isNull, - ); - expect( - await MessageUrlImageHelper.parse( - 'my picture: ipfs:bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly text', - ), - isNull, - ); - }, - ); + test('resolves ipfs cid links with the default ipfs.io gateway', () async { + expect( + await MessageUrlImageHelper.parse( + 'my picture: ipfs://bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly text', + ), + 'https://ipfs.io/ipfs/bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly', + ); + expect( + await MessageUrlImageHelper.parse( + 'my picture: ipfs:bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly text', + ), + 'https://ipfs.io/ipfs/bafybeibq75ws6nwk6wi473dch42wwy6woyj4dwdfy7nfz3buqx2caieoly', + ); + }); test('uses the configured public gateway for direct ipfs cid urls', () async { final attachment = await MessageUrlImageHelper.parse( diff --git a/test/models/model_changes_test.dart b/test/models/model_changes_test.dart index 078aa2b3..94a7eb2a 100644 --- a/test/models/model_changes_test.dart +++ b/test/models/model_changes_test.dart @@ -443,12 +443,28 @@ void main() { expect(settings.evictDiscoveredContactsEnabled, isFalse); }); - test('public IPFS gateway defaults to deactivated and preserves empty', () { - expect(AppSettings.fromJson({}).publicIpfsGateway, isEmpty); + test('public IPFS gateway defaults to ipfs.io when never set', () { expect( - AppSettings.fromJson({'public_ipfs_gateway': ''}).publicIpfsGateway, - isEmpty, + AppSettings.fromJson({}).publicIpfsGateway, + 'https://ipfs.io/ipfs/', ); + expect(AppSettings().publicIpfsGateway, 'https://ipfs.io/ipfs/'); + }); + + test('public IPFS gateway keeps a saved empty value as deactivated', () { + final saved = AppSettings(publicIpfsGateway: '').toJson(); + expect(AppSettings.fromJson(saved).publicIpfsGateway, isEmpty); + }); + + test('public IPFS gateway keeps saved ipfs.io and dweb.link values', () { + for (final gateway in [ + 'https://ipfs.io/ipfs/', + 'https://dweb.link/ipfs/', + 'https://gateway.example.com/ipfs/', + ]) { + final saved = AppSettings(publicIpfsGateway: gateway).toJson(); + expect(AppSettings.fromJson(saved).publicIpfsGateway, gateway); + } }); test('empty upload gateway does not fall back to the download gateway', () {