mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 14:56:20 +01:00
New naming scheme for album files
This commit is contained in:
parent
a4122854b4
commit
02e8bf0c76
3 changed files with 44 additions and 2 deletions
|
@ -270,7 +270,7 @@ class AlbumRemoteDataSource implements AlbumDataSource {
|
|||
// just make up something
|
||||
final timestamp = DateTime.now().millisecondsSinceEpoch;
|
||||
final random = Random().nextInt(0xFFFFFF);
|
||||
return "${timestamp.toRadixString(16)}-${random.toRadixString(16).padLeft(6, '0')}.json";
|
||||
return "${timestamp.toRadixString(16)}-${random.toRadixString(16).padLeft(6, '0')}.nc_album.json";
|
||||
}
|
||||
|
||||
static final _log = Logger("entity.album.AlbumRemoteDataSource");
|
||||
|
|
36
lib/use_case/compat/v25.dart
Normal file
36
lib/use_case/compat/v25.dart
Normal file
|
@ -0,0 +1,36 @@
|
|||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/use_case/move.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
/// 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(
|
||||
FileRepo fileRepo, Account account, File albumFile) =>
|
||||
_MigrateAlbumFile(fileRepo)(account, albumFile);
|
||||
}
|
||||
|
||||
class _MigrateAlbumFile {
|
||||
_MigrateAlbumFile(this.fileRepo);
|
||||
|
||||
Future<File> call(Account account, File albumFile) async {
|
||||
assert(CompatV25.isAlbumFileNeedMigration(albumFile));
|
||||
final newPath = path.dirname(albumFile.path) +
|
||||
"/" +
|
||||
path.basenameWithoutExtension(albumFile.path) +
|
||||
".nc_album.json";
|
||||
_log.info("[call] Migrate album file from '${albumFile.path}' to '$newPath'");
|
||||
await Move(fileRepo)(account, albumFile, newPath);
|
||||
return albumFile.copyWith(path: newPath);
|
||||
}
|
||||
|
||||
final FileRepo fileRepo;
|
||||
|
||||
static final _log = Logger("use_case.compat.v25._MigrateAlbumFile");
|
||||
}
|
|
@ -5,6 +5,7 @@ import 'package:nc_photos/entity/file.dart';
|
|||
import 'package:nc_photos/exception.dart';
|
||||
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
|
||||
import 'package:nc_photos/use_case/compat/v15.dart';
|
||||
import 'package:nc_photos/use_case/compat/v25.dart';
|
||||
import 'package:nc_photos/use_case/ls.dart';
|
||||
import 'package:tuple/tuple.dart';
|
||||
|
||||
|
@ -47,8 +48,13 @@ class ListAlbum {
|
|||
}
|
||||
final albumFiles =
|
||||
ls.where((element) => element.isCollection != true).toList();
|
||||
for (final f in albumFiles) {
|
||||
for (var i = 0; i < albumFiles.length; ++i) {
|
||||
var f = albumFiles[i];
|
||||
try {
|
||||
if (CompatV25.isAlbumFileNeedMigration(f)) {
|
||||
f = await CompatV25.migrateAlbumFile(fileRepo, account, f);
|
||||
}
|
||||
albumFiles[i] = f;
|
||||
yield await albumRepo.get(account, f);
|
||||
} catch (e, stacktrace) {
|
||||
yield Tuple2(e, stacktrace);
|
||||
|
|
Loading…
Reference in a new issue