diff --git a/lib/models/file.dart b/lib/models/file.dart index f4c318d51..34c746892 100644 --- a/lib/models/file.dart +++ b/lib/models/file.dart @@ -12,7 +12,6 @@ class File { String localID; String title; String deviceFolder; - bool isEncrypted; int creationTime; int modificationTime; int updationTime; @@ -44,7 +43,6 @@ class File { file.fileType = FileType.other; break; } - file.isEncrypted = false; file.creationTime = asset.createDateTime.microsecondsSinceEpoch; if (file.creationTime == 0) { try { diff --git a/lib/ui/video_widget.dart b/lib/ui/video_widget.dart index 7dca0c567..834eff20a 100644 --- a/lib/ui/video_widget.dart +++ b/lib/ui/video_widget.dart @@ -55,32 +55,19 @@ class _VideoWidgetState extends State { } void _loadNetworkVideo() { - if (!widget.file.isEncrypted) { - _setVideoPlayerController(url: widget.file.getStreamUrl()); - _videoPlayerController.addListener(() { - if (_videoPlayerController.value.hasError) { - _logger.warning(_videoPlayerController.value.errorDescription); - showToast( - "the video has not been processed yet. downloading the original one...", - toastLength: Toast.LENGTH_SHORT); - _setVideoPlayerController(url: widget.file.getDownloadUrl()); - } - }); - } else { - getFileFromServer( - widget.file, - progressCallback: (count, total) { - setState(() { - _progress = count / total; - if (_progress == 1) { - showToast("decrypting video...", toastLength: Toast.LENGTH_SHORT); - } - }); - }, - ).then((file) { - _setVideoPlayerController(file: file); - }); - } + getFileFromServer( + widget.file, + progressCallback: (count, total) { + setState(() { + _progress = count / total; + if (_progress == 1) { + showToast("decrypting video...", toastLength: Toast.LENGTH_SHORT); + } + }); + }, + ).then((file) { + _setVideoPlayerController(file: file); + }); } @override diff --git a/lib/utils/file_downloader.dart b/lib/utils/file_downloader.dart index 329e461c0..eacc8e1b5 100644 --- a/lib/utils/file_downloader.dart +++ b/lib/utils/file_downloader.dart @@ -57,7 +57,6 @@ class DiffFetcher { continue; } file.ownerID = item["ownerID"]; - file.isEncrypted = true; file.encryptedKey = item["encryptedKey"]; file.keyDecryptionNonce = item["keyDecryptionNonce"]; file.fileDecryptionHeader = item["file"]["decryptionHeader"]; diff --git a/lib/utils/file_util.dart b/lib/utils/file_util.dart index 1854631c8..b5cf3cfaa 100644 --- a/lib/utils/file_util.dart +++ b/lib/utils/file_util.dart @@ -169,53 +169,40 @@ Future getFileFromServer(File file, final cacheManager = file.fileType == FileType.video ? VideoCacheManager() : DefaultCacheManager(); - if (!file.isEncrypted) { - return cacheManager.getSingleFile(file.getDownloadUrl()); - } else { - return cacheManager.getFileFromCache(file.getDownloadUrl()).then((info) { - if (info == null) { - if (!fileDownloadsInProgress.containsKey(file.uploadedFileID)) { - fileDownloadsInProgress[file.uploadedFileID] = _downloadAndDecrypt( - file, - cacheManager, - progressCallback: progressCallback, - ); - } - return fileDownloadsInProgress[file.uploadedFileID]; - } else { - return info.file; + return cacheManager.getFileFromCache(file.getDownloadUrl()).then((info) { + if (info == null) { + if (!fileDownloadsInProgress.containsKey(file.uploadedFileID)) { + fileDownloadsInProgress[file.uploadedFileID] = _downloadAndDecrypt( + file, + cacheManager, + progressCallback: progressCallback, + ); } - }); - } + return fileDownloadsInProgress[file.uploadedFileID]; + } else { + return info.file; + } + }); } Future getThumbnailFromServer(File file) async { - if (!file.isEncrypted) { - return ThumbnailCacheManager() - .getSingleFile(file.getThumbnailUrl()) - .then((data) { - ThumbnailFileLruCache.put(file, data); - return data; - }); - } else { - return ThumbnailCacheManager() - .getFileFromCache(file.getThumbnailUrl()) - .then((info) { - if (info == null) { - if (!thumbnailDownloadsInProgress.containsKey(file.uploadedFileID)) { - thumbnailDownloadsInProgress[file.uploadedFileID] = - _downloadAndDecryptThumbnail(file).then((data) { - ThumbnailFileLruCache.put(file, data); - return data; - }); - } - return thumbnailDownloadsInProgress[file.uploadedFileID]; - } else { - ThumbnailFileLruCache.put(file, info.file); - return info.file; + return ThumbnailCacheManager() + .getFileFromCache(file.getThumbnailUrl()) + .then((info) { + if (info == null) { + if (!thumbnailDownloadsInProgress.containsKey(file.uploadedFileID)) { + thumbnailDownloadsInProgress[file.uploadedFileID] = + _downloadAndDecryptThumbnail(file).then((data) { + ThumbnailFileLruCache.put(file, data); + return data; + }); } - }); - } + return thumbnailDownloadsInProgress[file.uploadedFileID]; + } else { + ThumbnailFileLruCache.put(file, info.file); + return info.file; + } + }); } Future _downloadAndDecrypt(File file, BaseCacheManager cacheManager,