mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
支持上传脚本
This commit is contained in:
@@ -89,21 +89,24 @@ class Api {
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> startTasks(List<String> crons) async {
|
||||
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 {
|
||||
static Future<HttpResponse<NullResponse>> stopTasks(
|
||||
List<String> crons) async {
|
||||
return await Http.put<NullResponse>(
|
||||
Url.stopTasks,
|
||||
crons,
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> updatePassword(String name, String password) async {
|
||||
static Future<HttpResponse<NullResponse>> updatePassword(
|
||||
String name, String password) async {
|
||||
return await Http.put<NullResponse>(
|
||||
Url.updatePassword,
|
||||
{
|
||||
@@ -127,7 +130,11 @@ class Api {
|
||||
int? id,
|
||||
String? nId,
|
||||
}) async {
|
||||
var data = <String, dynamic>{"name": name, "command": command, "schedule": cron};
|
||||
var data = <String, dynamic>{
|
||||
"name": name,
|
||||
"command": command,
|
||||
"schedule": cron
|
||||
};
|
||||
|
||||
if (id != null || nId != null) {
|
||||
if (id != null) {
|
||||
@@ -195,7 +202,8 @@ class Api {
|
||||
);
|
||||
}
|
||||
|
||||
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},
|
||||
@@ -260,7 +268,8 @@ class Api {
|
||||
);
|
||||
}
|
||||
|
||||
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},
|
||||
@@ -275,10 +284,12 @@ class Api {
|
||||
}
|
||||
|
||||
static Future<HttpResponse<List<TaskLogBean>>> taskLog() async {
|
||||
return await Http.get<List<TaskLogBean>>(Url.taskLog, null, serializationName: Utils.isUpperVersion2_12_2() ? "data" : "dirs");
|
||||
return await Http.get<List<TaskLogBean>>(Url.taskLog, null,
|
||||
serializationName: Utils.isUpperVersion2_12_2() ? "data" : "dirs");
|
||||
}
|
||||
|
||||
static Future<HttpResponse<String>> taskLogDetail(String name, String path) async {
|
||||
static Future<HttpResponse<String>> taskLogDetail(
|
||||
String name, String path) async {
|
||||
if (Utils.isUpperVersion2_13_0()) {
|
||||
return await Http.get<String>(
|
||||
Url.taskLogDetail + name + "?path=" + path,
|
||||
@@ -300,7 +311,8 @@ class Api {
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> updateScript(String name, String path, String content) async {
|
||||
static Future<HttpResponse<NullResponse>> updateScript(
|
||||
String name, String path, String content) async {
|
||||
return await Http.put<NullResponse>(
|
||||
Url.scriptDetail,
|
||||
{
|
||||
@@ -311,7 +323,8 @@ class Api {
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> delScript(String name, String path) async {
|
||||
static Future<HttpResponse<NullResponse>> delScript(
|
||||
String name, String path) async {
|
||||
return await Http.delete<NullResponse>(
|
||||
Url.scriptDetail,
|
||||
{
|
||||
@@ -321,7 +334,8 @@ class Api {
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<String>> scriptDetail(String name, String? path) async {
|
||||
static Future<HttpResponse<String>> scriptDetail(
|
||||
String name, String? path) async {
|
||||
return await Http.get<String>(
|
||||
Url.scriptDetail + name,
|
||||
{
|
||||
@@ -330,7 +344,8 @@ class Api {
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<List<DependencyBean>>> dependencies(String type) async {
|
||||
static Future<HttpResponse<List<DependencyBean>>> dependencies(
|
||||
String type) async {
|
||||
return await Http.get<List<DependencyBean>>(
|
||||
Url.dependencies,
|
||||
{
|
||||
@@ -339,7 +354,8 @@ class Api {
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> dependencyReinstall(String id) async {
|
||||
static Future<HttpResponse<NullResponse>> dependencyReinstall(
|
||||
String id) async {
|
||||
return await Http.put<NullResponse>(
|
||||
Url.dependencies,
|
||||
[id],
|
||||
@@ -353,7 +369,8 @@ class Api {
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> addDependency(String name, int type) async {
|
||||
static Future<HttpResponse<NullResponse>> addDependency(
|
||||
String name, int type) async {
|
||||
return await Http.post<NullResponse>(
|
||||
Url.dependencies,
|
||||
[
|
||||
@@ -365,7 +382,8 @@ class Api {
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> addScript(String name, String path, String content) async {
|
||||
static Future<HttpResponse<NullResponse>> addScript(
|
||||
String name, String path, String content) async {
|
||||
return await Http.post<NullResponse>(
|
||||
Url.addScript,
|
||||
{
|
||||
|
||||
@@ -122,7 +122,8 @@ class Http {
|
||||
if (!pushedLoginPage) {
|
||||
"身份已过期,请重新登录".toast();
|
||||
pushedLoginPage = true;
|
||||
navigatorState.currentState?.pushNamedAndRemoveUntil(Routes.routeLogin, (route) => false);
|
||||
navigatorState.currentState
|
||||
?.pushNamedAndRemoveUntil(Routes.routeLogin, (route) => false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,9 +137,15 @@ class Http {
|
||||
}
|
||||
|
||||
if (e.response != null && e.response!.data != null) {
|
||||
return HttpResponse(success: false, message: e.response?.data["message"] ?? e.message, code: e.response?.data["code"] ?? 0);
|
||||
return HttpResponse(
|
||||
success: false,
|
||||
message: e.response?.data["message"] ?? e.message,
|
||||
code: e.response?.data["code"] ?? 0);
|
||||
} else {
|
||||
return HttpResponse(success: false, message: e.message, code: e.response?.statusCode ?? 0);
|
||||
return HttpResponse(
|
||||
success: false,
|
||||
message: e.message,
|
||||
code: e.response?.statusCode ?? 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,7 +230,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> {
|
||||
|
||||
@@ -7,8 +7,7 @@ import '../userinfo_viewmodel.dart';
|
||||
class TokenInterceptor extends Interceptor {
|
||||
@override
|
||||
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
|
||||
options.headers["User-Agent"] =
|
||||
"qinglong_client";
|
||||
options.headers["User-Agent"] = "qinglong_client";
|
||||
|
||||
options.headers["Content-Type"] = "application/json;charset=UTF-8";
|
||||
|
||||
|
||||
@@ -14,70 +14,127 @@ class Url {
|
||||
|
||||
static const updatePassword = "/api/user";
|
||||
|
||||
static get tasks => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons" : "/api/crons";
|
||||
static get tasks => getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/crons"
|
||||
: "/api/crons";
|
||||
|
||||
static get runTasks => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/run" : "/api/crons/run";
|
||||
static get runTasks => getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/crons/run"
|
||||
: "/api/crons/run";
|
||||
|
||||
static get stopTasks => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/stop" : "/api/crons/stop";
|
||||
static get stopTasks => getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/crons/stop"
|
||||
: "/api/crons/stop";
|
||||
|
||||
static get taskDetail => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/" : "/api/crons/";
|
||||
static get taskDetail => getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/crons/"
|
||||
: "/api/crons/";
|
||||
|
||||
static get addTask => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons" : "/api/crons";
|
||||
static get addTask => getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/crons"
|
||||
: "/api/crons";
|
||||
|
||||
static get pinTask => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/pin" : "/api/crons/pin";
|
||||
static get pinTask => getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/crons/pin"
|
||||
: "/api/crons/pin";
|
||||
|
||||
static get unpinTask => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/unpin" : "/api/crons/unpin";
|
||||
static get unpinTask => getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/crons/unpin"
|
||||
: "/api/crons/unpin";
|
||||
|
||||
static get enableTask => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/enable" : "/api/crons/enable";
|
||||
static get enableTask => getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/crons/enable"
|
||||
: "/api/crons/enable";
|
||||
|
||||
static get disableTask => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/disable" : "/api/crons/disable";
|
||||
static get disableTask => getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/crons/disable"
|
||||
: "/api/crons/disable";
|
||||
|
||||
static get files => getIt<UserInfoViewModel>().useSecretLogined ? "/open/configs/files" : "/api/configs/files";
|
||||
static get files => getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/configs/files"
|
||||
: "/api/configs/files";
|
||||
|
||||
static get configContent => getIt<UserInfoViewModel>().useSecretLogined ? "/open/configs/" : "/api/configs/";
|
||||
static get configContent => getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/configs/"
|
||||
: "/api/configs/";
|
||||
|
||||
static get saveFile => getIt<UserInfoViewModel>().useSecretLogined ? "/open/configs/save" : "/api/configs/save";
|
||||
static get saveFile => getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/configs/save"
|
||||
: "/api/configs/save";
|
||||
|
||||
static get envs => getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs" : "/api/envs";
|
||||
static get envs =>
|
||||
getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs" : "/api/envs";
|
||||
|
||||
static get addEnv => getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs" : "/api/envs";
|
||||
static get addEnv =>
|
||||
getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs" : "/api/envs";
|
||||
|
||||
static get delEnv => getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs" : "/api/envs";
|
||||
static get delEnv =>
|
||||
getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs" : "/api/envs";
|
||||
|
||||
static get disableEnvs => getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs/disable" : "/api/envs/disable";
|
||||
static get disableEnvs => getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/envs/disable"
|
||||
: "/api/envs/disable";
|
||||
|
||||
static get enableEnvs => getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs/enable" : "/api/envs/enable";
|
||||
static get enableEnvs => getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/envs/enable"
|
||||
: "/api/envs/enable";
|
||||
|
||||
static get loginLog => getIt<UserInfoViewModel>().useSecretLogined ? "/open/user/login-log" : "/api/user/login-log";
|
||||
static get loginLog => getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/user/login-log"
|
||||
: "/api/user/login-log";
|
||||
|
||||
static get taskLog => getIt<UserInfoViewModel>().useSecretLogined ? "/open/logs" : "/api/logs";
|
||||
static get taskLog =>
|
||||
getIt<UserInfoViewModel>().useSecretLogined ? "/open/logs" : "/api/logs";
|
||||
|
||||
static get taskLogDetail => getIt<UserInfoViewModel>().useSecretLogined ? "/open/logs/" : "/api/logs/";
|
||||
static get taskLogDetail => getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/logs/"
|
||||
: "/api/logs/";
|
||||
|
||||
static get scripts => getIt<UserInfoViewModel>().useSecretLogined ? "/open/scripts/files" : "/api/scripts/files";
|
||||
static get scripts => getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/scripts/files"
|
||||
: "/api/scripts/files";
|
||||
|
||||
static get scripts2 => getIt<UserInfoViewModel>().useSecretLogined ? "/open/scripts" : "/api/scripts";
|
||||
static get scripts2 => getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/scripts"
|
||||
: "/api/scripts";
|
||||
|
||||
static get scriptUpdate => getIt<UserInfoViewModel>().useSecretLogined ? "/open/scripts" : "/api/scripts";
|
||||
static get scriptUpdate => getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/scripts"
|
||||
: "/api/scripts";
|
||||
|
||||
static get scriptDetail => getIt<UserInfoViewModel>().useSecretLogined ? "/open/scripts/" : "/api/scripts/";
|
||||
static get scriptDetail => getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/scripts/"
|
||||
: "/api/scripts/";
|
||||
|
||||
static get dependencies => getIt<UserInfoViewModel>().useSecretLogined ? "/open/dependencies" : "/api/dependencies";
|
||||
static get dependencies => getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/dependencies"
|
||||
: "/api/dependencies";
|
||||
|
||||
static get addScript => getIt<UserInfoViewModel>().useSecretLogined ? "/open/scripts" : "/api/scripts";
|
||||
static get addScript => getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/scripts"
|
||||
: "/api/scripts";
|
||||
|
||||
static get dependencyReinstall => getIt<UserInfoViewModel>().useSecretLogined ? "/open/dependencies/reinstall" : "/api/dependencies/reinstall";
|
||||
static get dependencyReinstall => getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/dependencies/reinstall"
|
||||
: "/api/dependencies/reinstall";
|
||||
|
||||
static intimeLog(String cronId) {
|
||||
return getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/$cronId/log" : "/api/crons/$cronId/log";
|
||||
return getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/crons/$cronId/log"
|
||||
: "/api/crons/$cronId/log";
|
||||
}
|
||||
|
||||
static envMove(String envId) {
|
||||
return getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs/$envId/move" : "/api/envs/$envId/move";
|
||||
return getIt<UserInfoViewModel>().useSecretLogined
|
||||
? "/open/envs/$envId/move"
|
||||
: "/api/envs/$envId/move";
|
||||
}
|
||||
|
||||
static bool inWhiteList(String path) {
|
||||
if (path == login || path == loginByClientId || path == loginTwo || path == loginOld) {
|
||||
if (path == login ||
|
||||
path == loginByClientId ||
|
||||
path == loginTwo ||
|
||||
path == loginOld) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user