mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-24 10:28:50 +01:00
Support loading metadata from local file
This commit is contained in:
parent
e343e59741
commit
731370e994
4 changed files with 39 additions and 6 deletions
15
app/lib/file_extension.dart
Normal file
15
app/lib/file_extension.dart
Normal file
|
@ -0,0 +1,15 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:path/path.dart' as path_lib;
|
||||
import 'package:mime/mime.dart';
|
||||
|
||||
extension FileExtension on File {
|
||||
Future<String?> readMime() async {
|
||||
final header = await openRead(0, defaultMagicNumbersMaxLength)
|
||||
.expand((element) => element)
|
||||
.toList();
|
||||
return lookupMimeType(path, headerBytes: header);
|
||||
}
|
||||
|
||||
String get filename => path_lib.basename(path);
|
||||
}
|
|
@ -1,19 +1,23 @@
|
|||
import 'dart:io' as io;
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:exifdart/exifdart.dart' as exifdart;
|
||||
import 'package:exifdart/exifdart_io.dart';
|
||||
import 'package:exifdart/exifdart_memory.dart';
|
||||
import 'package:image_size_getter/image_size_getter.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:nc_photos/account.dart';
|
||||
import 'package:nc_photos/debug_util.dart';
|
||||
import 'package:nc_photos/entity/exif.dart';
|
||||
import 'package:nc_photos/entity/file.dart';
|
||||
import 'package:nc_photos/entity/file.dart' as app;
|
||||
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
||||
import 'package:nc_photos/file_extension.dart';
|
||||
import 'package:nc_photos/image_size_getter_util.dart';
|
||||
|
||||
class LoadMetadata {
|
||||
/// Load metadata of [binary], which is the content of [file]
|
||||
Future<Metadata> loadRemote(Account account, File file, Uint8List binary) {
|
||||
Future<app.Metadata> loadRemote(
|
||||
Account account, app.File file, Uint8List binary) {
|
||||
return _loadMetadata(
|
||||
mime: file.contentType ?? "",
|
||||
exifdartReaderBuilder: () => MemoryBlobReader(binary),
|
||||
|
@ -22,7 +26,20 @@ class LoadMetadata {
|
|||
);
|
||||
}
|
||||
|
||||
Future<Metadata> _loadMetadata({
|
||||
Future<app.Metadata> loadLocal(
|
||||
io.File file, {
|
||||
String? mime,
|
||||
}) async {
|
||||
mime = mime ?? await file.readMime();
|
||||
return _loadMetadata(
|
||||
mime: mime ?? "",
|
||||
exifdartReaderBuilder: () => FileReader(file),
|
||||
imageSizeGetterInputBuilder: () => AsyncFileInput(file),
|
||||
filename: file.path,
|
||||
);
|
||||
}
|
||||
|
||||
Future<app.Metadata> _loadMetadata({
|
||||
required String mime,
|
||||
required exifdart.AbstractBlobReader Function() exifdartReaderBuilder,
|
||||
required AsyncImageInput Function() imageSizeGetterInputBuilder,
|
||||
|
@ -86,7 +103,7 @@ class LoadMetadata {
|
|||
return _buildMetadata(map);
|
||||
}
|
||||
|
||||
Metadata _buildMetadata(Map<String, dynamic> map) {
|
||||
app.Metadata _buildMetadata(Map<String, dynamic> map) {
|
||||
int? imageWidth, imageHeight;
|
||||
Exif? exif;
|
||||
if (map.containsKey("resolution")) {
|
||||
|
@ -96,7 +113,7 @@ class LoadMetadata {
|
|||
if (map.containsKey("exif")) {
|
||||
exif = Exif(map["exif"]);
|
||||
}
|
||||
return Metadata(
|
||||
return app.Metadata(
|
||||
imageWidth: imageWidth,
|
||||
imageHeight: imageHeight,
|
||||
exif: exif,
|
||||
|
|
|
@ -620,7 +620,7 @@ packages:
|
|||
source: hosted
|
||||
version: "2.0.0"
|
||||
mime:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: mime
|
||||
url: "https://pub.dartlang.org"
|
||||
|
|
|
@ -71,6 +71,7 @@ dependencies:
|
|||
intl: ^0.17.0
|
||||
kiwi: ^4.0.1
|
||||
logging: ^1.0.1
|
||||
mime: ^1.0.1
|
||||
mutex: ^3.0.0
|
||||
native_device_orientation: ^1.0.0
|
||||
nc_photos_plugin:
|
||||
|
|
Loading…
Reference in a new issue