2022-10-14 14:57:55 -07:00
|
|
|
import 'package:collection/collection.dart';
|
2022-10-15 14:20:15 -07:00
|
|
|
import 'package:flutter/foundation.dart';
|
2022-10-14 14:57:55 -07:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2022-10-19 13:03:54 -07:00
|
|
|
import 'package:immich_mobile/shared/services/json_cache.dart';
|
2022-10-14 14:57:55 -07:00
|
|
|
import 'package:openapi/api.dart';
|
2022-10-17 09:02:43 -07:00
|
|
|
|
2022-10-14 14:57:55 -07:00
|
|
|
|
2022-10-17 05:53:27 -07:00
|
|
|
class AssetCacheService extends JsonCache<List<AssetResponseDto>> {
|
2022-10-17 09:02:43 -07:00
|
|
|
AssetCacheService() : super("asset_cache");
|
2022-10-17 05:53:27 -07:00
|
|
|
|
|
|
|
@override
|
|
|
|
void put(List<AssetResponseDto> data) {
|
|
|
|
putRawData(data.map((e) => e.toJson()).toList());
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-10-17 07:40:51 -07:00
|
|
|
Future<List<AssetResponseDto>> get() async {
|
2022-10-15 14:20:15 -07:00
|
|
|
try {
|
2022-10-17 07:40:51 -07:00
|
|
|
final mapList = await readRawData() as List<dynamic>;
|
2022-10-14 14:57:55 -07:00
|
|
|
|
2022-10-15 14:20:15 -07:00
|
|
|
final responseData = mapList
|
|
|
|
.map((e) => AssetResponseDto.fromJson(e))
|
|
|
|
.whereNotNull()
|
|
|
|
.toList();
|
2022-10-14 14:57:55 -07:00
|
|
|
|
2022-10-15 14:20:15 -07:00
|
|
|
return responseData;
|
|
|
|
} catch (e) {
|
|
|
|
debugPrint(e.toString());
|
2022-10-14 14:57:55 -07:00
|
|
|
|
2022-10-15 14:20:15 -07:00
|
|
|
return [];
|
|
|
|
}
|
2022-10-14 14:57:55 -07:00
|
|
|
}
|
|
|
|
}
|
2022-10-17 05:53:27 -07:00
|
|
|
|
|
|
|
final assetCacheServiceProvider = Provider(
|
|
|
|
(ref) => AssetCacheService(),
|
|
|
|
);
|