nc-photos/lib/use_case/import_potential_shared_album.dart

51 lines
1.7 KiB
Dart
Raw Normal View History

2021-08-08 14:09:21 +02:00
import 'package:logging/logging.dart';
import 'package:nc_photos/account.dart';
import 'package:nc_photos/di_container.dart';
2021-08-08 14:09:21 +02:00
import 'package:nc_photos/entity/album.dart';
import 'package:nc_photos/entity/file.dart';
2021-12-05 13:02:22 +01:00
import 'package:nc_photos/pref.dart';
2021-08-08 14:09:21 +02:00
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
import 'package:nc_photos/use_case/list_potential_shared_album.dart';
import 'package:nc_photos/use_case/move.dart';
/// Import new shared albums to the pending dir
class ImportPotentialSharedAlbum {
ImportPotentialSharedAlbum(this._c)
: assert(require(_c)),
assert(Move.require(_c));
static bool require(DiContainer c) =>
DiContainer.has(c, DiType.albumRepo) &&
DiContainer.has(c, DiType.fileRepo);
2021-08-08 14:09:21 +02:00
2021-12-05 13:02:22 +01:00
Future<List<Album>> call(Account account, AccountPref accountPref) async {
2021-10-18 22:09:33 +02:00
_log.info("[call] $account");
2021-08-08 14:09:21 +02:00
final products = <Album>[];
2021-12-05 13:02:22 +01:00
final files =
await ListPotentialSharedAlbum(_c.fileRepo)(account, accountPref);
2021-08-08 14:09:21 +02:00
for (final f in files) {
// check if the file is actually an album
try {
final album = await _c.albumRepo.get(account, f);
2021-08-08 14:09:21 +02:00
_log.info("[call] New shared album: ${album.name}, file: ${f.path}");
// move this file to the pending dir
await Move(_c)(
2021-08-08 14:09:21 +02:00
account,
f,
"${remote_storage_util.getRemotePendingSharedAlbumsDir(account)}/${f.filename}",
2021-08-08 14:09:21 +02:00
shouldCreateMissingDir: true,
);
products.add(album);
} catch (e, stacktrace) {
_log.severe("[call] Exception", e, stacktrace);
}
}
return products;
}
final DiContainer _c;
2021-08-08 14:09:21 +02:00
static final _log = Logger(
"user_case.import_potential_shared_album.ImportPotentialSharedAlbum");
}