2022-01-25 11:08:13 +01:00
|
|
|
import 'package:logging/logging.dart';
|
|
|
|
import 'package:nc_photos/account.dart';
|
2023-02-23 15:49:17 +01:00
|
|
|
import 'package:nc_photos/api/entity_converter.dart';
|
2022-01-25 11:08:13 +01:00
|
|
|
import 'package:nc_photos/entity/favorite.dart';
|
|
|
|
import 'package:nc_photos/entity/file.dart';
|
|
|
|
import 'package:nc_photos/exception.dart';
|
2023-02-23 15:49:17 +01:00
|
|
|
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';
|
2022-01-25 11:08:13 +01:00
|
|
|
|
2022-12-16 16:01:04 +01:00
|
|
|
part 'data_source.g.dart';
|
|
|
|
|
|
|
|
@npLog
|
2022-01-25 11:08:13 +01:00
|
|
|
class FavoriteRemoteDataSource implements FavoriteDataSource {
|
|
|
|
const FavoriteRemoteDataSource();
|
|
|
|
|
|
|
|
@override
|
|
|
|
list(Account account, File dir) async {
|
|
|
|
_log.info("[list] ${dir.path}");
|
2023-02-23 15:49:17 +01:00
|
|
|
final response = await ApiUtil.fromAccount(account).files().report(
|
2022-01-25 11:08:13 +01:00
|
|
|
path: dir.path,
|
|
|
|
favorite: true,
|
|
|
|
);
|
|
|
|
if (!response.isGood) {
|
|
|
|
_log.severe("[list] Failed requesting server: $response");
|
|
|
|
throw ApiException(
|
2023-02-23 15:49:17 +01:00
|
|
|
response: response,
|
|
|
|
message: "Server responed with an error: HTTP ${response.statusCode}",
|
|
|
|
);
|
2022-01-25 11:08:13 +01:00
|
|
|
}
|
|
|
|
|
2023-02-23 15:49:17 +01:00
|
|
|
final apiFavorites = await api.FavoriteParser().parse(response.body);
|
|
|
|
return apiFavorites.map(ApiFavoriteConverter.fromApi).toList();
|
2022-01-25 11:08:13 +01:00
|
|
|
}
|
|
|
|
}
|