🐛 Fix file upload
This commit is contained in:
@@ -34,20 +34,4 @@ extension SnFilePoolList on List<SnFilePool> {
|
|||||||
}
|
}
|
||||||
throw ArgumentError('Unexpected response format: $data');
|
throw ArgumentError('Unexpected response format: $data');
|
||||||
}
|
}
|
||||||
|
|
||||||
List<SnFilePool> filterValid() {
|
|
||||||
return where((p) {
|
|
||||||
final accept = p.policyConfig?['accept_types'];
|
|
||||||
|
|
||||||
if (accept is List) {
|
|
||||||
final acceptsOnlyMedia = accept.every((t) =>
|
|
||||||
t is String &&
|
|
||||||
(t.startsWith('image/') ||
|
|
||||||
t.startsWith('video/') ||
|
|
||||||
t.startsWith('audio/')));
|
|
||||||
if (acceptsOnlyMedia) return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}).toList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -6,23 +6,16 @@ import 'package:island/pods/network.dart';
|
|||||||
final poolsProvider = FutureProvider<List<SnFilePool>>((ref) async {
|
final poolsProvider = FutureProvider<List<SnFilePool>>((ref) async {
|
||||||
final dio = ref.watch(apiClientProvider);
|
final dio = ref.watch(apiClientProvider);
|
||||||
final response = await dio.get('/drive/pools');
|
final response = await dio.get('/drive/pools');
|
||||||
final pools = SnFilePoolList.listFromResponse(response.data);
|
return response.data.map((e) => SnFilePool.fromJson(e)).toList();
|
||||||
return pools.filterValid();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
String resolveDefaultPoolId(WidgetRef ref, List<SnFilePool> pools) {
|
String? resolveDefaultPoolId(WidgetRef ref, List<SnFilePool> pools) {
|
||||||
final settings = ref.watch(appSettingsNotifierProvider);
|
final settings = ref.watch(appSettingsNotifierProvider);
|
||||||
final validPools = pools.filterValid();
|
|
||||||
|
|
||||||
final configuredId = settings.defaultPoolId;
|
final configuredId = settings.defaultPoolId;
|
||||||
if (configuredId != null && validPools.any((p) => p.id == configuredId)) {
|
if (configuredId != null && pools.any((p) => p.id == configuredId)) {
|
||||||
return configuredId;
|
return configuredId;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (validPools.isNotEmpty) {
|
return pools.firstOrNull?.id;
|
||||||
return validPools.first.id;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// DEFAULT: Solar Network Driver
|
|
||||||
return '500e5ed8-bd44-4359-bc0a-ec85e2adf447'; }
|
|
||||||
|
|
||||||
|
@@ -935,7 +935,7 @@ class _ChatAttachmentUploaderSheetState
|
|||||||
if (snapshot.hasError) {
|
if (snapshot.hasError) {
|
||||||
return Center(child: Text('errorLoadingPools'.tr()));
|
return Center(child: Text('errorLoadingPools'.tr()));
|
||||||
}
|
}
|
||||||
final pools = snapshot.data!.filterValid();
|
final pools = snapshot.data!;
|
||||||
selectedPoolId ??= resolveDefaultPoolId(widget.ref, pools);
|
selectedPoolId ??= resolveDefaultPoolId(widget.ref, pools);
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
@@ -1162,9 +1162,7 @@ class _ChatAttachmentUploaderSheetState
|
|||||||
|
|
||||||
// Get the selected pool to check constraints
|
// Get the selected pool to check constraints
|
||||||
final pools = await widget.ref.read(poolsProvider.future);
|
final pools = await widget.ref.read(poolsProvider.future);
|
||||||
final selectedPool = pools.filterValid().firstWhere(
|
final selectedPool = pools.firstWhere((p) => p.id == selectedPoolId);
|
||||||
(p) => p.id == selectedPoolId,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Check constraints
|
// Check constraints
|
||||||
final maxFileSize = selectedPool.policyConfig?['max_file_size'] as int?;
|
final maxFileSize = selectedPool.policyConfig?['max_file_size'] as int?;
|
||||||
|
@@ -59,7 +59,7 @@ class _AttachmentUploaderSheetState extends State<AttachmentUploaderSheet> {
|
|||||||
if (snapshot.hasError) {
|
if (snapshot.hasError) {
|
||||||
return Center(child: Text('errorLoadingPools'.tr()));
|
return Center(child: Text('errorLoadingPools'.tr()));
|
||||||
}
|
}
|
||||||
final pools = snapshot.data!.filterValid();
|
final pools = snapshot.data!;
|
||||||
selectedPoolId ??= resolveDefaultPoolId(widget.ref, pools);
|
selectedPoolId ??= resolveDefaultPoolId(widget.ref, pools);
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
@@ -286,9 +286,7 @@ class _AttachmentUploaderSheetState extends State<AttachmentUploaderSheet> {
|
|||||||
|
|
||||||
// Get the selected pool to check constraints
|
// Get the selected pool to check constraints
|
||||||
final pools = await widget.ref.read(poolsProvider.future);
|
final pools = await widget.ref.read(poolsProvider.future);
|
||||||
final selectedPool = pools.filterValid().firstWhere(
|
final selectedPool = pools.firstWhere((p) => p.id == selectedPoolId);
|
||||||
(p) => p.id == selectedPoolId,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Check constraints
|
// Check constraints
|
||||||
final maxFileSize = selectedPool.policyConfig?['max_file_size'] as int?;
|
final maxFileSize = selectedPool.policyConfig?['max_file_size'] as int?;
|
||||||
|
Reference in New Issue
Block a user