[REF] refactor file pool model and imports

- Refactor SnFilePool using freezed + sealed for consistency with other Sn models
- Add extension method listFromResponse for PoolService compatibility
- Update PoolService and utils to use SnFilePool
- Replace relative imports (../) with package imports for clarity and maintainability

Signed-off-by: Texas0295 <kimura@texas0295.top>
This commit is contained in:
Texas0295
2025-09-21 21:37:07 +08:00
parent b80d91825a
commit cbdc7acdcd
11 changed files with 443 additions and 63 deletions

View File

@@ -1,36 +1,37 @@
class FilePool { import 'package:freezed_annotation/freezed_annotation.dart';
final String id;
final String name;
final String? description;
final Map<String, dynamic> storageConfig;
final Map<String, dynamic> billingConfig;
final Map<String, dynamic> policyConfig;
final bool isHidden;
FilePool({ part 'file_pool.freezed.dart';
required this.id, part 'file_pool.g.dart';
required this.name,
this.description,
required this.storageConfig,
required this.billingConfig,
required this.policyConfig,
required this.isHidden,
});
factory FilePool.fromJson(Map<String, dynamic> json) { @freezed
return FilePool( sealed class SnFilePool with _$SnFilePool {
id: json['id'] as String, const factory SnFilePool({
name: json['name'] as String, required String id,
description: json['description'] as String?, required String name,
storageConfig: json['storage_config'] as Map<String, dynamic>, String? description,
billingConfig: json['billing_config'] as Map<String, dynamic>, Map<String, dynamic>? storageConfig,
policyConfig: json['policy_config'] as Map<String, dynamic>, Map<String, dynamic>? billingConfig,
isHidden: json['is_hidden'] as bool, Map<String, dynamic>? policyConfig,
); bool? isHidden,
String? accountId,
String? resourceIdentifier,
DateTime? createdAt,
DateTime? updatedAt,
DateTime? deletedAt,
}) = _SnFilePool;
factory SnFilePool.fromJson(Map<String, dynamic> json) =>
_$SnFilePoolFromJson(json);
} }
static List<FilePool> listFromResponse(dynamic data) { extension SnFilePoolList on SnFilePool {
final parsed = data as List<dynamic>; static List<SnFilePool> listFromResponse(dynamic data) {
return parsed.map((e) => FilePool.fromJson(e)).toList(); if (data is List) {
return data
.whereType<Map<String, dynamic>>()
.map(SnFilePool.fromJson)
.toList();
}
throw ArgumentError('Unexpected response format: $data');
} }
} }

View File

@@ -0,0 +1,328 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// coverage:ignore-file
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'file_pool.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$SnFilePool {
String get id; String get name; String? get description; Map<String, dynamic>? get storageConfig; Map<String, dynamic>? get billingConfig; Map<String, dynamic>? get policyConfig; bool? get isHidden; String? get accountId; String? get resourceIdentifier; DateTime? get createdAt; DateTime? get updatedAt; DateTime? get deletedAt;
/// Create a copy of SnFilePool
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$SnFilePoolCopyWith<SnFilePool> get copyWith => _$SnFilePoolCopyWithImpl<SnFilePool>(this as SnFilePool, _$identity);
/// Serializes this SnFilePool to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is SnFilePool&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name)&&(identical(other.description, description) || other.description == description)&&const DeepCollectionEquality().equals(other.storageConfig, storageConfig)&&const DeepCollectionEquality().equals(other.billingConfig, billingConfig)&&const DeepCollectionEquality().equals(other.policyConfig, policyConfig)&&(identical(other.isHidden, isHidden) || other.isHidden == isHidden)&&(identical(other.accountId, accountId) || other.accountId == accountId)&&(identical(other.resourceIdentifier, resourceIdentifier) || other.resourceIdentifier == resourceIdentifier)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&(identical(other.deletedAt, deletedAt) || other.deletedAt == deletedAt));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,id,name,description,const DeepCollectionEquality().hash(storageConfig),const DeepCollectionEquality().hash(billingConfig),const DeepCollectionEquality().hash(policyConfig),isHidden,accountId,resourceIdentifier,createdAt,updatedAt,deletedAt);
@override
String toString() {
return 'SnFilePool(id: $id, name: $name, description: $description, storageConfig: $storageConfig, billingConfig: $billingConfig, policyConfig: $policyConfig, isHidden: $isHidden, accountId: $accountId, resourceIdentifier: $resourceIdentifier, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt)';
}
}
/// @nodoc
abstract mixin class $SnFilePoolCopyWith<$Res> {
factory $SnFilePoolCopyWith(SnFilePool value, $Res Function(SnFilePool) _then) = _$SnFilePoolCopyWithImpl;
@useResult
$Res call({
String id, String name, String? description, Map<String, dynamic>? storageConfig, Map<String, dynamic>? billingConfig, Map<String, dynamic>? policyConfig, bool? isHidden, String? accountId, String? resourceIdentifier, DateTime? createdAt, DateTime? updatedAt, DateTime? deletedAt
});
}
/// @nodoc
class _$SnFilePoolCopyWithImpl<$Res>
implements $SnFilePoolCopyWith<$Res> {
_$SnFilePoolCopyWithImpl(this._self, this._then);
final SnFilePool _self;
final $Res Function(SnFilePool) _then;
/// Create a copy of SnFilePool
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? name = null,Object? description = freezed,Object? storageConfig = freezed,Object? billingConfig = freezed,Object? policyConfig = freezed,Object? isHidden = freezed,Object? accountId = freezed,Object? resourceIdentifier = freezed,Object? createdAt = freezed,Object? updatedAt = freezed,Object? deletedAt = freezed,}) {
return _then(_self.copyWith(
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
as String,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
as String,description: freezed == description ? _self.description : description // ignore: cast_nullable_to_non_nullable
as String?,storageConfig: freezed == storageConfig ? _self.storageConfig : storageConfig // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,billingConfig: freezed == billingConfig ? _self.billingConfig : billingConfig // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,policyConfig: freezed == policyConfig ? _self.policyConfig : policyConfig // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,isHidden: freezed == isHidden ? _self.isHidden : isHidden // ignore: cast_nullable_to_non_nullable
as bool?,accountId: freezed == accountId ? _self.accountId : accountId // ignore: cast_nullable_to_non_nullable
as String?,resourceIdentifier: freezed == resourceIdentifier ? _self.resourceIdentifier : resourceIdentifier // ignore: cast_nullable_to_non_nullable
as String?,createdAt: freezed == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable
as DateTime?,updatedAt: freezed == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable
as DateTime?,deletedAt: freezed == deletedAt ? _self.deletedAt : deletedAt // ignore: cast_nullable_to_non_nullable
as DateTime?,
));
}
}
/// Adds pattern-matching-related methods to [SnFilePool].
extension SnFilePoolPatterns on SnFilePool {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _SnFilePool value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _SnFilePool() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _SnFilePool value) $default,){
final _that = this;
switch (_that) {
case _SnFilePool():
return $default(_that);}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _SnFilePool value)? $default,){
final _that = this;
switch (_that) {
case _SnFilePool() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( String id, String name, String? description, Map<String, dynamic>? storageConfig, Map<String, dynamic>? billingConfig, Map<String, dynamic>? policyConfig, bool? isHidden, String? accountId, String? resourceIdentifier, DateTime? createdAt, DateTime? updatedAt, DateTime? deletedAt)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _SnFilePool() when $default != null:
return $default(_that.id,_that.name,_that.description,_that.storageConfig,_that.billingConfig,_that.policyConfig,_that.isHidden,_that.accountId,_that.resourceIdentifier,_that.createdAt,_that.updatedAt,_that.deletedAt);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String id, String name, String? description, Map<String, dynamic>? storageConfig, Map<String, dynamic>? billingConfig, Map<String, dynamic>? policyConfig, bool? isHidden, String? accountId, String? resourceIdentifier, DateTime? createdAt, DateTime? updatedAt, DateTime? deletedAt) $default,) {final _that = this;
switch (_that) {
case _SnFilePool():
return $default(_that.id,_that.name,_that.description,_that.storageConfig,_that.billingConfig,_that.policyConfig,_that.isHidden,_that.accountId,_that.resourceIdentifier,_that.createdAt,_that.updatedAt,_that.deletedAt);}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String id, String name, String? description, Map<String, dynamic>? storageConfig, Map<String, dynamic>? billingConfig, Map<String, dynamic>? policyConfig, bool? isHidden, String? accountId, String? resourceIdentifier, DateTime? createdAt, DateTime? updatedAt, DateTime? deletedAt)? $default,) {final _that = this;
switch (_that) {
case _SnFilePool() when $default != null:
return $default(_that.id,_that.name,_that.description,_that.storageConfig,_that.billingConfig,_that.policyConfig,_that.isHidden,_that.accountId,_that.resourceIdentifier,_that.createdAt,_that.updatedAt,_that.deletedAt);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _SnFilePool implements SnFilePool {
const _SnFilePool({required this.id, required this.name, this.description, final Map<String, dynamic>? storageConfig, final Map<String, dynamic>? billingConfig, final Map<String, dynamic>? policyConfig, this.isHidden, this.accountId, this.resourceIdentifier, this.createdAt, this.updatedAt, this.deletedAt}): _storageConfig = storageConfig,_billingConfig = billingConfig,_policyConfig = policyConfig;
factory _SnFilePool.fromJson(Map<String, dynamic> json) => _$SnFilePoolFromJson(json);
@override final String id;
@override final String name;
@override final String? description;
final Map<String, dynamic>? _storageConfig;
@override Map<String, dynamic>? get storageConfig {
final value = _storageConfig;
if (value == null) return null;
if (_storageConfig is EqualUnmodifiableMapView) return _storageConfig;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(value);
}
final Map<String, dynamic>? _billingConfig;
@override Map<String, dynamic>? get billingConfig {
final value = _billingConfig;
if (value == null) return null;
if (_billingConfig is EqualUnmodifiableMapView) return _billingConfig;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(value);
}
final Map<String, dynamic>? _policyConfig;
@override Map<String, dynamic>? get policyConfig {
final value = _policyConfig;
if (value == null) return null;
if (_policyConfig is EqualUnmodifiableMapView) return _policyConfig;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(value);
}
@override final bool? isHidden;
@override final String? accountId;
@override final String? resourceIdentifier;
@override final DateTime? createdAt;
@override final DateTime? updatedAt;
@override final DateTime? deletedAt;
/// Create a copy of SnFilePool
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$SnFilePoolCopyWith<_SnFilePool> get copyWith => __$SnFilePoolCopyWithImpl<_SnFilePool>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$SnFilePoolToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _SnFilePool&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name)&&(identical(other.description, description) || other.description == description)&&const DeepCollectionEquality().equals(other._storageConfig, _storageConfig)&&const DeepCollectionEquality().equals(other._billingConfig, _billingConfig)&&const DeepCollectionEquality().equals(other._policyConfig, _policyConfig)&&(identical(other.isHidden, isHidden) || other.isHidden == isHidden)&&(identical(other.accountId, accountId) || other.accountId == accountId)&&(identical(other.resourceIdentifier, resourceIdentifier) || other.resourceIdentifier == resourceIdentifier)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt)&&(identical(other.deletedAt, deletedAt) || other.deletedAt == deletedAt));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,id,name,description,const DeepCollectionEquality().hash(_storageConfig),const DeepCollectionEquality().hash(_billingConfig),const DeepCollectionEquality().hash(_policyConfig),isHidden,accountId,resourceIdentifier,createdAt,updatedAt,deletedAt);
@override
String toString() {
return 'SnFilePool(id: $id, name: $name, description: $description, storageConfig: $storageConfig, billingConfig: $billingConfig, policyConfig: $policyConfig, isHidden: $isHidden, accountId: $accountId, resourceIdentifier: $resourceIdentifier, createdAt: $createdAt, updatedAt: $updatedAt, deletedAt: $deletedAt)';
}
}
/// @nodoc
abstract mixin class _$SnFilePoolCopyWith<$Res> implements $SnFilePoolCopyWith<$Res> {
factory _$SnFilePoolCopyWith(_SnFilePool value, $Res Function(_SnFilePool) _then) = __$SnFilePoolCopyWithImpl;
@override @useResult
$Res call({
String id, String name, String? description, Map<String, dynamic>? storageConfig, Map<String, dynamic>? billingConfig, Map<String, dynamic>? policyConfig, bool? isHidden, String? accountId, String? resourceIdentifier, DateTime? createdAt, DateTime? updatedAt, DateTime? deletedAt
});
}
/// @nodoc
class __$SnFilePoolCopyWithImpl<$Res>
implements _$SnFilePoolCopyWith<$Res> {
__$SnFilePoolCopyWithImpl(this._self, this._then);
final _SnFilePool _self;
final $Res Function(_SnFilePool) _then;
/// Create a copy of SnFilePool
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? name = null,Object? description = freezed,Object? storageConfig = freezed,Object? billingConfig = freezed,Object? policyConfig = freezed,Object? isHidden = freezed,Object? accountId = freezed,Object? resourceIdentifier = freezed,Object? createdAt = freezed,Object? updatedAt = freezed,Object? deletedAt = freezed,}) {
return _then(_SnFilePool(
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
as String,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
as String,description: freezed == description ? _self.description : description // ignore: cast_nullable_to_non_nullable
as String?,storageConfig: freezed == storageConfig ? _self._storageConfig : storageConfig // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,billingConfig: freezed == billingConfig ? _self._billingConfig : billingConfig // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,policyConfig: freezed == policyConfig ? _self._policyConfig : policyConfig // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,isHidden: freezed == isHidden ? _self.isHidden : isHidden // ignore: cast_nullable_to_non_nullable
as bool?,accountId: freezed == accountId ? _self.accountId : accountId // ignore: cast_nullable_to_non_nullable
as String?,resourceIdentifier: freezed == resourceIdentifier ? _self.resourceIdentifier : resourceIdentifier // ignore: cast_nullable_to_non_nullable
as String?,createdAt: freezed == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable
as DateTime?,updatedAt: freezed == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable
as DateTime?,deletedAt: freezed == deletedAt ? _self.deletedAt : deletedAt // ignore: cast_nullable_to_non_nullable
as DateTime?,
));
}
}
// dart format on

View File

@@ -0,0 +1,47 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'file_pool.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_SnFilePool _$SnFilePoolFromJson(Map<String, dynamic> json) => _SnFilePool(
id: json['id'] as String,
name: json['name'] as String,
description: json['description'] as String?,
storageConfig: json['storage_config'] as Map<String, dynamic>?,
billingConfig: json['billing_config'] as Map<String, dynamic>?,
policyConfig: json['policy_config'] as Map<String, dynamic>?,
isHidden: json['is_hidden'] as bool?,
accountId: json['account_id'] as String?,
resourceIdentifier: json['resource_identifier'] as String?,
createdAt:
json['created_at'] == null
? null
: DateTime.parse(json['created_at'] as String),
updatedAt:
json['updated_at'] == null
? null
: DateTime.parse(json['updated_at'] as String),
deletedAt:
json['deleted_at'] == null
? null
: DateTime.parse(json['deleted_at'] as String),
);
Map<String, dynamic> _$SnFilePoolToJson(_SnFilePool instance) =>
<String, dynamic>{
'id': instance.id,
'name': instance.name,
'description': instance.description,
'storage_config': instance.storageConfig,
'billing_config': instance.billingConfig,
'policy_config': instance.policyConfig,
'is_hidden': instance.isHidden,
'account_id': instance.accountId,
'resource_identifier': instance.resourceIdentifier,
'created_at': instance.createdAt?.toIso8601String(),
'updated_at': instance.updatedAt?.toIso8601String(),
'deleted_at': instance.deletedAt?.toIso8601String(),
};

View File

@@ -1,6 +1,6 @@
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../services/pool_service.dart'; import 'package:island/services/pool_service.dart';
import '../models/file_pool.dart'; import 'package:island/models/file_pool.dart';
import 'package:island/pods/network.dart'; import 'package:island/pods/network.dart';
final poolServiceProvider = Provider<PoolService>((ref) { final poolServiceProvider = Provider<PoolService>((ref) {
@@ -8,7 +8,7 @@ final poolServiceProvider = Provider<PoolService>((ref) {
return PoolService(dio); return PoolService(dio);
}); });
final poolsProvider = FutureProvider<List<FilePool>>((ref) async { final poolsProvider = FutureProvider<List<SnFilePool>>((ref) async {
final service = ref.watch(poolServiceProvider); final service = ref.watch(poolServiceProvider);
return service.fetchPools(); return service.fetchPools();
}); });

View File

@@ -268,7 +268,7 @@ class _AccountBadgesProviderElement
} }
String _$accountAppbarForcegroundColorHash() => String _$accountAppbarForcegroundColorHash() =>
r'8ee0cae10817b77fb09548a482f5247662b4374c'; r'127fcc7fd6ec6a41ac4a6975276b5271aa4fa7d0';
/// See also [accountAppbarForcegroundColor]. /// See also [accountAppbarForcegroundColor].
@ProviderFor(accountAppbarForcegroundColor) @ProviderFor(accountAppbarForcegroundColor)

View File

@@ -6,7 +6,7 @@ part of 'captcha.config.dart';
// RiverpodGenerator // RiverpodGenerator
// ************************************************************************** // **************************************************************************
String _$captchaUrlHash() => r'bbed0d18272dd205069642b3c6583ea2eef735d1'; String _$captchaUrlHash() => r'd46bc43032cef504547cd528a40c23cf76f27cc8';
/// See also [captchaUrl]. /// See also [captchaUrl].
@ProviderFor(captchaUrl) @ProviderFor(captchaUrl)

View File

@@ -400,7 +400,7 @@ class _PublisherSubscriptionStatusProviderElement
} }
String _$publisherAppbarForcegroundColorHash() => String _$publisherAppbarForcegroundColorHash() =>
r'd781a806a242aea5c1609ec98c97c52fdd9f7db1'; r'cd9a9816177a6eecc2bc354acebbbd48892ffdd7';
/// See also [publisherAppbarForcegroundColor]. /// See also [publisherAppbarForcegroundColor].
@ProviderFor(publisherAppbarForcegroundColor) @ProviderFor(publisherAppbarForcegroundColor)

View File

@@ -7,7 +7,7 @@ part of 'realm_detail.dart';
// ************************************************************************** // **************************************************************************
String _$realmAppbarForegroundColorHash() => String _$realmAppbarForegroundColorHash() =>
r'14b5563d861996ea182d0d2db7aa5c2bb3bbaf48'; r'8131c047a984318a4cc3fbb5daa5ef0ce44dfae5';
/// Copied from Dart SDK /// Copied from Dart SDK
class _SystemHash { class _SystemHash {

View File

@@ -373,7 +373,7 @@ class SettingsScreen extends HookConsumerWidget {
poolsAsync.when( poolsAsync.when(
data: (pools) { data: (pools) {
final validPools = filterValidPools(pools); final validPools = filterValidPools(pools);
final currentPoolId = resolveDefaultPoolId(ref, pools); final currentPoolId = resolveDefaultPoolId(ref, validPools);
return ListTile( return ListTile(
isThreeLine: true, isThreeLine: true,
@@ -392,12 +392,14 @@ class SettingsScreen extends HookConsumerWidget {
child: DropdownButton2<String>( child: DropdownButton2<String>(
isExpanded: true, isExpanded: true,
items: items:
validPools.map((p) { validPools
return DropdownMenuItem<String>( .map(
(p) => DropdownMenuItem<String>(
value: p.id, value: p.id,
child: Text(p.name).fontSize(14), child: Text(p.name).fontSize(14),
); ),
}).toList(), )
.toList(),
value: currentPoolId, value: currentPoolId,
onChanged: (value) { onChanged: (value) {
ref ref

View File

@@ -7,11 +7,11 @@ class PoolService {
PoolService(this._dio); PoolService(this._dio);
Future<List<FilePool>> fetchPools() async { Future<List<SnFilePool>> fetchPools() async {
final response = await _dio.get('/drive/pools'); final response = await _dio.get('/drive/pools');
if (response.statusCode == 200) { if (response.statusCode == 200) {
return FilePool.listFromResponse(response.data); return SnFilePoolList.listFromResponse(response.data);
} else { } else {
throw Exception('Failed to fetch pools: ${response.statusCode}'); throw Exception('Failed to fetch pools: ${response.statusCode}');
} }

View File

@@ -1,35 +1,37 @@
import 'package:island/models/file_pool.dart';
import '../models/file_pool.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart';
import '../pods/config.dart'; import 'package:island/pods/config.dart';
List<FilePool> filterValidPools(List<FilePool> pools) { List<SnFilePool> filterValidPools(List<SnFilePool> pools) {
return pools.where((p) { return pools.where((p) {
final accept = p.policyConfig['accept_types']; final accept = p.policyConfig?['accept_types'];
if (accept != null) {
if (accept is List) {
final acceptsOnlyMedia = accept.every((t) => final acceptsOnlyMedia = accept.every((t) =>
t.startsWith('image/') || t is String &&
(t.startsWith('image/') ||
t.startsWith('video/') || t.startsWith('video/') ||
t.startsWith('audio/')); t.startsWith('audio/')));
if (acceptsOnlyMedia) return false; if (acceptsOnlyMedia) return false;
} }
return true; return true;
}).toList(); }).toList();
} }
String resolveDefaultPoolId(WidgetRef ref, List<FilePool> pools) { String resolveDefaultPoolId(WidgetRef ref, List<SnFilePool> pools) {
final settings = ref.watch(appSettingsNotifierProvider); final settings = ref.watch(appSettingsNotifierProvider);
final validPools = filterValidPools(pools); final validPools = filterValidPools(pools);
if (settings.defaultPoolId != null && final configuredId = settings.defaultPoolId;
validPools.any((p) => p.id == settings.defaultPoolId)) { if (configuredId != null &&
return settings.defaultPoolId!; validPools.any((p) => p.id == configuredId)) {
return configuredId;
} }
if (validPools.isNotEmpty) { if (validPools.isNotEmpty) {
return validPools.first.id; return validPools.first.id;
} }
// DEFAULT: Solar Network Driver
return '500e5ed8-bd44-4359-bc0a-ec85e2adf447';
}
return '500e5ed8-bd44-4359-bc0a-ec85e2adf447'; // Solar Network Driver
}