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:
Texas0295
2025-09-21 16:14:57 +08:00
parent 3621ea7744
commit 1a703b7eba
3 changed files with 50 additions and 14 deletions

35
lib/utils/pool_utils.dart Normal file
View 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';
}