mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
add login log
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
import 'dart:ffi';
|
||||
|
||||
import 'package:qinglong_app/base/http/http.dart';
|
||||
import 'package:qinglong_app/module/config/config_bean.dart';
|
||||
import 'package:qinglong_app/module/env/env_bean.dart';
|
||||
import 'package:qinglong_app/module/login/login_bean.dart';
|
||||
import 'package:qinglong_app/module/others/dependencies/dependency_bean.dart';
|
||||
import 'package:qinglong_app/module/others/login_log/login_log_bean.dart';
|
||||
import 'package:qinglong_app/module/others/scripts/script_bean.dart';
|
||||
import 'package:qinglong_app/module/others/task_log/task_log_bean.dart';
|
||||
import 'package:qinglong_app/module/task/task_bean.dart';
|
||||
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,
|
||||
{
|
||||
@@ -22,104 +23,240 @@ 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.runTasks, 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.runTasks, 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.intimeLog(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.taskDetail + 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.addTask, data);
|
||||
return await Http.put<TaskDetailBean>(
|
||||
Url.addTask,
|
||||
data,
|
||||
);
|
||||
}
|
||||
return await Http.post<TaskDetailBean>(Url.addTask, data);
|
||||
return await Http.post<TaskDetailBean>(
|
||||
Url.addTask,
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> delTask(String cron) async {
|
||||
return await Http.delete<NullResponse>(Url.addTask, [cron]);
|
||||
return await Http.delete<NullResponse>(
|
||||
Url.addTask,
|
||||
[cron],
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> pinTask(String cron) async {
|
||||
return await Http.put<NullResponse>(Url.pinTask, [cron]);
|
||||
return await Http.put<NullResponse>(
|
||||
Url.pinTask,
|
||||
[cron],
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> unpinTask(String cron) async {
|
||||
return await Http.put<NullResponse>(Url.unpinTask, [cron]);
|
||||
return await Http.put<NullResponse>(
|
||||
Url.unpinTask,
|
||||
[cron],
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> enableTask(String cron) async {
|
||||
return await Http.put<NullResponse>(Url.enableTask, [cron]);
|
||||
return await Http.put<NullResponse>(
|
||||
Url.enableTask,
|
||||
[cron],
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> disableTask(String cron) async {
|
||||
return await Http.put<NullResponse>(Url.disableTask, [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.configContent + name, null);
|
||||
return await Http.get<String>(
|
||||
Url.configContent + name,
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> saveFile(
|
||||
String name, String content) async {
|
||||
static Future<HttpResponse<NullResponse>> saveFile(String name, String content) async {
|
||||
return await Http.post<NullResponse>(
|
||||
Url.saveFile, {"content": content, "name": name});
|
||||
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.enableEnvs, [id]);
|
||||
return await Http.put<NullResponse>(
|
||||
Url.enableEnvs,
|
||||
[id],
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> disableEnv(String id) async {
|
||||
return await Http.put<NullResponse>(Url.disableEnvs, [id]);
|
||||
return await Http.put<NullResponse>(
|
||||
Url.disableEnvs,
|
||||
[id],
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> delEnv(String id) async {
|
||||
return await Http.delete<NullResponse>(Url.delEnv, [id]);
|
||||
return await Http.delete<NullResponse>(
|
||||
Url.delEnv,
|
||||
[id],
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> addEnv(
|
||||
String name, String value, String remarks,
|
||||
{String? id}) async {
|
||||
var data = {"value": value, "remarks": remarks, "name": name};
|
||||
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.addEnv, data);
|
||||
return await Http.put<NullResponse>(
|
||||
Url.addEnv,
|
||||
data,
|
||||
);
|
||||
}
|
||||
return await Http.post<NullResponse>(Url.addEnv, [data]);
|
||||
return await Http.post<NullResponse>(
|
||||
Url.addEnv,
|
||||
[data],
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> moveEnv(
|
||||
String id, int fromIndex, int toIndex) async {
|
||||
static Future<HttpResponse<NullResponse>> moveEnv(String id, int fromIndex, int toIndex) async {
|
||||
return await Http.put<NullResponse>(
|
||||
Url.envMove(id), {"fromIndex": fromIndex, "toIndex": toIndex});
|
||||
Url.envMove(id),
|
||||
{"fromIndex": fromIndex, "toIndex": toIndex},
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<List<LoginLogBean>>> loginLog() async {
|
||||
return await Http.get<List<LoginLogBean>>(
|
||||
Url.loginLog,
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<List<TaskLogBean>>> taskLog() async {
|
||||
return await Http.get<List<TaskLogBean>>(Url.taskLog, null, serializationName: "dirs");
|
||||
}
|
||||
|
||||
static Future<HttpResponse<String>> taskLogDetail(String name) async {
|
||||
return await Http.get<String>(
|
||||
Url.taskLogDetail + name,
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<List<ScriptBean>>> scripts() async {
|
||||
return await Http.get<List<ScriptBean>>(
|
||||
Url.scripts,
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<String>> scriptDetail(String name, String path) async {
|
||||
return await Http.get<String>(
|
||||
Url.scriptDetail + name,
|
||||
{
|
||||
"path": path,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<List<DependencyBean>>> dependencies(String type) async {
|
||||
return await Http.get<List<DependencyBean>>(
|
||||
Url.dependencies,
|
||||
{
|
||||
"type": type,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> dependencyReinstall(String id) async {
|
||||
return await Http.put<NullResponse>(
|
||||
Url.dependencies,
|
||||
[id],
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<String>> dependencyLog(String id) async {
|
||||
return await Http.get<String>(
|
||||
Url.dependencies + "/" + id,
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> addDependency(String name, int type) async {
|
||||
return await Http.post<NullResponse>(
|
||||
Url.dependencies,
|
||||
[
|
||||
{
|
||||
"name": name,
|
||||
"type": type,
|
||||
}
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> delDependency(String id) async {
|
||||
return await Http.delete<NullResponse>(
|
||||
Url.dependencies,
|
||||
[id],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,74 +38,90 @@ 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,
|
||||
String serializationName = "data",
|
||||
}) async {
|
||||
try {
|
||||
_init();
|
||||
var response = await _dio!.get(uri, queryParameters: json);
|
||||
|
||||
return decodeResponse<T>(response, compute);
|
||||
return decodeResponse<T>(response, serializationName, compute);
|
||||
} on DioError catch (e) {
|
||||
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,
|
||||
String serializationName = "data",
|
||||
}) async {
|
||||
try {
|
||||
_init();
|
||||
var response = await _dio!.post(uri, data: json);
|
||||
|
||||
return decodeResponse<T>(response, compute);
|
||||
return decodeResponse<T>(
|
||||
response,
|
||||
serializationName,
|
||||
compute,
|
||||
);
|
||||
} on DioError catch (e) {
|
||||
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,
|
||||
String serializationName = "data",
|
||||
}) async {
|
||||
try {
|
||||
_init();
|
||||
var response = await _dio!.delete(uri, data: json);
|
||||
|
||||
return decodeResponse<T>(response, compute);
|
||||
return decodeResponse<T>(
|
||||
response,
|
||||
serializationName,
|
||||
compute,
|
||||
);
|
||||
} on DioError catch (e) {
|
||||
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,
|
||||
String serializationName = "data",
|
||||
}) async {
|
||||
try {
|
||||
_init();
|
||||
var response = await _dio!.put(uri, data: json);
|
||||
return decodeResponse<T>(response, compute);
|
||||
return decodeResponse<T>(
|
||||
response,
|
||||
serializationName,
|
||||
compute,
|
||||
);
|
||||
} on DioError catch (e) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,13 +136,14 @@ class Http {
|
||||
|
||||
static HttpResponse<T> decodeResponse<T>(
|
||||
Response<dynamic> response,
|
||||
String serializationName,
|
||||
bool compute,
|
||||
) {
|
||||
int code = 0;
|
||||
if (response.statusCode == 200) {
|
||||
try {
|
||||
if (response.data["code"] == 200) {
|
||||
if (response.data["data"] != null) {
|
||||
if (response.data[serializationName] != null) {
|
||||
if (T == NullResponse) {
|
||||
return HttpResponse<T>(
|
||||
success: true,
|
||||
@@ -134,7 +151,7 @@ class Http {
|
||||
);
|
||||
}
|
||||
|
||||
dynamic data = response.data["data"];
|
||||
dynamic data = response.data[serializationName];
|
||||
T t;
|
||||
if (T == String) {
|
||||
if (data is String) {
|
||||
@@ -198,8 +215,7 @@ 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> {
|
||||
|
||||
@@ -17,6 +17,13 @@ class Url {
|
||||
static const delEnv = "/api/envs";
|
||||
static const disableEnvs = "/api/envs/disable";
|
||||
static const enableEnvs = "/api/envs/enable";
|
||||
static const loginLog = "/api/user/login-log";
|
||||
static const taskLog = "/api/logs";
|
||||
static const taskLogDetail = "/api/logs/code/";
|
||||
static const scripts = "/api/scripts/files";
|
||||
static const scriptDetail = "/api/scripts/";
|
||||
static const dependencies = "/api/dependencies";
|
||||
static const dependencyReinstall = "/api/dependencies/reinstall";
|
||||
|
||||
static intimeLog(String cronId) {
|
||||
return "/api/crons/$cronId/log";
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:qinglong_app/module/env/add_env_page.dart';
|
||||
import 'package:qinglong_app/module/env/env_bean.dart';
|
||||
import 'package:qinglong_app/module/home/home_page.dart';
|
||||
import 'package:qinglong_app/module/login/login_page.dart';
|
||||
import 'package:qinglong_app/module/others/login_log/login_log_page.dart';
|
||||
import 'package:qinglong_app/module/task/add_task_page.dart';
|
||||
import 'package:qinglong_app/module/task/task_bean.dart';
|
||||
|
||||
@@ -14,6 +15,7 @@ class Routes {
|
||||
static const String routeAddTask = "/task/add";
|
||||
static const String routeAddEnv = "/env/add";
|
||||
static const String routeConfigEdit = "/config/edit";
|
||||
static const String routeLoginLog = "/log/login";
|
||||
|
||||
static Route<dynamic>? generateRoute(RouteSettings settings) {
|
||||
switch (settings.name) {
|
||||
@@ -46,6 +48,10 @@ class Routes {
|
||||
(settings.arguments as Map)["content"],
|
||||
),
|
||||
);
|
||||
case routeLoginLog:
|
||||
return CupertinoPageRoute(
|
||||
builder: (context) => const LoginLogPage(),
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -9,6 +9,8 @@ import 'package:qinglong_app/utils/sp_utils.dart';
|
||||
var themeProvider = ChangeNotifierProvider((ref) => ThemeViewModel());
|
||||
const Color _primaryColor = Color(0xFF299343);
|
||||
|
||||
get primaryColor => _primaryColor;
|
||||
|
||||
class ThemeViewModel extends ChangeNotifier {
|
||||
ThemeData currentTheme = lightTheme;
|
||||
|
||||
@@ -221,7 +223,7 @@ class DartThemeColors extends ThemeColors {
|
||||
|
||||
@override
|
||||
Color settingBgColor() {
|
||||
return Colors.black;
|
||||
return Colors.black12;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user