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