mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-01-22 16:56:19 +01:00
Fix exception when loadind metadata for png/webp
This commit is contained in:
parent
9d2e1798f7
commit
5ad3254634
4 changed files with 26 additions and 8 deletions
|
@ -10,6 +10,9 @@ bool isSupportedImageFormat(File file) =>
|
|||
bool isSupportedVideoFormat(File file) =>
|
||||
isSupportedFormat(file) && file.contentType?.startsWith("video/") == true;
|
||||
|
||||
bool isMetadataSupportedFormat(File file) =>
|
||||
_metadataSupportedFormatMimes.contains(file.contentType);
|
||||
|
||||
const _supportedFormatMimes = [
|
||||
"image/jpeg",
|
||||
"image/png",
|
||||
|
@ -18,3 +21,8 @@ const _supportedFormatMimes = [
|
|||
// video player currently doesn't work on web
|
||||
if (!platform_k.isWeb) "video/mp4",
|
||||
];
|
||||
|
||||
const _metadataSupportedFormatMimes = [
|
||||
"image/jpeg",
|
||||
"image/heic",
|
||||
];
|
||||
|
|
|
@ -23,7 +23,7 @@ class MetadataLoader implements itf.MetadataLoader {
|
|||
Future.delayed(Duration(seconds: 10)),
|
||||
]);
|
||||
if (_getFileTask.isGood && result is FileInfo) {
|
||||
return _onGetFile(result);
|
||||
return _onGetFile(file, result);
|
||||
} else {
|
||||
// timeout
|
||||
_getFileTask.cancel();
|
||||
|
@ -42,6 +42,7 @@ class MetadataLoader implements itf.MetadataLoader {
|
|||
message: "Failed communicating with server: ${response.statusCode}");
|
||||
}
|
||||
return itf.MetadataLoader.loadMetadata(
|
||||
file: file,
|
||||
exifdartReaderBuilder: () => MemoryBlobReader(response.body),
|
||||
imageSizeGetterInputBuilder: () => AsyncMemoryInput(response.body),
|
||||
);
|
||||
|
@ -55,7 +56,7 @@ class MetadataLoader implements itf.MetadataLoader {
|
|||
// no cache
|
||||
return loadNewFile(account, file);
|
||||
} else {
|
||||
return _onGetFile(info);
|
||||
return _onGetFile(file, info);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,10 +65,11 @@ class MetadataLoader implements itf.MetadataLoader {
|
|||
_getFileTask.cancel();
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> _onGetFile(FileInfo f) {
|
||||
Future<Map<String, dynamic>> _onGetFile(File file, FileInfo info) {
|
||||
return itf.MetadataLoader.loadMetadata(
|
||||
exifdartReaderBuilder: () => FileReader(f.file),
|
||||
imageSizeGetterInputBuilder: () => AsyncFileInput(f.file),
|
||||
file: file,
|
||||
exifdartReaderBuilder: () => FileReader(info.file),
|
||||
imageSizeGetterInputBuilder: () => AsyncFileInput(info.file),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import 'package:exifdart/exifdart.dart';
|
||||
import 'package:exifdart/exifdart.dart' as exifdart;
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:image_size_getter/image_size_getter.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
||||
|
||||
abstract class MetadataLoader {
|
||||
/// Load metadata for [file] from cache
|
||||
|
@ -24,10 +25,16 @@ abstract class MetadataLoader {
|
|||
|
||||
@protected
|
||||
static Future<Map<String, dynamic>> loadMetadata({
|
||||
AbstractBlobReader Function() exifdartReaderBuilder,
|
||||
@required File file,
|
||||
exifdart.AbstractBlobReader Function() exifdartReaderBuilder,
|
||||
AsyncImageInput Function() imageSizeGetterInputBuilder,
|
||||
}) async {
|
||||
final metadata = await readMetadata(exifdartReaderBuilder());
|
||||
exifdart.Metadata metadata;
|
||||
if (file_util.isMetadataSupportedFormat(file)) {
|
||||
metadata = await exifdart.readMetadata(exifdartReaderBuilder());
|
||||
} else {
|
||||
metadata = exifdart.Metadata();
|
||||
}
|
||||
int imageWidth, imageHeight;
|
||||
if (metadata.imageWidth == null || metadata.imageHeight == null) {
|
||||
final resolution =
|
||||
|
|
|
@ -27,6 +27,7 @@ class MetadataLoader implements itf.MetadataLoader {
|
|||
message: "Failed communicating with server: ${response.statusCode}");
|
||||
}
|
||||
return itf.MetadataLoader.loadMetadata(
|
||||
file: file,
|
||||
exifdartReaderBuilder: () => MemoryBlobReader(response.body),
|
||||
imageSizeGetterInputBuilder: () => AsyncMemoryInput(response.body),
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue