mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-07-08 01:30:28 +08:00
Update
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:dio/dio.dart';
|
||||
import 'package:eh_downloader_flutter/api/file.dart';
|
||||
import 'package:retrofit/retrofit.dart';
|
||||
import 'api_result.dart';
|
||||
import 'gallery.dart';
|
||||
import 'status.dart';
|
||||
import 'token.dart';
|
||||
import 'user.dart';
|
||||
@@ -76,6 +77,14 @@ abstract class _EHApi {
|
||||
@GET('/files/{token}')
|
||||
// ignore: unused_element
|
||||
Future<ApiResult<EhFiles>> _getFiles(@Path("token") String token);
|
||||
|
||||
@GET('/gallery/{gid}')
|
||||
Future<ApiResult<GalleryData>> getGallery(@Path("gid") int gid);
|
||||
@GET('/gallery/list')
|
||||
Future<ApiResult<List<GMeta>>> listGalleries(
|
||||
{@Query("all") bool? all,
|
||||
@Query("offset") int? offset,
|
||||
@Query("limit") int? limit});
|
||||
}
|
||||
|
||||
class EHApi extends __EHApi {
|
||||
|
||||
@@ -408,6 +408,79 @@ class __EHApi implements _EHApi {
|
||||
return value;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ApiResult<GalleryData>> getGallery(int gid) async {
|
||||
const _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
final Map<String, dynamic>? _data = null;
|
||||
final _result = await _dio.fetch<Map<String, dynamic>>(
|
||||
_setStreamType<ApiResult<GalleryData>>(Options(
|
||||
method: 'GET',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/gallery/${gid}',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(
|
||||
baseUrl: _combineBaseUrls(
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
))));
|
||||
final value = ApiResult<GalleryData>.fromJson(
|
||||
_result.data!,
|
||||
(json) => GalleryData.fromJson(json as Map<String, dynamic>),
|
||||
);
|
||||
return value;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ApiResult<List<GMeta>>> listGalleries({
|
||||
bool? all,
|
||||
int? offset,
|
||||
int? limit,
|
||||
}) async {
|
||||
const _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{
|
||||
r'all': all,
|
||||
r'offset': offset,
|
||||
r'limit': limit,
|
||||
};
|
||||
queryParameters.removeWhere((k, v) => v == null);
|
||||
final _headers = <String, dynamic>{};
|
||||
final Map<String, dynamic>? _data = null;
|
||||
final _result = await _dio.fetch<Map<String, dynamic>>(
|
||||
_setStreamType<ApiResult<List<GMeta>>>(Options(
|
||||
method: 'GET',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/gallery/list',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(
|
||||
baseUrl: _combineBaseUrls(
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
))));
|
||||
final value = ApiResult<List<GMeta>>.fromJson(
|
||||
_result.data!,
|
||||
(json) => json is List<dynamic>
|
||||
? json
|
||||
.map<GMeta>((i) => GMeta.fromJson(i as Map<String, dynamic>))
|
||||
.toList()
|
||||
: List.empty(),
|
||||
);
|
||||
return value;
|
||||
}
|
||||
|
||||
RequestOptions _setStreamType<T>(RequestOptions requestOptions) {
|
||||
if (T != dynamic &&
|
||||
!(requestOptions.responseType == ResponseType.bytes ||
|
||||
|
||||
163
lib/api/gallery.dart
Normal file
163
lib/api/gallery.dart
Normal file
@@ -0,0 +1,163 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'gallery.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class GMeta {
|
||||
const GMeta({
|
||||
required this.gid,
|
||||
required this.token,
|
||||
required this.title,
|
||||
required this.titleJpn,
|
||||
required this.category,
|
||||
required this.uploader,
|
||||
required this.posted,
|
||||
required this.filecount,
|
||||
required this.filesize,
|
||||
required this.expunged,
|
||||
required this.rating,
|
||||
this.parentGid,
|
||||
this.parentToken,
|
||||
this.firstGid,
|
||||
this.firstToken,
|
||||
});
|
||||
final int gid;
|
||||
final String token;
|
||||
final String title;
|
||||
@JsonKey(name: 'title_jpn')
|
||||
final String titleJpn;
|
||||
final String category;
|
||||
final String uploader;
|
||||
@JsonKey(fromJson: _fromJson, toJson: _toJson)
|
||||
final DateTime posted;
|
||||
final int filecount;
|
||||
final int filesize;
|
||||
final bool expunged;
|
||||
final double rating;
|
||||
@JsonKey(name: 'parent_gid')
|
||||
final int? parentGid;
|
||||
@JsonKey(name: 'parent_token')
|
||||
final String? parentToken;
|
||||
@JsonKey(name: 'first_gid')
|
||||
final int? firstGid;
|
||||
@JsonKey(name: 'first_token')
|
||||
final String? firstToken;
|
||||
|
||||
static DateTime _fromJson(int posted) =>
|
||||
DateTime.fromMillisecondsSinceEpoch(posted * 1000);
|
||||
static int _toJson(DateTime posted) => posted.millisecondsSinceEpoch ~/ 1000;
|
||||
factory GMeta.fromJson(Map<String, dynamic> json) => _$GMetaFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GMetaToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class GMetaOptional {
|
||||
const GMetaOptional({
|
||||
this.gid,
|
||||
this.token,
|
||||
this.title,
|
||||
this.titleJpn,
|
||||
this.category,
|
||||
this.uploader,
|
||||
this.posted,
|
||||
this.filecount,
|
||||
this.filesize,
|
||||
this.expunged,
|
||||
this.rating,
|
||||
this.parentGid,
|
||||
this.parentToken,
|
||||
this.firstGid,
|
||||
this.firstToken,
|
||||
});
|
||||
final int? gid;
|
||||
final String? token;
|
||||
final String? title;
|
||||
@JsonKey(name: 'title_jpn')
|
||||
final String? titleJpn;
|
||||
final String? category;
|
||||
final String? uploader;
|
||||
@JsonKey(fromJson: _fromJson, toJson: _toJson)
|
||||
final DateTime? posted;
|
||||
final int? filecount;
|
||||
final int? filesize;
|
||||
final bool? expunged;
|
||||
final double? rating;
|
||||
@JsonKey(name: 'parent_gid')
|
||||
final int? parentGid;
|
||||
@JsonKey(name: 'parent_token')
|
||||
final String? parentToken;
|
||||
@JsonKey(name: 'first_gid')
|
||||
final int? firstGid;
|
||||
@JsonKey(name: 'first_token')
|
||||
final String? firstToken;
|
||||
|
||||
static DateTime? _fromJson(int? posted) => posted != null
|
||||
? DateTime.fromMillisecondsSinceEpoch(posted! * 1000)
|
||||
: null;
|
||||
static int? _toJson(DateTime? posted) =>
|
||||
posted != null ? posted.millisecondsSinceEpoch ~/ 1000 : null;
|
||||
factory GMetaOptional.fromJson(Map<String, dynamic> json) =>
|
||||
_$GMetaOptionalFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GMetaOptionalToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class Tag {
|
||||
const Tag({
|
||||
required this.id,
|
||||
required this.tag,
|
||||
this.translated,
|
||||
this.intro,
|
||||
});
|
||||
final int id;
|
||||
final String tag;
|
||||
final String? translated;
|
||||
final String? intro;
|
||||
|
||||
factory Tag.fromJson(Map<String, dynamic> json) => _$TagFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$TagToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class ExtendedPMeta {
|
||||
const ExtendedPMeta({
|
||||
required this.gid,
|
||||
required this.index,
|
||||
required this.token,
|
||||
required this.name,
|
||||
required this.width,
|
||||
required this.height,
|
||||
required this.isNsfw,
|
||||
required this.isAd,
|
||||
});
|
||||
final int gid;
|
||||
final int index;
|
||||
final String token;
|
||||
final String name;
|
||||
final int width;
|
||||
final int height;
|
||||
@JsonKey(name: 'is_nsfw')
|
||||
final bool isNsfw;
|
||||
@JsonKey(name: 'is_ad')
|
||||
final bool isAd;
|
||||
|
||||
factory ExtendedPMeta.fromJson(Map<String, dynamic> json) =>
|
||||
_$ExtendedPMetaFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$ExtendedPMetaToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class GalleryData {
|
||||
const GalleryData({
|
||||
required this.meta,
|
||||
required this.tags,
|
||||
required this.pages,
|
||||
});
|
||||
final GMeta meta;
|
||||
final List<Tag> tags;
|
||||
final List<ExtendedPMeta> pages;
|
||||
|
||||
factory GalleryData.fromJson(Map<String, dynamic> json) =>
|
||||
_$GalleryDataFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GalleryDataToJson(this);
|
||||
}
|
||||
136
lib/api/gallery.g.dart
Normal file
136
lib/api/gallery.g.dart
Normal file
@@ -0,0 +1,136 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'gallery.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
GMeta _$GMetaFromJson(Map<String, dynamic> json) => GMeta(
|
||||
gid: json['gid'] as int,
|
||||
token: json['token'] as String,
|
||||
title: json['title'] as String,
|
||||
titleJpn: json['title_jpn'] as String,
|
||||
category: json['category'] as String,
|
||||
uploader: json['uploader'] as String,
|
||||
posted: GMeta._fromJson(json['posted'] as int),
|
||||
filecount: json['filecount'] as int,
|
||||
filesize: json['filesize'] as int,
|
||||
expunged: json['expunged'] as bool,
|
||||
rating: (json['rating'] as num).toDouble(),
|
||||
parentGid: json['parent_gid'] as int?,
|
||||
parentToken: json['parent_token'] as String?,
|
||||
firstGid: json['first_gid'] as int?,
|
||||
firstToken: json['first_token'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GMetaToJson(GMeta instance) => <String, dynamic>{
|
||||
'gid': instance.gid,
|
||||
'token': instance.token,
|
||||
'title': instance.title,
|
||||
'title_jpn': instance.titleJpn,
|
||||
'category': instance.category,
|
||||
'uploader': instance.uploader,
|
||||
'posted': GMeta._toJson(instance.posted),
|
||||
'filecount': instance.filecount,
|
||||
'filesize': instance.filesize,
|
||||
'expunged': instance.expunged,
|
||||
'rating': instance.rating,
|
||||
'parent_gid': instance.parentGid,
|
||||
'parent_token': instance.parentToken,
|
||||
'first_gid': instance.firstGid,
|
||||
'first_token': instance.firstToken,
|
||||
};
|
||||
|
||||
GMetaOptional _$GMetaOptionalFromJson(Map<String, dynamic> json) =>
|
||||
GMetaOptional(
|
||||
gid: json['gid'] as int?,
|
||||
token: json['token'] as String?,
|
||||
title: json['title'] as String?,
|
||||
titleJpn: json['title_jpn'] as String?,
|
||||
category: json['category'] as String?,
|
||||
uploader: json['uploader'] as String?,
|
||||
posted: GMetaOptional._fromJson(json['posted'] as int?),
|
||||
filecount: json['filecount'] as int?,
|
||||
filesize: json['filesize'] as int?,
|
||||
expunged: json['expunged'] as bool?,
|
||||
rating: (json['rating'] as num?)?.toDouble(),
|
||||
parentGid: json['parent_gid'] as int?,
|
||||
parentToken: json['parent_token'] as String?,
|
||||
firstGid: json['first_gid'] as int?,
|
||||
firstToken: json['first_token'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GMetaOptionalToJson(GMetaOptional instance) =>
|
||||
<String, dynamic>{
|
||||
'gid': instance.gid,
|
||||
'token': instance.token,
|
||||
'title': instance.title,
|
||||
'title_jpn': instance.titleJpn,
|
||||
'category': instance.category,
|
||||
'uploader': instance.uploader,
|
||||
'posted': GMetaOptional._toJson(instance.posted),
|
||||
'filecount': instance.filecount,
|
||||
'filesize': instance.filesize,
|
||||
'expunged': instance.expunged,
|
||||
'rating': instance.rating,
|
||||
'parent_gid': instance.parentGid,
|
||||
'parent_token': instance.parentToken,
|
||||
'first_gid': instance.firstGid,
|
||||
'first_token': instance.firstToken,
|
||||
};
|
||||
|
||||
Tag _$TagFromJson(Map<String, dynamic> json) => Tag(
|
||||
id: json['id'] as int,
|
||||
tag: json['tag'] as String,
|
||||
translated: json['translated'] as String?,
|
||||
intro: json['intro'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$TagToJson(Tag instance) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'tag': instance.tag,
|
||||
'translated': instance.translated,
|
||||
'intro': instance.intro,
|
||||
};
|
||||
|
||||
ExtendedPMeta _$ExtendedPMetaFromJson(Map<String, dynamic> json) =>
|
||||
ExtendedPMeta(
|
||||
gid: json['gid'] as int,
|
||||
index: json['index'] as int,
|
||||
token: json['token'] as String,
|
||||
name: json['name'] as String,
|
||||
width: json['width'] as int,
|
||||
height: json['height'] as int,
|
||||
isNsfw: json['is_nsfw'] as bool,
|
||||
isAd: json['is_ad'] as bool,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ExtendedPMetaToJson(ExtendedPMeta instance) =>
|
||||
<String, dynamic>{
|
||||
'gid': instance.gid,
|
||||
'index': instance.index,
|
||||
'token': instance.token,
|
||||
'name': instance.name,
|
||||
'width': instance.width,
|
||||
'height': instance.height,
|
||||
'is_nsfw': instance.isNsfw,
|
||||
'is_ad': instance.isAd,
|
||||
};
|
||||
|
||||
GalleryData _$GalleryDataFromJson(Map<String, dynamic> json) => GalleryData(
|
||||
meta: GMeta.fromJson(json['meta'] as Map<String, dynamic>),
|
||||
tags: (json['tags'] as List<dynamic>)
|
||||
.map((e) => Tag.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
pages: (json['pages'] as List<dynamic>)
|
||||
.map((e) => ExtendedPMeta.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GalleryDataToJson(GalleryData instance) =>
|
||||
<String, dynamic>{
|
||||
'meta': instance.meta,
|
||||
'tags': instance.tags,
|
||||
'pages': instance.pages,
|
||||
};
|
||||
Reference in New Issue
Block a user