fix(redis): 修复 Redis 流读取兼容性问题
- 支持 bytes 和 str 类型的 entry_id - 支持 list 类型响应格式 - 优化 payload 解码处理
This commit is contained in:
@@ -38,6 +38,10 @@ class ApiClient implements IApiClient {
|
||||
|
||||
Dio get dio => _dio;
|
||||
|
||||
void resetInterceptor() {
|
||||
_interceptor.reset();
|
||||
}
|
||||
|
||||
void setRefreshCallback(Future<bool> Function(String) refresh) {
|
||||
_interceptor.onTokenRefresh = () async {
|
||||
final token = await _tokenStorage.getRefreshToken();
|
||||
@@ -102,10 +106,7 @@ class ApiClient implements IApiClient {
|
||||
try {
|
||||
final response = await _dio.get<ResponseBody>(
|
||||
path,
|
||||
options: Options(
|
||||
responseType: ResponseType.stream,
|
||||
headers: headers,
|
||||
),
|
||||
options: Options(responseType: ResponseType.stream, headers: headers),
|
||||
);
|
||||
final responseBody = response.data;
|
||||
if (responseBody == null) {
|
||||
|
||||
@@ -98,4 +98,9 @@ class ApiInterceptor extends Interceptor {
|
||||
return refreshed;
|
||||
});
|
||||
}
|
||||
|
||||
void reset() {
|
||||
_refreshFuture = null;
|
||||
_refreshBlockedUntil = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +72,11 @@ Future<void> configureDependencies() async {
|
||||
final authRepository = AuthRepositoryImpl(
|
||||
api: authApi,
|
||||
tokenStorage: tokenStorage,
|
||||
onLogout: Env.isMockApi
|
||||
? null
|
||||
: () async {
|
||||
(apiClient as ApiClient).resetInterceptor();
|
||||
},
|
||||
);
|
||||
sl.registerSingleton<AuthRepository>(authRepository);
|
||||
|
||||
|
||||
@@ -8,10 +8,15 @@ import 'models/auth_response.dart';
|
||||
class AuthRepositoryImpl implements AuthRepository {
|
||||
final AuthApi _api;
|
||||
final TokenStorage _tokenStorage;
|
||||
final Future<void> Function()? _onLogout;
|
||||
|
||||
AuthRepositoryImpl({required AuthApi api, required TokenStorage tokenStorage})
|
||||
: _api = api,
|
||||
_tokenStorage = tokenStorage;
|
||||
AuthRepositoryImpl({
|
||||
required AuthApi api,
|
||||
required TokenStorage tokenStorage,
|
||||
Future<void> Function()? onLogout,
|
||||
}) : _api = api,
|
||||
_tokenStorage = tokenStorage,
|
||||
_onLogout = onLogout;
|
||||
|
||||
@override
|
||||
Future<VerificationCreateResponse> createVerification(
|
||||
@@ -59,9 +64,16 @@ class AuthRepositoryImpl implements AuthRepository {
|
||||
|
||||
@override
|
||||
Future<void> deleteSession() async {
|
||||
if (_onLogout != null) {
|
||||
await _onLogout!();
|
||||
}
|
||||
final refreshToken = await _tokenStorage.getRefreshToken();
|
||||
if (refreshToken != null) {
|
||||
await _api.deleteSession(LogoutRequest(refreshToken: refreshToken));
|
||||
try {
|
||||
await _api.deleteSession(LogoutRequest(refreshToken: refreshToken));
|
||||
} catch (_) {
|
||||
// ignore API errors during logout
|
||||
}
|
||||
}
|
||||
await _tokenStorage.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user