mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-24 18:38:48 +01:00
Refactor: extract fn to unstrip file path
This commit is contained in:
parent
87d2696a99
commit
679aaf36dd
10 changed files with 27 additions and 30 deletions
|
@ -1,7 +1,6 @@
|
|||
import 'package:bloc/bloc.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/api/api_util.dart' as api_util;
|
||||
import 'package:nc_photos/app_db.dart';
|
||||
import 'package:nc_photos/entity/album.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
|
@ -231,8 +230,7 @@ class ListAlbumBloc extends Bloc<ListAlbumBlocEvent, ListAlbumBlocState> {
|
|||
_onShareChanged(ev.account, ev.share);
|
||||
|
||||
void _onShareChanged(Account account, Share share) {
|
||||
final webdavPath =
|
||||
"${api_util.getWebdavRootUrlRelative(account)}/${share.path}";
|
||||
final webdavPath = file_util.unstripPath(account, share.path);
|
||||
if (webdavPath
|
||||
.startsWith(remote_storage_util.getRemoteAlbumsDir(account))) {
|
||||
_refreshThrottler.trigger(
|
||||
|
|
|
@ -2,7 +2,6 @@ import 'package:bloc/bloc.dart';
|
|||
import 'package:kiwi/kiwi.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/api/api_util.dart' as api_util;
|
||||
import 'package:nc_photos/app_db.dart';
|
||||
import 'package:nc_photos/entity/album.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
|
@ -221,8 +220,7 @@ class ListSharingBloc extends Bloc<ListSharingBlocEvent, ListSharingBlocState> {
|
|||
final shareRepo = ShareRepo(ShareRemoteDataSource());
|
||||
final shares = await shareRepo.listAll(ev.account);
|
||||
final futures = shares.map((s) async {
|
||||
final webdavPath =
|
||||
"${api_util.getWebdavRootUrlRelative(ev.account)}/${s.path}";
|
||||
final webdavPath = file_util.unstripPath(ev.account, s.path);
|
||||
// include link share dirs
|
||||
if (s.itemType == ShareItemType.folder) {
|
||||
if (webdavPath.startsWith(
|
||||
|
@ -289,8 +287,7 @@ class ListSharingBloc extends Bloc<ListSharingBlocEvent, ListSharingBlocState> {
|
|||
final shareRepo = ShareRepo(ShareRemoteDataSource());
|
||||
final shares = await shareRepo.reverseListAll(ev.account);
|
||||
final futures = shares.map((s) async {
|
||||
final webdavPath =
|
||||
"${api_util.getWebdavRootUrlRelative(ev.account)}/${s.path}";
|
||||
final webdavPath = file_util.unstripPath(ev.account, s.path);
|
||||
// include pending shared albums
|
||||
if (path.dirname(webdavPath) ==
|
||||
remote_storage_util.getRemotePendingSharedAlbumsDir(ev.account)) {
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:nc_photos/ci_string.dart';
|
|||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/platform/k.dart' as platform_k;
|
||||
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
|
||||
import 'package:nc_photos/string_extension.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
bool isSupportedMime(String mime) => _supportedFormatMimes.contains(mime);
|
||||
|
@ -38,6 +39,13 @@ bool isUnderDir(File file, File dir) => file.path.startsWith("${dir.path}/");
|
|||
bool isOrUnderDir(File file, File dir) =>
|
||||
file.path == dir.path || isUnderDir(file, dir);
|
||||
|
||||
/// Convert a stripped path to a full path
|
||||
///
|
||||
/// See [File.strippedPath]
|
||||
String unstripPath(Account account, String strippedPath) =>
|
||||
"${api_util.getWebdavRootUrlRelative(account)}/$strippedPath"
|
||||
.trimRightAny("/");
|
||||
|
||||
/// For a path "remote.php/dav/files/foo/bar.jpg", return foo
|
||||
CiString getUserDirName(File file) {
|
||||
if (file.path.startsWith("remote.php/dav/files/")) {
|
||||
|
|
|
@ -4,10 +4,10 @@ import 'package:event_bus/event_bus.dart';
|
|||
import 'package:kiwi/kiwi.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/api/api_util.dart' as api_util;
|
||||
import 'package:nc_photos/app_db.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/entity/file/data_source.dart';
|
||||
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
||||
import 'package:nc_photos/event/event.dart';
|
||||
import 'package:nc_photos/pref.dart';
|
||||
import 'package:nc_photos/use_case/update_missing_metadata.dart';
|
||||
|
@ -28,8 +28,8 @@ class MetadataTask {
|
|||
final fileRepo = FileRepo(FileCachedDataSource(AppDb()));
|
||||
for (final r in account.roots) {
|
||||
final op = UpdateMissingMetadata(fileRepo);
|
||||
await for (final _ in op(account,
|
||||
File(path: "${api_util.getWebdavRootUrlRelative(account)}/$r"))) {
|
||||
await for (final _
|
||||
in op(account, File(path: file_util.unstripPath(account, r)))) {
|
||||
if (!Pref().isEnableExifOr()) {
|
||||
_log.info("[call] EXIF disabled, task ending immaturely");
|
||||
op.stop();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/api/api_util.dart' as api_util;
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
||||
import 'package:nc_photos/entity/share.dart';
|
||||
|
||||
class ListDirShareItem {
|
||||
|
@ -26,8 +26,7 @@ class ListDirShare {
|
|||
return shareGroups.entries
|
||||
.map((e) => ListDirShareItem(
|
||||
File(
|
||||
path:
|
||||
"${api_util.getWebdavRootUrlRelative(account)}/${e.value.first.path}",
|
||||
path: file_util.unstripPath(account, e.value.first.path),
|
||||
fileId: e.key,
|
||||
),
|
||||
e.value))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/api/api_util.dart' as api_util;
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
||||
import 'package:nc_photos/use_case/ls.dart';
|
||||
|
||||
/// List all shared files that are potentially albums
|
||||
|
@ -14,10 +14,7 @@ class ListPotentialSharedAlbum {
|
|||
final results = <File>[];
|
||||
final ls = await Ls(fileRepo)(
|
||||
account,
|
||||
File(
|
||||
path:
|
||||
"${api_util.getWebdavRootUrlRelative(account)}/${settings.shareFolder}",
|
||||
),
|
||||
File(path: file_util.unstripPath(account, settings.shareFolder)),
|
||||
);
|
||||
for (final f in ls) {
|
||||
// check owner
|
||||
|
|
|
@ -3,7 +3,6 @@ import 'package:flutter/widgets.dart';
|
|||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
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/bloc/list_importable_album.dart';
|
||||
|
@ -12,6 +11,7 @@ import 'package:nc_photos/entity/album/cover_provider.dart';
|
|||
import 'package:nc_photos/entity/album/provider.dart';
|
||||
import 'package:nc_photos/entity/album/sort_provider.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
||||
import 'package:nc_photos/exception_util.dart' as exception_util;
|
||||
import 'package:nc_photos/iterable_extension.dart';
|
||||
import 'package:nc_photos/k.dart' as k;
|
||||
|
@ -83,9 +83,7 @@ class _AlbumImporterState extends State<AlbumImporter> {
|
|||
_bloc.add(ListImportableAlbumBlocQuery(
|
||||
widget.account,
|
||||
widget.account.roots
|
||||
.map((e) => File(
|
||||
path:
|
||||
"${api_util.getWebdavRootUrlRelative(widget.account)}/$e"))
|
||||
.map((e) => File(path: file_util.unstripPath(widget.account, e)))
|
||||
.toList()));
|
||||
}
|
||||
|
||||
|
|
|
@ -297,9 +297,7 @@ class _ArchiveBrowserState extends State<ArchiveBrowser>
|
|||
_bloc.add(ScanDirBlocQuery(
|
||||
widget.account,
|
||||
widget.account.roots
|
||||
.map((e) => File(
|
||||
path:
|
||||
"${api_util.getWebdavRootUrlRelative(widget.account)}/$e"))
|
||||
.map((e) => File(path: file_util.unstripPath(widget.account, e)))
|
||||
.toList()));
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import 'package:nc_photos/api/api_util.dart' as api_util;
|
|||
import 'package:nc_photos/app_localizations.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/entity/file/data_source.dart';
|
||||
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
||||
import 'package:nc_photos/exception_util.dart' as exception_util;
|
||||
import 'package:nc_photos/k.dart' as k;
|
||||
import 'package:nc_photos/snack_bar_manager.dart';
|
||||
|
@ -61,8 +62,8 @@ class _RootPickerState extends State<RootPicker> {
|
|||
for (final r in widget.account.roots) {
|
||||
if (r.isNotEmpty) {
|
||||
_ensureInitDialog();
|
||||
files.add(await LsSingleFile(fileSrc)(widget.account,
|
||||
"${api_util.getWebdavRootUrlRelative(widget.account)}/$r"));
|
||||
files.add(await LsSingleFile(fileSrc)(
|
||||
widget.account, file_util.unstripPath(widget.account, r)));
|
||||
}
|
||||
}
|
||||
setState(() {
|
||||
|
|
|
@ -5,6 +5,7 @@ import 'package:nc_photos/account.dart';
|
|||
import 'package:nc_photos/api/api_util.dart' as api_util;
|
||||
import 'package:nc_photos/app_localizations.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
||||
import 'package:nc_photos/iterable_extension.dart';
|
||||
import 'package:nc_photos/k.dart' as k;
|
||||
import 'package:nc_photos/snack_bar_manager.dart';
|
||||
|
@ -86,8 +87,8 @@ class _ShareFolderPickerState extends State<ShareFolderPicker> {
|
|||
initialPicks: [
|
||||
if (widget.initialValue.isNotEmpty)
|
||||
File(
|
||||
path:
|
||||
"${api_util.getWebdavRootUrlRelative(widget.account)}/${widget.initialValue}",
|
||||
path: file_util.unstripPath(
|
||||
widget.account, widget.initialValue),
|
||||
),
|
||||
],
|
||||
isMultipleSelections: false,
|
||||
|
|
Loading…
Reference in a new issue