mirror of
https://github.com/lifegpc/eh_downloader_flutter.git
synced 2026-06-22 11:54:18 +08:00
Add session manage page
This commit is contained in:
@@ -187,9 +187,20 @@ abstract class _EHApi {
|
||||
Future<ApiResult<bool>> deleteToken(
|
||||
{@Part(name: "token") String? token,
|
||||
@CancelRequest() CancelToken? cancel});
|
||||
@DELETE('/token/manage')
|
||||
@MultiPart()
|
||||
Future<ApiResult<bool>> deleteTokenById(@Part(name: "id") int id,
|
||||
{@CancelRequest() CancelToken? cancel});
|
||||
@GET('/token')
|
||||
Future<ApiResult<TokenWithUserInfo>> getToken(
|
||||
{@Query("token") String? token, @CancelRequest() CancelToken? cancel});
|
||||
@GET('/token/manage')
|
||||
Future<ApiResult<List<TokenWithoutToken>>> getTokens(
|
||||
{@Query("uid") int? uid,
|
||||
@Query("offset") int? offset,
|
||||
@Query("limit") int? limit,
|
||||
@Query("all_user") bool? allUser,
|
||||
@CancelRequest() CancelToken? cancel});
|
||||
@GET('/shared_token')
|
||||
Future<ApiResult<SharedToken>> getSharedToken(
|
||||
{@CancelRequest() CancelToken? cancel});
|
||||
|
||||
@@ -689,6 +689,52 @@ class __EHApi implements _EHApi {
|
||||
return _value;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ApiResult<bool>> deleteTokenById(
|
||||
int id, {
|
||||
CancelToken? cancel,
|
||||
}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
queryParameters.removeWhere((k, v) => v == null);
|
||||
final _headers = <String, dynamic>{};
|
||||
final _data = FormData();
|
||||
_data.fields.add(MapEntry(
|
||||
'id',
|
||||
id.toString(),
|
||||
));
|
||||
final _options = _setStreamType<ApiResult<bool>>(Options(
|
||||
method: 'DELETE',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
contentType: 'multipart/form-data',
|
||||
)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/token/manage',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
cancelToken: cancel,
|
||||
)
|
||||
.copyWith(
|
||||
baseUrl: _combineBaseUrls(
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
)));
|
||||
final _result = await _dio.fetch<Map<String, dynamic>>(_options);
|
||||
late ApiResult<bool> _value;
|
||||
try {
|
||||
_value = ApiResult<bool>.fromJson(
|
||||
_result.data!,
|
||||
(json) => json as bool,
|
||||
);
|
||||
} on Object catch (e, s) {
|
||||
errorLogger?.logError(e, s, _options);
|
||||
rethrow;
|
||||
}
|
||||
return _value;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ApiResult<TokenWithUserInfo>> getToken({
|
||||
String? token,
|
||||
@@ -730,6 +776,60 @@ class __EHApi implements _EHApi {
|
||||
return _value;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ApiResult<List<TokenWithoutToken>>> getTokens({
|
||||
int? uid,
|
||||
int? offset,
|
||||
int? limit,
|
||||
bool? allUser,
|
||||
CancelToken? cancel,
|
||||
}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{
|
||||
r'uid': uid,
|
||||
r'offset': offset,
|
||||
r'limit': limit,
|
||||
r'all_user': allUser,
|
||||
};
|
||||
queryParameters.removeWhere((k, v) => v == null);
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
final _options = _setStreamType<ApiResult<List<TokenWithoutToken>>>(Options(
|
||||
method: 'GET',
|
||||
headers: _headers,
|
||||
extra: _extra,
|
||||
)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/token/manage',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
cancelToken: cancel,
|
||||
)
|
||||
.copyWith(
|
||||
baseUrl: _combineBaseUrls(
|
||||
_dio.options.baseUrl,
|
||||
baseUrl,
|
||||
)));
|
||||
final _result = await _dio.fetch<Map<String, dynamic>>(_options);
|
||||
late ApiResult<List<TokenWithoutToken>> _value;
|
||||
try {
|
||||
_value = ApiResult<List<TokenWithoutToken>>.fromJson(
|
||||
_result.data!,
|
||||
(json) => json is List<dynamic>
|
||||
? json
|
||||
.map<TokenWithoutToken>((i) =>
|
||||
TokenWithoutToken.fromJson(i as Map<String, dynamic>))
|
||||
.toList()
|
||||
: List.empty(),
|
||||
);
|
||||
} on Object catch (e, s) {
|
||||
errorLogger?.logError(e, s, _options);
|
||||
rethrow;
|
||||
}
|
||||
return _value;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ApiResult<SharedToken>> getSharedToken({CancelToken? cancel}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
|
||||
@@ -40,6 +40,42 @@ class Token {
|
||||
Map<String, dynamic> toJson() => _$TokenToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class TokenWithoutToken {
|
||||
const TokenWithoutToken({
|
||||
required this.id,
|
||||
required this.uid,
|
||||
required this.expired,
|
||||
required this.httpOnly,
|
||||
required this.secure,
|
||||
required this.lastUsed,
|
||||
this.client,
|
||||
this.device,
|
||||
this.clientVersion,
|
||||
this.clientPlatform,
|
||||
});
|
||||
final int id;
|
||||
final int uid;
|
||||
@JsonKey(fromJson: _fromJson, toJson: _toJson)
|
||||
final DateTime expired;
|
||||
@JsonKey(name: 'http_only')
|
||||
final bool httpOnly;
|
||||
final bool secure;
|
||||
@JsonKey(fromJson: _fromJson, toJson: _toJson, name: 'last_used')
|
||||
final DateTime lastUsed;
|
||||
final String? client;
|
||||
final String? device;
|
||||
@JsonKey(name: 'client_version')
|
||||
final String? clientVersion;
|
||||
@JsonKey(name: 'client_platform')
|
||||
final String? clientPlatform;
|
||||
static DateTime _fromJson(String d) => DateTime.parse(d);
|
||||
static String _toJson(DateTime d) => d.toIso8601String();
|
||||
factory TokenWithoutToken.fromJson(Map<String, dynamic> json) =>
|
||||
_$TokenWithoutTokenFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$TokenWithoutTokenToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class TokenWithUserInfo {
|
||||
const TokenWithUserInfo({
|
||||
|
||||
@@ -34,6 +34,34 @@ Map<String, dynamic> _$TokenToJson(Token instance) => <String, dynamic>{
|
||||
'client_platform': instance.clientPlatform,
|
||||
};
|
||||
|
||||
TokenWithoutToken _$TokenWithoutTokenFromJson(Map<String, dynamic> json) =>
|
||||
TokenWithoutToken(
|
||||
id: (json['id'] as num).toInt(),
|
||||
uid: (json['uid'] as num).toInt(),
|
||||
expired: TokenWithoutToken._fromJson(json['expired'] as String),
|
||||
httpOnly: json['http_only'] as bool,
|
||||
secure: json['secure'] as bool,
|
||||
lastUsed: TokenWithoutToken._fromJson(json['last_used'] as String),
|
||||
client: json['client'] as String?,
|
||||
device: json['device'] as String?,
|
||||
clientVersion: json['client_version'] as String?,
|
||||
clientPlatform: json['client_platform'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$TokenWithoutTokenToJson(TokenWithoutToken instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'uid': instance.uid,
|
||||
'expired': TokenWithoutToken._toJson(instance.expired),
|
||||
'http_only': instance.httpOnly,
|
||||
'secure': instance.secure,
|
||||
'last_used': TokenWithoutToken._toJson(instance.lastUsed),
|
||||
'client': instance.client,
|
||||
'device': instance.device,
|
||||
'client_version': instance.clientVersion,
|
||||
'client_platform': instance.clientPlatform,
|
||||
};
|
||||
|
||||
TokenWithUserInfo _$TokenWithUserInfoFromJson(Map<String, dynamic> json) =>
|
||||
TokenWithUserInfo(
|
||||
token: Token.fromJson(json['token'] as Map<String, dynamic>),
|
||||
|
||||
Reference in New Issue
Block a user