mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-06-30 18:30:15 +08:00
Update
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import 'dart:convert';
|
||||
import 'package:cryptography/cryptography.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eh_downloader_flutter/api/file.dart';
|
||||
import 'package:retrofit/retrofit.dart';
|
||||
import 'api_result.dart';
|
||||
import 'status.dart';
|
||||
@@ -41,26 +42,41 @@ abstract class _EHApi {
|
||||
Future<ApiResult<ServerStatus>> getStatus();
|
||||
|
||||
@PUT('/token')
|
||||
// ignore: unused_element
|
||||
Future<ApiResult<Token>> _createToken(
|
||||
{@Query("username") required String username,
|
||||
@Query("password") required String password,
|
||||
@Query("t") required int t,
|
||||
// ignore: unused_element
|
||||
@Query("set_cookie") bool? setCookie,
|
||||
// ignore: unused_element
|
||||
@Query("http_only") bool? httpOnly,
|
||||
// ignore: unused_element
|
||||
@Query("secure") bool? secure});
|
||||
@DELETE('/token')
|
||||
Future<ApiResult<bool>> deleteToken({@Query("token") String? token});
|
||||
@GET('/token')
|
||||
Future<ApiResult<TokenWithUserInfo>> getToken({@Query("token") String? token});
|
||||
Future<ApiResult<TokenWithUserInfo>> getToken(
|
||||
{@Query("token") String? token});
|
||||
|
||||
@GET('/file/{id}')
|
||||
Future<HttpResponse> getFile(@Path("id") int id);
|
||||
@GET('/file/{id}')
|
||||
// ignore: unused_element
|
||||
Future<ApiResult<EhFileExtend>> _getFileData(
|
||||
@Path("id") int id, @Query("data") bool data);
|
||||
@GET('/file/random')
|
||||
Future<HttpResponse> getRandomFile({@Query("is_nsfw") bool? isNsfw, @Query("is_ad") bool? isAd, @Query("thumb") bool? thumb});
|
||||
Future<HttpResponse> getRandomFile(
|
||||
{@Query("is_nsfw") bool? isNsfw,
|
||||
@Query("is_ad") bool? isAd,
|
||||
@Query("thumb") bool? thumb});
|
||||
@GET('/files/{token}')
|
||||
// ignore: unused_element
|
||||
Future<ApiResult<EhFiles>> _getFiles(@Path("token") String token);
|
||||
}
|
||||
|
||||
class EHApi extends __EHApi {
|
||||
EHApi(Dio dio, {required String baseUrl}): super(dio, baseUrl: baseUrl);
|
||||
EHApi(Dio dio, {required String baseUrl}) : super(dio, baseUrl: baseUrl);
|
||||
Future<ApiResult<Token>> createToken(
|
||||
{required String username,
|
||||
required String password,
|
||||
@@ -81,4 +97,12 @@ class EHApi extends __EHApi {
|
||||
httpOnly: httpOnly,
|
||||
secure: secure);
|
||||
}
|
||||
|
||||
Future<ApiResult<EhFileExtend>> getFileData(int id) {
|
||||
return _getFileData(id, true);
|
||||
}
|
||||
|
||||
Future<ApiResult<EhFiles>> getFiles(List<String> tokens) {
|
||||
return _getFiles(tokens.join(","));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,6 +261,39 @@ class __EHApi implements _EHApi {
|
||||
return httpResponse;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ApiResult<EhFileExtend>> _getFileData(
|
||||
int id,
|
||||
bool data,
|
||||
) async {
|
||||
const _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{r'data': data};
|
||||
final _headers = <String, dynamic>{};
|
||||
final Map<String, dynamic>? _data = null;
|
||||
final _result = await _dio.fetch<Map<String, dynamic>>(
|
||||
_setStreamType<ApiResult<EhFileExtend>>(Options(
|
||||
method: 'GET',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/file/${id}',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(
|
||||
baseUrl: _combineBaseUrls(
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
))));
|
||||
final value = ApiResult<EhFileExtend>.fromJson(
|
||||
_result.data!,
|
||||
(json) => EhFileExtend.fromJson(json as Map<String, dynamic>),
|
||||
);
|
||||
return value;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<HttpResponse<dynamic>> getRandomFile({
|
||||
bool? isNsfw,
|
||||
@@ -298,6 +331,36 @@ class __EHApi implements _EHApi {
|
||||
return httpResponse;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ApiResult<EhFiles>> _getFiles(String token) 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<EhFiles>>(Options(
|
||||
method: 'GET',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/files/${token}',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(
|
||||
baseUrl: _combineBaseUrls(
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
))));
|
||||
final value = ApiResult<EhFiles>.fromJson(
|
||||
_result.data!,
|
||||
(json) => EhFiles.fromJson(json as Map<String, dynamic>),
|
||||
);
|
||||
return value;
|
||||
}
|
||||
|
||||
RequestOptions _setStreamType<T>(RequestOptions requestOptions) {
|
||||
if (T != dynamic &&
|
||||
!(requestOptions.responseType == ResponseType.bytes ||
|
||||
|
||||
52
lib/api/file.dart
Normal file
52
lib/api/file.dart
Normal file
@@ -0,0 +1,52 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'file.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class EhFileBasic {
|
||||
const EhFileBasic({
|
||||
required this.id,
|
||||
required this.width,
|
||||
required this.height,
|
||||
required this.isOriginal,
|
||||
});
|
||||
final int id;
|
||||
final int width;
|
||||
final int height;
|
||||
@JsonKey(name: 'is_original')
|
||||
final bool isOriginal;
|
||||
factory EhFileBasic.fromJson(Map<String, dynamic> json) =>
|
||||
_$EhFileBasicFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$EhFileBasicToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class EhFileExtend {
|
||||
const EhFileExtend({
|
||||
required this.id,
|
||||
required this.width,
|
||||
required this.height,
|
||||
required this.isOriginal,
|
||||
required this.token,
|
||||
});
|
||||
final int id;
|
||||
final int width;
|
||||
final int height;
|
||||
@JsonKey(name: 'is_original')
|
||||
final bool isOriginal;
|
||||
final String token;
|
||||
factory EhFileExtend.fromJson(Map<String, dynamic> json) =>
|
||||
_$EhFileExtendFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$EhFileExtendToJson(this);
|
||||
}
|
||||
|
||||
class EhFiles {
|
||||
const EhFiles({required this.files});
|
||||
final Map<String, EhFileBasic> files;
|
||||
factory EhFiles.fromJson(Map<String, dynamic> json) => EhFiles(
|
||||
files: (json).map(
|
||||
(k, e) =>
|
||||
MapEntry(k, EhFileBasic.fromJson(e as Map<String, dynamic>)),
|
||||
),
|
||||
);
|
||||
}
|
||||
39
lib/api/file.g.dart
Normal file
39
lib/api/file.g.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'file.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
EhFileBasic _$EhFileBasicFromJson(Map<String, dynamic> json) => EhFileBasic(
|
||||
id: json['id'] as int,
|
||||
width: json['width'] as int,
|
||||
height: json['height'] as int,
|
||||
isOriginal: json['is_original'] as bool,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$EhFileBasicToJson(EhFileBasic instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'width': instance.width,
|
||||
'height': instance.height,
|
||||
'is_original': instance.isOriginal,
|
||||
};
|
||||
|
||||
EhFileExtend _$EhFileExtendFromJson(Map<String, dynamic> json) => EhFileExtend(
|
||||
id: json['id'] as int,
|
||||
width: json['width'] as int,
|
||||
height: json['height'] as int,
|
||||
isOriginal: json['is_original'] as bool,
|
||||
token: json['token'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$EhFileExtendToJson(EhFileExtend instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'width': instance.width,
|
||||
'height': instance.height,
|
||||
'is_original': instance.isOriginal,
|
||||
'token': instance.token,
|
||||
};
|
||||
Reference in New Issue
Block a user