From 5f92d036fa22e9b663b7a47bcfd91090241bdfda Mon Sep 17 00:00:00 2001 From: lifegpc Date: Sat, 8 Mar 2025 15:18:26 +0800 Subject: [PATCH] Add new API --- lib/api/client.dart | 11 +++++++++++ lib/api/client.g.dart | 41 +++++++++++++++++++++++++++++++++++++++++ lib/api/gallery.dart | 15 +++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/lib/api/client.dart b/lib/api/client.dart index 7c4f2f3..ea85b2c 100644 --- a/lib/api/client.dart +++ b/lib/api/client.dart @@ -248,6 +248,12 @@ abstract class _EHApi { Future> _getGalleriesMeta(@Path("gids") String gids, // ignore: unused_element {@CancelRequest() CancelToken? cancel}); + @GET('/gallery/thumbnail/{gids}') + // ignore: unused_element + Future> _getGalleriesThumbnail( + @Path("gids") String gids, + // ignore: unused_element + {@CancelRequest() CancelToken? cancel}); @GET('/gallery/list') Future>> listGalleries( {@Query("all") bool? all, @@ -455,6 +461,11 @@ class EHApi extends __EHApi { return _getGalleriesMeta(gids.join(","), cancel: cancel); } + Future> getGalleriesThumbnail(List gids, + {CancelToken? cancel}) { + return _getGalleriesThumbnail(gids.join(","), cancel: cancel); + } + Future> getTags(List ids, {CancelToken? cancel}) { return _getTags(ids.join(","), cancel: cancel); } diff --git a/lib/api/client.g.dart b/lib/api/client.g.dart index 12ea8a4..e4ae293 100644 --- a/lib/api/client.g.dart +++ b/lib/api/client.g.dart @@ -1174,6 +1174,47 @@ class __EHApi implements _EHApi { return _value; } + @override + Future> _getGalleriesThumbnail( + String gids, { + CancelToken? cancel, + }) async { + final _extra = {}; + final queryParameters = {}; + queryParameters.removeWhere((k, v) => v == null); + final _headers = {}; + const Map? _data = null; + final _options = _setStreamType>(Options( + method: 'GET', + headers: _headers, + extra: _extra, + ) + .compose( + _dio.options, + '/gallery/thumbnail/${gids}', + queryParameters: queryParameters, + data: _data, + cancelToken: cancel, + ) + .copyWith( + baseUrl: _combineBaseUrls( + _dio.options.baseUrl, + baseUrl, + ))); + final _result = await _dio.fetch>(_options); + late ApiResult _value; + try { + _value = ApiResult.fromJson( + _result.data!, + (json) => GalleryThumbnails.fromJson(json as Map), + ); + } on Object catch (e, s) { + errorLogger?.logError(e, s, _options); + rethrow; + } + return _value; + } + @override Future>> listGalleries({ bool? all, diff --git a/lib/api/gallery.dart b/lib/api/gallery.dart index 4d5a135..b4c3a58 100644 --- a/lib/api/gallery.dart +++ b/lib/api/gallery.dart @@ -237,3 +237,18 @@ class GMetaSearchInfo { : titleJpn : title; } + +class GalleryThumbnails { + const GalleryThumbnails({ + required this.thumbnails, + }); + final Map> thumbnails; + factory GalleryThumbnails.fromJson(Map json) => + GalleryThumbnails( + thumbnails: json.map((key, value) => MapEntry( + int.parse(key), + ApiResult.fromJson( + value as Map, + (json) => + ExtendedPMeta.fromJson(json as Map))))); +}