add default pool selection with validation and fallback
- extend AppSettings with defaultPoolId - add pool filtering utility to exclude media-only pools - add resolveDefaultPoolId with fallback to safe pool - update SettingsScreen with default pool dropdown - integrate uploadAttachment with default pool resolution Signed-off-by: Texas0295 <kimura@texas0295.top>
This commit is contained in:
35
lib/utils/pool_utils.dart
Normal file
35
lib/utils/pool_utils.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
import '../models/file_pool.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import '../pods/config.dart';
|
||||
|
||||
List<FilePool> filterValidPools(List<FilePool> pools) {
|
||||
return pools.where((p) {
|
||||
final accept = p.policyConfig['accept_types'];
|
||||
if (accept != null) {
|
||||
final acceptsOnlyMedia = accept.every((t) =>
|
||||
t.startsWith('image/') ||
|
||||
t.startsWith('video/') ||
|
||||
t.startsWith('audio/'));
|
||||
if (acceptsOnlyMedia) return false;
|
||||
}
|
||||
return true;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
String resolveDefaultPoolId(WidgetRef ref, List<FilePool> pools) {
|
||||
final settings = ref.watch(appSettingsNotifierProvider);
|
||||
final validPools = filterValidPools(pools);
|
||||
|
||||
if (settings.defaultPoolId != null &&
|
||||
validPools.any((p) => p.id == settings.defaultPoolId)) {
|
||||
return settings.defaultPoolId!;
|
||||
}
|
||||
|
||||
if (validPools.isNotEmpty) {
|
||||
return validPools.first.id;
|
||||
}
|
||||
// DEFAULT: Solar Network Driver
|
||||
return '500e5ed8-bd44-4359-bc0a-ec85e2adf447';
|
||||
}
|
||||
|
Reference in New Issue
Block a user