mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
add others
This commit is contained in:
@@ -6,9 +6,11 @@ import 'package:dio_log/dio_log.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:qinglong_app/base/http/token_interceptor.dart';
|
||||
import 'package:qinglong_app/base/userinfo_viewmodel.dart';
|
||||
import 'package:qinglong_app/utils/QlNavigatorObserver.dart';
|
||||
|
||||
import '../../json.jc.dart';
|
||||
import '../../main.dart';
|
||||
import '../routes.dart';
|
||||
|
||||
class Http {
|
||||
static const int NOT_LOGIN = 1000;
|
||||
@@ -43,6 +45,9 @@ class Http {
|
||||
|
||||
return decodeResponse<T>(response, compute);
|
||||
} on DioError catch (e) {
|
||||
if (e.response?.statusCode == 401) {
|
||||
exitLogin();
|
||||
}
|
||||
return HttpResponse(success: false, message: e.message, code: 0);
|
||||
}
|
||||
}
|
||||
@@ -54,6 +59,9 @@ class Http {
|
||||
|
||||
return decodeResponse<T>(response, compute);
|
||||
} on DioError catch (e) {
|
||||
if (e.response?.statusCode == 401) {
|
||||
exitLogin();
|
||||
}
|
||||
return HttpResponse(success: false, message: e.message, code: 0);
|
||||
}
|
||||
}
|
||||
@@ -65,6 +73,9 @@ class Http {
|
||||
|
||||
return decodeResponse<T>(response, compute);
|
||||
} on DioError catch (e) {
|
||||
if (e.response?.statusCode == 401) {
|
||||
exitLogin();
|
||||
}
|
||||
return HttpResponse(success: false, message: e.message, code: 0);
|
||||
}
|
||||
}
|
||||
@@ -75,16 +86,27 @@ class Http {
|
||||
var response = await _dio!.put(uri, data: json);
|
||||
return decodeResponse<T>(response, compute);
|
||||
} on DioError catch (e) {
|
||||
if (e.response?.statusCode == 401) {
|
||||
exitLogin();
|
||||
}
|
||||
return HttpResponse(success: false, message: e.message, code: 0);
|
||||
}
|
||||
}
|
||||
|
||||
static bool pushedLoginPage = false;
|
||||
|
||||
static void exitLogin() {
|
||||
if (!pushedLoginPage) {
|
||||
pushedLoginPage = true;
|
||||
navigatorState.currentState?.pushReplacementNamed(Routes.route_LOGIN);
|
||||
}
|
||||
}
|
||||
|
||||
static HttpResponse<T> decodeResponse<T>(
|
||||
Response<dynamic> response,
|
||||
bool compute,
|
||||
) {
|
||||
int code = 0;
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
try {
|
||||
if (response.data["code"] == 200) {
|
||||
@@ -191,3 +213,5 @@ void decode<T>() async {
|
||||
}
|
||||
|
||||
class NullResponse {}
|
||||
|
||||
class NotLoginException implements Exception {}
|
||||
|
||||
@@ -6,7 +6,7 @@ import '../userinfo_viewmodel.dart';
|
||||
class TokenInterceptor extends Interceptor {
|
||||
@override
|
||||
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
|
||||
if (getIt<UserInfoViewModel>().token != null) {
|
||||
if (getIt<UserInfoViewModel>().token != null && getIt<UserInfoViewModel>().token!.isNotEmpty) {
|
||||
options.headers["Authorization"] = "Bearer " + getIt<UserInfoViewModel>().token!;
|
||||
}
|
||||
options.queryParameters["t"] = (DateTime.now().millisecondsSinceEpoch~/1000).toString();
|
||||
|
||||
@@ -15,8 +15,8 @@ class Url {
|
||||
static const ENVS = "/api/envs";
|
||||
static const ADD_ENV = "/api/envs";
|
||||
static const DEL_ENV = "/api/envs";
|
||||
static const DISABLE_ENVS = "/api/disable";
|
||||
static const ENABLE_ENVS = "/api/enable";
|
||||
static const DISABLE_ENVS = "/api/envs/disable";
|
||||
static const ENABLE_ENVS = "/api/envs/enable";
|
||||
|
||||
static INTIME_LOG(String cronId) {
|
||||
return "/api/crons/$cronId/log";
|
||||
|
||||
Reference in New Issue
Block a user