upload url image or file to ipfs

This commit is contained in:
ericz committed 2026-10-11 13:14:14 +02:00
1 parent 9609a8231d
commit a4a7e00732
33 files changed
+2594 -81

No files matched your search

+57
View File
@@ -3,6 +3,32 @@ import 'translation_support.dart';
enum UnitSystem { metric, imperial }
String normalizeIpfsGateway(String value) {
var gateway = value.trim();
if (gateway.isEmpty) return gateway;
if (!gateway.startsWith('http://') && !gateway.startsWith('https://')) {
gateway = 'https://$gateway';
}
gateway = gateway.replaceAll('{cid}', '');
if (gateway.endsWith('/ipfs')) gateway = '$gateway/';
if (!gateway.endsWith('/ipfs/')) {
gateway = '${gateway.endsWith('/') ? gateway : '$gateway/'}ipfs/';
}
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;
}
extension UnitSystemValue on UnitSystem {
String get value {
switch (this) {
@@ -78,6 +104,7 @@ class Cyr2LatProfile {
class AppSettings {
static const Object _unset = Object();
static const String stadiaDemo = '51bd0381-4685-4666-bae8-48940f6d77c0';
static const String defaultPublicIpfsGateway = '';
final bool clearPathOnMaxRetry;
final bool mapShowRepeaters;
@@ -130,6 +157,10 @@ class AppSettings {
final int tcpServerPort;
final bool jumpToOldestUnread;
final bool imageMessagesEnabled;
final String publicIpfsGateway;
final String uploadIpfsGateway;
final String uploadIpfsEndpoint;
final String uploadIpfsApiKey;
/// Whether a received image is decoded as soon as it is reassembled.
///
@@ -180,6 +211,10 @@ class AppSettings {
return apiKey;
}
String get effectiveUploadIpfsGateway {
return uploadIpfsGateway.trim();
}
bool get usesstadiaDemo => effectiveMapTileApiKey == stadiaDemo;
Map<String, String> get cyr2latCharMap {
@@ -239,6 +274,10 @@ class AppSettings {
this.tcpServerPort = 0,
this.jumpToOldestUnread = false,
this.imageMessagesEnabled = false,
this.publicIpfsGateway = defaultPublicIpfsGateway,
this.uploadIpfsGateway = '',
this.uploadIpfsEndpoint = '',
this.uploadIpfsApiKey = '',
this.imageProcessAutomatically = false,
this.imageCodecEnabled = false,
this.imageCodecSelectedModelId,
@@ -321,6 +360,10 @@ class AppSettings {
'tcp_server_port': tcpServerPort,
'jump_to_oldest_unread': jumpToOldestUnread,
'image_messages_enabled': imageMessagesEnabled,
'public_ipfs_gateway': publicIpfsGateway,
'upload_ipfs_gateway': uploadIpfsGateway,
'upload_ipfs_endpoint': uploadIpfsEndpoint,
'upload_ipfs_api_key': uploadIpfsApiKey,
'image_process_automatically': imageProcessAutomatically,
'image_codec_enabled': imageCodecEnabled,
'image_codec_selected_model_id': imageCodecSelectedModelId,
@@ -428,6 +471,12 @@ class AppSettings {
tcpServerPort: json['tcp_server_port'] as int? ?? 0,
jumpToOldestUnread: json['jump_to_oldest_unread'] as bool? ?? false,
imageMessagesEnabled: json['image_messages_enabled'] as bool? ?? false,
publicIpfsGateway: migratePublicIpfsGateway(
json['public_ipfs_gateway'] as String?,
),
uploadIpfsGateway: json['upload_ipfs_gateway'] as String? ?? '',
uploadIpfsEndpoint: json['upload_ipfs_endpoint'] as String? ?? '',
uploadIpfsApiKey: json['upload_ipfs_api_key'] as String? ?? '',
imageProcessAutomatically:
json['image_process_automatically'] as bool? ?? false,
imageCodecEnabled: json['image_codec_enabled'] as bool? ?? false,
@@ -548,6 +597,10 @@ class AppSettings {
int? tcpServerPort,
bool? jumpToOldestUnread,
bool? imageMessagesEnabled,
String? publicIpfsGateway,
String? uploadIpfsGateway,
String? uploadIpfsEndpoint,
String? uploadIpfsApiKey,
bool? imageProcessAutomatically,
bool? imageCodecEnabled,
Object? imageCodecSelectedModelId = _unset,
@@ -633,6 +686,10 @@ class AppSettings {
tcpServerPort: tcpServerPort ?? this.tcpServerPort,
jumpToOldestUnread: jumpToOldestUnread ?? this.jumpToOldestUnread,
imageMessagesEnabled: imageMessagesEnabled ?? this.imageMessagesEnabled,
publicIpfsGateway: publicIpfsGateway ?? this.publicIpfsGateway,
uploadIpfsGateway: uploadIpfsGateway ?? this.uploadIpfsGateway,
uploadIpfsEndpoint: uploadIpfsEndpoint ?? this.uploadIpfsEndpoint,
uploadIpfsApiKey: uploadIpfsApiKey ?? this.uploadIpfsApiKey,
imageProcessAutomatically:
imageProcessAutomatically ?? this.imageProcessAutomatically,
imageCodecEnabled: imageCodecEnabled ?? this.imageCodecEnabled,