Merge pull request #29 from ente-io/invalid_file
This commit is contained in:
commit
f244472671
3 changed files with 11 additions and 9 deletions
|
@ -1,4 +1,6 @@
|
|||
class InvalidFileError extends Error {}
|
||||
class InvalidFileError extends ArgumentError {
|
||||
InvalidFileError(String message) : super(message);
|
||||
}
|
||||
|
||||
class InvalidFileUploadState extends AssertionError {
|
||||
InvalidFileUploadState(String message) : super(message);
|
||||
|
|
|
@ -279,7 +279,7 @@ class FileUploader {
|
|||
mediaUploadData = await getUploadDataFromEnteFile(file);
|
||||
} catch (e) {
|
||||
if (e is InvalidFileError) {
|
||||
await _onInvalidFileError(file);
|
||||
await _onInvalidFileError(file, e);
|
||||
} else {
|
||||
rethrow;
|
||||
}
|
||||
|
@ -403,12 +403,12 @@ class FileUploader {
|
|||
}
|
||||
}
|
||||
|
||||
Future _onInvalidFileError(File file) async {
|
||||
Future _onInvalidFileError(File file, InvalidFileError e) async {
|
||||
String ext = file.title == null ? "no title" : extension(file.title);
|
||||
_logger.severe("Invalid file: (ext: $ext) encountered: " + file.toString());
|
||||
_logger.severe("Invalid file: (ext: $ext) encountered: " + file.toString(), e);
|
||||
await FilesDB.instance.deleteLocalFile(file);
|
||||
await LocalSyncService.instance.trackInvalidFile(file);
|
||||
throw InvalidFileError();
|
||||
throw e;
|
||||
}
|
||||
|
||||
Future<File> _uploadFile(
|
||||
|
|
|
@ -51,7 +51,7 @@ Future<MediaUploadData> _getMediaUploadDataFromAssetFile(ente.File file) async {
|
|||
}
|
||||
});
|
||||
if (asset == null) {
|
||||
throw InvalidFileError();
|
||||
throw InvalidFileError("asset is null");
|
||||
}
|
||||
sourceFile = await asset.originFile
|
||||
.timeout(Duration(seconds: 3))
|
||||
|
@ -64,7 +64,7 @@ Future<MediaUploadData> _getMediaUploadDataFromAssetFile(ente.File file) async {
|
|||
}
|
||||
});
|
||||
if (sourceFile == null || !sourceFile.existsSync()) {
|
||||
throw InvalidFileError();
|
||||
throw InvalidFileError("source fill is null or do not exist");
|
||||
}
|
||||
|
||||
// h4ck to fetch location data if missing (thank you Android Q+) lazily only during uploads
|
||||
|
@ -100,7 +100,7 @@ Future<MediaUploadData> _getMediaUploadDataFromAssetFile(ente.File file) async {
|
|||
quality: kThumbnailQuality,
|
||||
);
|
||||
if (thumbnailData == null) {
|
||||
throw InvalidFileError();
|
||||
throw InvalidFileError("unable to get asset thumbData");
|
||||
}
|
||||
int compressionAttempts = 0;
|
||||
while (thumbnailData.length > kThumbnailDataLimit &&
|
||||
|
@ -138,7 +138,7 @@ Future<MediaUploadData> _getMediaUploadDataFromAppCache(ente.File file) async {
|
|||
sourceFile = io.File(localPath);
|
||||
if (!sourceFile.existsSync()) {
|
||||
_logger.warning("File doesn't exist in app sandbox");
|
||||
throw InvalidFileError();
|
||||
throw InvalidFileError("File doesn't exist in app sandbox");
|
||||
}
|
||||
thumbnailData = await getThumbnailFromInAppCacheFile(file);
|
||||
return MediaUploadData(sourceFile, thumbnailData, isDeleted);
|
||||
|
|
Loading…
Add table
Reference in a new issue