mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-23 09:16:19 +01:00
Move op
This commit is contained in:
parent
832f866d00
commit
de9c6e15ef
1 changed files with 37 additions and 0 deletions
37
lib/use_case/move.dart
Normal file
37
lib/use_case/move.dart
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
import 'package:logging/logging.dart';
|
||||||
|
import 'package:nc_photos/account.dart';
|
||||||
|
import 'package:nc_photos/entity/file.dart';
|
||||||
|
import 'package:nc_photos/exception.dart';
|
||||||
|
import 'package:nc_photos/use_case/create_dir.dart';
|
||||||
|
import 'package:path/path.dart' as path;
|
||||||
|
|
||||||
|
class Move {
|
||||||
|
Move(this.fileRepo);
|
||||||
|
|
||||||
|
/// Move a file from its original location to [destination]
|
||||||
|
Future<void> call(
|
||||||
|
Account account,
|
||||||
|
File file,
|
||||||
|
String destination, {
|
||||||
|
bool shouldCreateMissingDir = false,
|
||||||
|
}) async {
|
||||||
|
try {
|
||||||
|
await fileRepo.move(account, file, destination);
|
||||||
|
} catch (e) {
|
||||||
|
if (e is ApiException &&
|
||||||
|
e.response.statusCode == 409 &&
|
||||||
|
shouldCreateMissingDir) {
|
||||||
|
// no dir
|
||||||
|
_log.info("[call] Auto creating parent dirs");
|
||||||
|
await CreateDir(fileRepo)(account, path.dirname(destination));
|
||||||
|
await fileRepo.move(account, file, destination);
|
||||||
|
} else {
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final FileRepo fileRepo;
|
||||||
|
|
||||||
|
static final _log = Logger("use_case.move.Move");
|
||||||
|
}
|
Loading…
Reference in a new issue