mirror of
https://github.com/immich-app/immich.git
synced 2024-12-20 00:38:24 +02:00
bcb0056b55
* Run dart analyze in CI * Add pub get * Fix linter errors in mobile code
44 lines
1.1 KiB
Dart
44 lines
1.1 KiB
Dart
import 'package:collection/collection.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:immich_mobile/shared/models/asset.dart';
|
|
import 'package:immich_mobile/shared/services/json_cache.dart';
|
|
|
|
class AssetCacheService extends JsonCache<List<Asset>> {
|
|
AssetCacheService() : super("asset_cache");
|
|
|
|
static Future<List<Map<String, dynamic>>> _computeSerialize(
|
|
List<Asset> assets,
|
|
) async {
|
|
return assets.map((e) => e.toJson()).toList();
|
|
}
|
|
|
|
@override
|
|
void put(List<Asset> data) async {
|
|
putRawData(await compute(_computeSerialize, data));
|
|
}
|
|
|
|
static Future<List<Asset>> _computeEncode(List<dynamic> data) async {
|
|
return data.map((e) => Asset.fromJson(e)).whereNotNull().toList();
|
|
}
|
|
|
|
@override
|
|
Future<List<Asset>> get() async {
|
|
try {
|
|
final mapList = await readRawData() as List<dynamic>;
|
|
|
|
final responseData = await compute(_computeEncode, mapList);
|
|
|
|
return responseData;
|
|
} catch (e) {
|
|
debugPrint(e.toString());
|
|
|
|
return [];
|
|
}
|
|
}
|
|
}
|
|
|
|
final assetCacheServiceProvider = Provider(
|
|
(ref) => AssetCacheService(),
|
|
);
|