Remove legacy code related to orma.in where files could be unencrypted

This commit is contained in:
Vishnu Mohandas 2021-02-08 14:35:41 +05:30
parent 383b67427f
commit 77b909f3d2
4 changed files with 42 additions and 71 deletions

View file

@ -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 {

View file

@ -55,32 +55,19 @@ class _VideoWidgetState extends State<VideoWidget> {
}
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

View file

@ -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"];

View file

@ -169,53 +169,40 @@ Future<io.File> 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<io.File> 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<io.File> _downloadAndDecrypt(File file, BaseCacheManager cacheManager,