mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-03-24 16:04:43 +01:00
LsSingleFile now takes repo as with other use cases
This commit is contained in:
parent
d9a6d04ae8
commit
adf1968a40
5 changed files with 37 additions and 12 deletions
|
@ -508,6 +508,10 @@ class FileRepo {
|
||||||
Future<List<File>> list(Account account, File root) =>
|
Future<List<File>> list(Account account, File root) =>
|
||||||
dataSrc.list(account, root);
|
dataSrc.list(account, root);
|
||||||
|
|
||||||
|
/// See [FileDataSource.listSingle]
|
||||||
|
Future<File> listSingle(Account account, File root) =>
|
||||||
|
dataSrc.listSingle(account, root);
|
||||||
|
|
||||||
/// See [FileDataSource.remove]
|
/// See [FileDataSource.remove]
|
||||||
Future<void> remove(Account account, File file) =>
|
Future<void> remove(Account account, File file) =>
|
||||||
dataSrc.remove(account, file);
|
dataSrc.remove(account, file);
|
||||||
|
@ -575,6 +579,9 @@ abstract class FileDataSource {
|
||||||
/// List all files under [f]
|
/// List all files under [f]
|
||||||
Future<List<File>> list(Account account, File f);
|
Future<List<File>> list(Account account, File f);
|
||||||
|
|
||||||
|
/// List a single file [f]
|
||||||
|
Future<File> listSingle(Account account, File f);
|
||||||
|
|
||||||
/// Remove file
|
/// Remove file
|
||||||
Future<void> remove(Account account, File f);
|
Future<void> remove(Account account, File f);
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@ import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
|
||||||
import 'package:nc_photos/string_extension.dart';
|
import 'package:nc_photos/string_extension.dart';
|
||||||
import 'package:nc_photos/touch_token_manager.dart';
|
import 'package:nc_photos/touch_token_manager.dart';
|
||||||
import 'package:nc_photos/use_case/compat/v32.dart';
|
import 'package:nc_photos/use_case/compat/v32.dart';
|
||||||
import 'package:nc_photos/use_case/ls_single_file.dart';
|
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
import 'package:quiver/iterables.dart';
|
import 'package:quiver/iterables.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
@ -78,6 +77,12 @@ class FileWebdavDataSource implements FileDataSource {
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
listSingle(Account account, File f) async {
|
||||||
|
_log.info("[listSingle] ${f.path}");
|
||||||
|
return (await list(account, f, depth: 0)).first;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
remove(Account account, File f) async {
|
remove(Account account, File f) async {
|
||||||
_log.info("[remove] ${f.path}");
|
_log.info("[remove] ${f.path}");
|
||||||
|
@ -250,6 +255,12 @@ class FileAppDbDataSource implements FileDataSource {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
listSingle(Account account, File f) {
|
||||||
|
_log.info("[listSingle] ${f.path}");
|
||||||
|
throw UnimplementedError();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
remove(Account account, File f) {
|
remove(Account account, File f) {
|
||||||
_log.info("[remove] ${f.path}");
|
_log.info("[remove] ${f.path}");
|
||||||
|
@ -440,6 +451,11 @@ class FileCachedDataSource implements FileDataSource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
listSingle(Account account, File f) {
|
||||||
|
return _remoteSrc.listSingle(account, f);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
remove(Account account, File f) async {
|
remove(Account account, File f) async {
|
||||||
await _appDbSrc.remove(account, f);
|
await _appDbSrc.remove(account, f);
|
||||||
|
@ -656,7 +672,7 @@ class _CacheManager {
|
||||||
// compare the etag to see if the content has been updated
|
// compare the etag to see if the content has been updated
|
||||||
var remoteEtag = f.etag;
|
var remoteEtag = f.etag;
|
||||||
// if no etag supplied, we need to query it form remote
|
// if no etag supplied, we need to query it form remote
|
||||||
remoteEtag ??= (await LsSingleFile(remoteSrc)(account, f.path)).etag;
|
remoteEtag ??= (await remoteSrc.list(account, f, depth: 0)).first.etag;
|
||||||
if (cacheEtag == remoteEtag) {
|
if (cacheEtag == remoteEtag) {
|
||||||
_log.fine(
|
_log.fine(
|
||||||
"[_listCache] etag matched for ${AppDbFileEntry.toPath(account, f)}");
|
"[_listCache] etag matched for ${AppDbFileEntry.toPath(account, f)}");
|
||||||
|
|
|
@ -1,15 +1,11 @@
|
||||||
import 'package:nc_photos/account.dart';
|
import 'package:nc_photos/account.dart';
|
||||||
import 'package:nc_photos/entity/file.dart';
|
import 'package:nc_photos/entity/file.dart';
|
||||||
import 'package:nc_photos/entity/file/data_source.dart';
|
|
||||||
|
|
||||||
class LsSingleFile {
|
class LsSingleFile {
|
||||||
LsSingleFile(this.dataSrc);
|
LsSingleFile(this.fileRepo);
|
||||||
|
|
||||||
Future<File> call(Account account, String path) async {
|
Future<File> call(Account account, String path) =>
|
||||||
final files = await dataSrc.list(account, File(path: path), depth: 0);
|
fileRepo.listSingle(account, File(path: path));
|
||||||
assert(files.length == 1);
|
|
||||||
return files.first;
|
|
||||||
}
|
|
||||||
|
|
||||||
final FileWebdavDataSource dataSrc;
|
final FileRepo fileRepo;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import 'package:flutter/widgets.dart';
|
||||||
import 'package:logging/logging.dart';
|
import 'package:logging/logging.dart';
|
||||||
import 'package:nc_photos/account.dart';
|
import 'package:nc_photos/account.dart';
|
||||||
import 'package:nc_photos/api/api_util.dart' as api_util;
|
import 'package:nc_photos/api/api_util.dart' as api_util;
|
||||||
|
import 'package:nc_photos/app_db.dart';
|
||||||
import 'package:nc_photos/app_localizations.dart';
|
import 'package:nc_photos/app_localizations.dart';
|
||||||
import 'package:nc_photos/entity/file.dart';
|
import 'package:nc_photos/entity/file.dart';
|
||||||
import 'package:nc_photos/entity/file/data_source.dart';
|
import 'package:nc_photos/entity/file/data_source.dart';
|
||||||
|
@ -57,12 +58,12 @@ class _RootPickerState extends State<RootPicker> {
|
||||||
|
|
||||||
void _initAccount() async {
|
void _initAccount() async {
|
||||||
try {
|
try {
|
||||||
const fileSrc = FileWebdavDataSource();
|
final fileRepo = FileRepo(FileCachedDataSource(AppDb()));
|
||||||
final files = <File>[];
|
final files = <File>[];
|
||||||
for (final r in widget.account.roots) {
|
for (final r in widget.account.roots) {
|
||||||
if (r.isNotEmpty) {
|
if (r.isNotEmpty) {
|
||||||
_ensureInitDialog();
|
_ensureInitDialog();
|
||||||
files.add(await LsSingleFile(fileSrc)(
|
files.add(await LsSingleFile(fileRepo)(
|
||||||
widget.account, file_util.unstripPath(widget.account, r)));
|
widget.account, file_util.unstripPath(widget.account, r)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,6 +142,11 @@ class MockFileRepo implements FileRepo {
|
||||||
throw UnimplementedError();
|
throw UnimplementedError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<File> listSingle(Account account, File root) async {
|
||||||
|
throw UnimplementedError();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> move(Account account, File f, String destination,
|
Future<void> move(Account account, File f, String destination,
|
||||||
{bool? shouldOverwrite}) {
|
{bool? shouldOverwrite}) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue