nc-photos/app/lib/entity/face/data_source.dart

38 lines
1.1 KiB
Dart
Raw Normal View History

2021-09-10 19:10:26 +02:00
import 'package:logging/logging.dart';
import 'package:nc_photos/account.dart';
import 'package:nc_photos/api/entity_converter.dart';
2021-09-10 19:10:26 +02:00
import 'package:nc_photos/entity/face.dart';
import 'package:nc_photos/entity/person.dart';
import 'package:nc_photos/exception.dart';
import 'package:nc_photos/np_api_util.dart';
import 'package:np_api/np_api.dart' as api;
2022-12-16 16:01:04 +01:00
import 'package:np_codegen/np_codegen.dart';
2021-09-10 19:10:26 +02:00
2022-12-16 16:01:04 +01:00
part 'data_source.g.dart';
@npLog
2021-09-10 19:10:26 +02:00
class FaceRemoteDataSource implements FaceDataSource {
const FaceRemoteDataSource();
@override
list(Account account, Person person) async {
_log.info("[list] $person");
final response = await ApiUtil.fromAccount(account)
2021-09-10 19:10:26 +02:00
.ocs()
.facerecognition()
.person(person.name)
.faces()
.get();
if (!response.isGood) {
_log.severe("[list] Failed requesting server: $response");
throw ApiException(
response: response,
message: "Server responed with an error: HTTP ${response.statusCode}",
);
2021-09-10 19:10:26 +02:00
}
final apiFaces = await api.FaceParser().parse(response.body);
return apiFaces.map(ApiFaceConverter.fromApi).toList();
2021-09-10 19:10:26 +02:00
}
}