mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
format code
This commit is contained in:
@@ -10,9 +10,10 @@ import 'package:qinglong_app/module/task/task_detail/task_detail_bean.dart';
|
||||
import 'url.dart';
|
||||
|
||||
class Api {
|
||||
static Future<HttpResponse<LoginBean>> login(String userName, String passWord) async {
|
||||
static Future<HttpResponse<LoginBean>> login(
|
||||
String userName, String passWord) async {
|
||||
return await Http.post<LoginBean>(
|
||||
Url.LOGIN,
|
||||
Url.login,
|
||||
{
|
||||
"username": userName,
|
||||
"password": passWord,
|
||||
@@ -21,90 +22,104 @@ class Api {
|
||||
}
|
||||
|
||||
static Future<HttpResponse<List<TaskBean>>> crons() async {
|
||||
return await Http.get<List<TaskBean>>(Url.TASKS, {"searchValue": ""});
|
||||
return await Http.get<List<TaskBean>>(Url.tasks, {"searchValue": ""});
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> startTasks(List<String> crons) async {
|
||||
return await Http.put<NullResponse>(Url.RUN_TASKS, crons);
|
||||
static Future<HttpResponse<NullResponse>> startTasks(
|
||||
List<String> crons) async {
|
||||
return await Http.put<NullResponse>(Url.runTasks, crons);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> stopTasks(List<String> crons) async {
|
||||
return await Http.put<NullResponse>(Url.RUN_TASKS, crons);
|
||||
static Future<HttpResponse<NullResponse>> stopTasks(
|
||||
List<String> crons) async {
|
||||
return await Http.put<NullResponse>(Url.runTasks, crons);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<String>> inTimeLog(String cron) async {
|
||||
return await Http.get<String>(Url.INTIME_LOG(cron), null);
|
||||
return await Http.get<String>(Url.intimeLog(cron), null);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<TaskDetailBean>> taskDetail(String cron) async {
|
||||
return await Http.get<TaskDetailBean>(Url.TASK_DETAIL + cron, null);
|
||||
return await Http.get<TaskDetailBean>(Url.taskDetail + cron, null);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<TaskDetailBean>> addTask(String name, String command, String cron, {String? id}) async {
|
||||
static Future<HttpResponse<TaskDetailBean>> addTask(
|
||||
String name, String command, String cron,
|
||||
{String? id}) async {
|
||||
var data = {"name": name, "command": command, "schedule": cron};
|
||||
|
||||
if (id != null) {
|
||||
data["_id"] = id;
|
||||
return await Http.put<TaskDetailBean>(Url.ADD_TASK, data);
|
||||
return await Http.put<TaskDetailBean>(Url.addTask, data);
|
||||
}
|
||||
return await Http.post<TaskDetailBean>(Url.ADD_TASK, data);
|
||||
return await Http.post<TaskDetailBean>(Url.addTask, data);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> delTask(String cron) async {
|
||||
return await Http.delete<NullResponse>(Url.ADD_TASK, [cron]);
|
||||
return await Http.delete<NullResponse>(Url.addTask, [cron]);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> pinTask(String cron) async {
|
||||
return await Http.put<NullResponse>(Url.PIN_TASK, [cron]);
|
||||
return await Http.put<NullResponse>(Url.pinTask, [cron]);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> unpinTask(String cron) async {
|
||||
return await Http.put<NullResponse>(Url.UNPIN_TASK, [cron]);
|
||||
return await Http.put<NullResponse>(Url.unpinTask, [cron]);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> enableTask(String cron) async {
|
||||
return await Http.put<NullResponse>(Url.ENABLE_TASK, [cron]);
|
||||
return await Http.put<NullResponse>(Url.enableTask, [cron]);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> disableTask(String cron) async {
|
||||
return await Http.put<NullResponse>(Url.DISABLE_TASK, [cron]);
|
||||
return await Http.put<NullResponse>(Url.disableTask, [cron]);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<List<ConfigBean>>> files() async {
|
||||
return await Http.get<List<ConfigBean>>(Url.FILES, null);
|
||||
return await Http.get<List<ConfigBean>>(Url.files, null);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<String>> content(String name) async {
|
||||
return await Http.get<String>(Url.CONFIG_CONTENT + name, null);
|
||||
return await Http.get<String>(Url.configContent + name, null);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> saveFile(String name, String content) async {
|
||||
return await Http.post<NullResponse>(Url.SAVE_FILE, {"content": content, "name": name});
|
||||
static Future<HttpResponse<NullResponse>> saveFile(
|
||||
String name, String content) async {
|
||||
return await Http.post<NullResponse>(
|
||||
Url.saveFile, {"content": content, "name": name});
|
||||
}
|
||||
|
||||
static Future<HttpResponse<List<EnvBean>>> envs(String search) async {
|
||||
return await Http.get<List<EnvBean>>(Url.ENVS, {"searchValue": search});
|
||||
return await Http.get<List<EnvBean>>(Url.envs, {"searchValue": search});
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> enableEnv(String id) async {
|
||||
return await Http.put<NullResponse>(Url.ENABLE_ENVS, [id]);
|
||||
return await Http.put<NullResponse>(Url.enableEnvs, [id]);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> disableEnv(String id) async {
|
||||
return await Http.put<NullResponse>(Url.DISABLE_ENVS, [id]);
|
||||
return await Http.put<NullResponse>(Url.disableEnvs, [id]);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> delEnv(String id) async {
|
||||
return await Http.delete<NullResponse>(Url.DEL_ENV, [id]);
|
||||
return await Http.delete<NullResponse>(Url.delEnv, [id]);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> addEnv(String name, String value, String remarks, {String? id}) async {
|
||||
static Future<HttpResponse<NullResponse>> addEnv(
|
||||
String name, String value, String remarks,
|
||||
{String? id}) async {
|
||||
var data = {"value": value, "remarks": remarks, "name": name};
|
||||
|
||||
if (id != null) {
|
||||
data["_id"] = id;
|
||||
return await Http.put<NullResponse>(Url.ADD_ENV, data);
|
||||
return await Http.put<NullResponse>(Url.addEnv, data);
|
||||
}
|
||||
return await Http.post<NullResponse>(Url.ADD_ENV, [data]);
|
||||
return await Http.post<NullResponse>(Url.addEnv, [data]);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> moveEnv(
|
||||
String id, int fromIndex, int toIndex) async {
|
||||
return await Http.put<NullResponse>(
|
||||
Url.envMove(id), {"fromIndex": fromIndex, "toIndex": toIndex});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,8 @@ class Http {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<HttpResponse<T>> get<T>(String uri, Map<String, String>? json, {bool compute = true}) async {
|
||||
static Future<HttpResponse<T>> get<T>(String uri, Map<String, String>? json,
|
||||
{bool compute = true}) async {
|
||||
try {
|
||||
_init();
|
||||
var response = await _dio!.get(uri, queryParameters: json);
|
||||
@@ -48,11 +49,15 @@ class Http {
|
||||
if (e.response?.statusCode == 401) {
|
||||
exitLogin();
|
||||
}
|
||||
return HttpResponse(success: false, message: e.response?.statusMessage ?? e.message, code: 0);
|
||||
return HttpResponse(
|
||||
success: false,
|
||||
message: e.response?.statusMessage ?? e.message,
|
||||
code: 0);
|
||||
}
|
||||
}
|
||||
|
||||
static Future<HttpResponse<T>> post<T>(String uri, dynamic json, {bool compute = true}) async {
|
||||
static Future<HttpResponse<T>> post<T>(String uri, dynamic json,
|
||||
{bool compute = true}) async {
|
||||
try {
|
||||
_init();
|
||||
var response = await _dio!.post(uri, data: json);
|
||||
@@ -62,11 +67,15 @@ class Http {
|
||||
if (e.response?.statusCode == 401) {
|
||||
exitLogin();
|
||||
}
|
||||
return HttpResponse(success: false, message: e.response?.statusMessage ?? e.message, code: 0);
|
||||
return HttpResponse(
|
||||
success: false,
|
||||
message: e.response?.statusMessage ?? e.message,
|
||||
code: 0);
|
||||
}
|
||||
}
|
||||
|
||||
static Future<HttpResponse<T>> delete<T>(String uri, dynamic json, {bool compute = true}) async {
|
||||
static Future<HttpResponse<T>> delete<T>(String uri, dynamic json,
|
||||
{bool compute = true}) async {
|
||||
try {
|
||||
_init();
|
||||
var response = await _dio!.delete(uri, data: json);
|
||||
@@ -76,11 +85,15 @@ class Http {
|
||||
if (e.response?.statusCode == 401) {
|
||||
exitLogin();
|
||||
}
|
||||
return HttpResponse(success: false, message: e.response?.statusMessage ?? e.message, code: 0);
|
||||
return HttpResponse(
|
||||
success: false,
|
||||
message: e.response?.statusMessage ?? e.message,
|
||||
code: 0);
|
||||
}
|
||||
}
|
||||
|
||||
static Future<HttpResponse<T>> put<T>(String uri, dynamic json, {bool compute = true}) async {
|
||||
static Future<HttpResponse<T>> put<T>(String uri, dynamic json,
|
||||
{bool compute = true}) async {
|
||||
try {
|
||||
_init();
|
||||
var response = await _dio!.put(uri, data: json);
|
||||
@@ -89,7 +102,10 @@ class Http {
|
||||
if (e.response?.statusCode == 401) {
|
||||
exitLogin();
|
||||
}
|
||||
return HttpResponse(success: false, message: e.response?.statusMessage ?? e.message, code: 0);
|
||||
return HttpResponse(
|
||||
success: false,
|
||||
message: e.response?.statusMessage ?? e.message,
|
||||
code: 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +114,7 @@ class Http {
|
||||
static void exitLogin() {
|
||||
if (!pushedLoginPage) {
|
||||
pushedLoginPage = true;
|
||||
navigatorState.currentState?.pushReplacementNamed(Routes.route_LOGIN);
|
||||
navigatorState.currentState?.pushReplacementNamed(Routes.routeLogin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,7 +198,8 @@ class HttpResponse<T> {
|
||||
late int code;
|
||||
T? bean;
|
||||
|
||||
HttpResponse({required this.success, this.message, required this.code, this.bean});
|
||||
HttpResponse(
|
||||
{required this.success, this.message, required this.code, this.bean});
|
||||
}
|
||||
|
||||
class DeserializeAction<T> {
|
||||
|
||||
@@ -6,13 +6,17 @@ import '../userinfo_viewmodel.dart';
|
||||
class TokenInterceptor extends Interceptor {
|
||||
@override
|
||||
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
|
||||
if (getIt<UserInfoViewModel>().token != null && getIt<UserInfoViewModel>().token!.isNotEmpty) {
|
||||
options.headers["Authorization"] = "Bearer " + getIt<UserInfoViewModel>().token!;
|
||||
if (getIt<UserInfoViewModel>().token != null &&
|
||||
getIt<UserInfoViewModel>().token!.isNotEmpty) {
|
||||
options.headers["Authorization"] =
|
||||
"Bearer " + getIt<UserInfoViewModel>().token!;
|
||||
}
|
||||
|
||||
options.headers["User-Agent"] = "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1";
|
||||
options.headers["User-Agent"] =
|
||||
"Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1";
|
||||
options.headers["Content-Type"] = "application/json;charset=UTF-8";
|
||||
options.queryParameters["t"] = (DateTime.now().millisecondsSinceEpoch~/1000).toString();
|
||||
options.queryParameters["t"] =
|
||||
(DateTime.now().millisecondsSinceEpoch ~/ 1000).toString();
|
||||
return handler.next(options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,28 @@
|
||||
class Url {
|
||||
static const LOGIN = "/api/user/login";
|
||||
static const TASKS = "/api/crons";
|
||||
static const RUN_TASKS = "/api/crons/run";
|
||||
static const STOP_TASKS = "/api/crons/stop";
|
||||
static const TASK_DETAIL = "/api/crons/";
|
||||
static const ADD_TASK = "/api/crons";
|
||||
static const PIN_TASK = "/api/crons/pin";
|
||||
static const UNPIN_TASK = "/api/crons/unpin";
|
||||
static const ENABLE_TASK = "/api/crons/enable";
|
||||
static const DISABLE_TASK = "/api/crons/disable";
|
||||
static const FILES = "/api/configs/files";
|
||||
static const CONFIG_CONTENT = "/api/configs/";
|
||||
static const SAVE_FILE = "/api/configs/save";
|
||||
static const ENVS = "/api/envs";
|
||||
static const ADD_ENV = "/api/envs";
|
||||
static const DEL_ENV = "/api/envs";
|
||||
static const DISABLE_ENVS = "/api/envs/disable";
|
||||
static const ENABLE_ENVS = "/api/envs/enable";
|
||||
static const login = "/api/user/login";
|
||||
static const tasks = "/api/crons";
|
||||
static const runTasks = "/api/crons/run";
|
||||
static const stopTasks = "/api/crons/stop";
|
||||
static const taskDetail = "/api/crons/";
|
||||
static const addTask = "/api/crons";
|
||||
static const pinTask = "/api/crons/pin";
|
||||
static const unpinTask = "/api/crons/unpin";
|
||||
static const enableTask = "/api/crons/enable";
|
||||
static const disableTask = "/api/crons/disable";
|
||||
static const files = "/api/configs/files";
|
||||
static const configContent = "/api/configs/";
|
||||
static const saveFile = "/api/configs/save";
|
||||
static const envs = "/api/envs";
|
||||
static const addEnv = "/api/envs";
|
||||
static const delEnv = "/api/envs";
|
||||
static const disableEnvs = "/api/envs/disable";
|
||||
static const enableEnvs = "/api/envs/enable";
|
||||
|
||||
static INTIME_LOG(String cronId) {
|
||||
static intimeLog(String cronId) {
|
||||
return "/api/crons/$cronId/log";
|
||||
}
|
||||
|
||||
static envMove(String envId) {
|
||||
return "/api/envs/$envId/move";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user