nc-photos/lib/entity/album/upgrader.dart

87 lines
2.1 KiB
Dart
Raw Normal View History

2021-06-24 16:54:41 +02:00
import 'package:logging/logging.dart';
abstract class AlbumUpgrader {
2021-07-23 22:05:57 +02:00
Map<String, dynamic>? call(Map<String, dynamic> json);
2021-06-24 16:54:41 +02:00
}
/// Upgrade v1 Album to v2
class AlbumUpgraderV1 implements AlbumUpgrader {
AlbumUpgraderV1({
this.logFilePath,
});
2021-07-23 22:05:57 +02:00
@override
call(Map<String, dynamic> json) {
2021-06-24 16:54:41 +02:00
// v1 album items are corrupted in one of the updates, drop it
_log.fine("[call] Upgrade v1 Album for file: $logFilePath");
final result = Map<String, dynamic>.from(json);
result["items"] = [];
return result;
}
/// File path for logging only
2021-07-23 22:05:57 +02:00
final String? logFilePath;
2021-06-24 16:54:41 +02:00
static final _log = Logger("entity.album.upgrader.AlbumUpgraderV1");
}
2021-06-24 18:26:56 +02:00
/// Upgrade v2 Album to v3
class AlbumUpgraderV2 implements AlbumUpgrader {
AlbumUpgraderV2({
this.logFilePath,
});
2021-07-23 22:05:57 +02:00
@override
call(Map<String, dynamic> json) {
2021-06-24 18:26:56 +02:00
// move v2 items to v3 provider
_log.fine("[call] Upgrade v2 Album for file: $logFilePath");
final result = Map<String, dynamic>.from(json);
result["provider"] = <String, dynamic>{
"type": "static",
"content": <String, dynamic>{
"items": result["items"],
}
};
result.remove("items");
2021-06-26 13:51:13 +02:00
// add the auto cover provider
result["coverProvider"] = <String, dynamic>{
"type": "auto",
"content": {},
};
2021-06-24 18:26:56 +02:00
return result;
}
/// File path for logging only
2021-07-23 22:05:57 +02:00
final String? logFilePath;
2021-06-24 18:26:56 +02:00
static final _log = Logger("entity.album.upgrader.AlbumUpgraderV2");
}
2021-07-07 20:40:43 +02:00
/// Upgrade v3 Album to v4
class AlbumUpgraderV3 implements AlbumUpgrader {
AlbumUpgraderV3({
this.logFilePath,
});
2021-07-23 22:05:57 +02:00
@override
call(Map<String, dynamic> json) {
2021-07-07 20:40:43 +02:00
// move v3 items to v4 provider
_log.fine("[call] Upgrade v3 Album for file: $logFilePath");
final result = Map<String, dynamic>.from(json);
// add the descending time sort provider
result["sortProvider"] = <String, dynamic>{
"type": "time",
"content": {
"isAscending": false,
},
};
return result;
}
/// File path for logging only
2021-07-23 22:05:57 +02:00
final String? logFilePath;
2021-07-07 20:40:43 +02:00
static final _log = Logger("entity.album.upgrader.AlbumUpgraderV3");
}