From af69bb910b5872970265da71e6852c85e1c4f62e Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Wed, 16 Mar 2022 15:03:38 -0400 Subject: [PATCH] Fix image file preview loading --- .../src/components/media_wrapper_component.dart | 15 +++++++-------- .../services/diaspora_path_mapping_service.dart | 4 ++++ .../services/friendica_path_mapping_service.dart | 14 ++------------ 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/friendica_archive_browser/lib/src/components/media_wrapper_component.dart b/friendica_archive_browser/lib/src/components/media_wrapper_component.dart index 7cce22a..b3d836e 100644 --- a/friendica_archive_browser/lib/src/components/media_wrapper_component.dart +++ b/friendica_archive_browser/lib/src/components/media_wrapper_component.dart @@ -55,13 +55,13 @@ class MediaWrapperComponent extends StatelessWidget { noImageText: 'No Thumbnail', noImageOnTapText: 'Click to launch video in external player (No Thumbnail)', - onTap: () async => - await _attemptToPlay(context, videoPlayerCommand, path)); + onTap: () async => await _attemptToPlay( + context, videoPlayerCommand, path.toString())); } return TextButton( onPressed: () async { - await _attemptToPlay(context, videoPlayerCommand, path); + await _attemptToPlay(context, videoPlayerCommand, path.toString()); }, child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( @@ -74,8 +74,7 @@ class MediaWrapperComponent extends StatelessWidget { } if (mediaAttachment.explicitType == AttachmentMediaType.image) { - final imageResult = - _uriToImage(mediaAttachment.uri, archiveService.pathMappingService); + final imageResult = _uriToImage(path, archiveService.pathMappingService); if (imageResult.image == null) { final errorPath = imageResult.path.isNotEmpty ? imageResult.path @@ -172,13 +171,13 @@ class MediaWrapperComponent extends StatelessWidget { return InkWell(onTap: onTap, child: imageWidget); } - String _calculatePath(ArchiveServiceProvider archiveService) { + Uri _calculatePath(ArchiveServiceProvider archiveService) { final url = mediaAttachment.uri.toString(); String basePath = ''; if (url.startsWith('http')) { final localCacheFile = archiveService.getImageByUrl(url); if (localCacheFile.isFailure) { - return url; + return mediaAttachment.uri; } basePath = localCacheFile.value.localFilename; @@ -186,7 +185,7 @@ class MediaWrapperComponent extends StatelessWidget { basePath = mediaAttachment.uri.path; } - return archiveService.pathMappingService.toFullPath(basePath); + return Uri.parse(basePath); } } diff --git a/friendica_archive_browser/lib/src/diaspora/services/diaspora_path_mapping_service.dart b/friendica_archive_browser/lib/src/diaspora/services/diaspora_path_mapping_service.dart index 2e9ec39..5d2f62e 100644 --- a/friendica_archive_browser/lib/src/diaspora/services/diaspora_path_mapping_service.dart +++ b/friendica_archive_browser/lib/src/diaspora/services/diaspora_path_mapping_service.dart @@ -40,6 +40,10 @@ class DiasporaPathMappingService implements PathMappingService { @override String toFullPath(String relPath) { + if (File(relPath).existsSync()) { + return relPath; + } + for (final file in _photoDirectories) { final fullPath = p.join(file.path, relPath); if (File(fullPath).existsSync()) { diff --git a/friendica_archive_browser/lib/src/friendica/services/friendica_path_mapping_service.dart b/friendica_archive_browser/lib/src/friendica/services/friendica_path_mapping_service.dart index d189bd3..5d4b1bb 100644 --- a/friendica_archive_browser/lib/src/friendica/services/friendica_path_mapping_service.dart +++ b/friendica_archive_browser/lib/src/friendica/services/friendica_path_mapping_service.dart @@ -29,19 +29,9 @@ class FriendicaPathMappingService implements PathMappingService { } _archiveDirectories.clear(); - try { - if (_calcRootIsSingleArchiveFolder()) { - _archiveDirectories.add(Directory(rootFolder)); - return; - } - } catch (e) { - _logger - .severe('Error thrown while trying to calculate root structure: $e'); - return; - } - + final recursive = !_calcRootIsSingleArchiveFolder(); _archiveDirectories.addAll(Directory(settings.rootFolder) - .listSync(recursive: false) + .listSync(recursive: recursive) .where((element) => element.statSync().type == FileSystemEntityType.directory)); }