nc-photos/app/lib/use_case/compat/v25.dart

45 lines
1.4 KiB
Dart
Raw Normal View History

2021-08-06 06:52:20 +02:00
import 'package:logging/logging.dart';
import 'package:nc_photos/account.dart';
import 'package:nc_photos/di_container.dart';
2021-08-06 06:52:20 +02:00
import 'package:nc_photos/entity/file.dart';
import 'package:nc_photos/use_case/move.dart';
2022-12-16 16:01:04 +01:00
import 'package:np_codegen/np_codegen.dart';
2022-01-31 10:47:37 +01:00
import 'package:path/path.dart' as path_lib;
2021-08-06 06:52:20 +02:00
2022-12-16 16:01:04 +01:00
part 'v25.g.dart';
2021-08-06 06:52:20 +02:00
/// Compatibility helper for v25
class CompatV25 {
/// Return whether the album file need to be migrated to the new naming scheme
static bool isAlbumFileNeedMigration(File albumFile) =>
albumFile.path.endsWith(".nc_album.json") == false;
/// Migrate an album file to the new naming scheme
static Future<File> migrateAlbumFile(
DiContainer c, Account account, File albumFile) =>
_MigrateAlbumFile(c)(account, albumFile);
2021-08-06 06:52:20 +02:00
}
2022-12-16 16:01:04 +01:00
@npLog
2021-08-06 06:52:20 +02:00
class _MigrateAlbumFile {
_MigrateAlbumFile(this._c)
: assert(require(_c)),
assert(Move.require(_c));
static bool require(DiContainer c) => true;
2021-08-06 06:52:20 +02:00
Future<File> call(Account account, File albumFile) async {
assert(CompatV25.isAlbumFileNeedMigration(albumFile));
2022-01-31 10:47:37 +01:00
final newPath = path_lib.dirname(albumFile.path) +
2021-08-06 06:52:20 +02:00
"/" +
2022-01-31 10:47:37 +01:00
path_lib.basenameWithoutExtension(albumFile.path) +
2021-08-06 06:52:20 +02:00
".nc_album.json";
_log.info(
"[call] Migrate album file from '${albumFile.path}' to '$newPath'");
await Move(_c)(account, albumFile, newPath);
2021-08-06 06:52:20 +02:00
return albumFile.copyWith(path: newPath);
}
final DiContainer _c;
2021-08-06 06:52:20 +02:00
}