2021-04-10 06:28:12 +02:00
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:exifdart/exifdart_memory.dart';
|
|
|
|
import 'package:logging/logging.dart';
|
|
|
|
import 'package:nc_photos/account.dart';
|
|
|
|
import 'package:nc_photos/api/api.dart';
|
|
|
|
import 'package:nc_photos/api/api_util.dart' as api_util;
|
|
|
|
import 'package:nc_photos/entity/file.dart';
|
|
|
|
import 'package:nc_photos/exception.dart';
|
|
|
|
import 'package:nc_photos/image_size_getter_util.dart';
|
|
|
|
import 'package:nc_photos/platform/metadata_loader.dart' as itf;
|
|
|
|
|
|
|
|
class MetadataLoader implements itf.MetadataLoader {
|
|
|
|
// on web we just download the image again, hopefully the browser would
|
|
|
|
// cache it for us (which is sadly not the case :|
|
|
|
|
@override
|
|
|
|
loadCacheFile(Account account, File file) => loadNewFile(account, file);
|
|
|
|
|
|
|
|
@override
|
|
|
|
loadNewFile(Account account, File file) async {
|
|
|
|
final response =
|
|
|
|
await Api(account).files().get(path: api_util.getFileUrlRelative(file));
|
|
|
|
if (!response.isGood) {
|
|
|
|
_log.severe("[loadFile] Failed requesting server: $response");
|
|
|
|
throw ApiException(
|
|
|
|
response: response,
|
|
|
|
message: "Failed communicating with server: ${response.statusCode}");
|
|
|
|
}
|
2021-04-14 23:09:31 +02:00
|
|
|
return itf.MetadataLoader.loadMetadata(
|
2021-05-06 22:11:31 +02:00
|
|
|
file: file,
|
2021-04-14 23:09:31 +02:00
|
|
|
exifdartReaderBuilder: () => MemoryBlobReader(response.body),
|
|
|
|
imageSizeGetterInputBuilder: () => AsyncMemoryInput(response.body),
|
|
|
|
);
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
loadFile(Account account, File file) => loadNewFile(account, file);
|
|
|
|
|
|
|
|
@override
|
|
|
|
cancel() {}
|
|
|
|
|
|
|
|
static final _log = Logger("web.metadata_loader.MetadataLoader");
|
|
|
|
}
|