适配新版本api

This commit is contained in:
jyuesong
2022-04-24 12:12:53 +08:00
parent 6c3c15a85d
commit 70f4df431f
7 changed files with 144 additions and 25 deletions

View File

@@ -1,6 +1,7 @@
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/home/system_bean.dart';
import 'package:qinglong_app/module/login/login_bean.dart';
import 'package:qinglong_app/module/login/user_bean.dart';
import 'package:qinglong_app/module/others/dependencies/dependency_bean.dart';
@@ -9,9 +10,17 @@ 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 '../../utils/utils.dart';
import 'url.dart';
class Api {
static Future<HttpResponse<SystemBean>> system() async {
return await Http.get<SystemBean>(
Url.system,
{},
);
}
static Future<HttpResponse<LoginBean>> login(
String userName,
String passWord,
@@ -24,10 +33,11 @@ class Api {
},
);
}
static Future<HttpResponse<LoginBean>> loginOld(
String userName,
String passWord,
) async {
String userName,
String passWord,
) async {
return await Http.post<LoginBean>(
Url.loginOld,
{
@@ -36,6 +46,7 @@ class Api {
},
);
}
static Future<HttpResponse<LoginBean>> loginTwo(
String userName,
String passWord,
@@ -78,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,
{
@@ -109,11 +123,17 @@ class Api {
);
}
static Future<HttpResponse<NullResponse>> addTask(String name, String command, String cron, {String? id}) async {
static Future<HttpResponse<NullResponse>> addTask(
String name, String command, String cron,
{String? id}) async {
var data = {"name": name, "command": command, "schedule": cron};
if (id != null) {
data["id"] = id;
if (Utils.isUpperVersion()) {
data["id"] = id;
} else {
data["_id"] = id;
}
return await Http.put<NullResponse>(
Url.addTask,
data,
@@ -174,7 +194,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},
@@ -209,7 +230,9 @@ class Api {
);
}
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,
@@ -217,7 +240,12 @@ class Api {
};
if (id != null) {
data["id"] = id;
if (Utils.isUpperVersion()) {
data["id"] = id;
} else {
data["_id"] = id;
}
return await Http.put<NullResponse>(
Url.addEnv,
data,
@@ -229,7 +257,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},
@@ -244,7 +273,8 @@ class Api {
}
static Future<HttpResponse<List<TaskLogBean>>> taskLog() async {
return await Http.get<List<TaskLogBean>>(Url.taskLog, null, serializationName: "dirs");
return await Http.get<List<TaskLogBean>>(Url.taskLog, null,
serializationName: "dirs");
}
static Future<HttpResponse<String>> taskLogDetail(String name) async {
@@ -261,7 +291,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,
{
@@ -272,7 +303,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,
{
@@ -282,7 +314,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,
{
@@ -291,7 +324,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,
{
@@ -300,7 +334,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],
@@ -314,7 +349,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,
[

View File

@@ -2,6 +2,8 @@ import '../../main.dart';
import '../userinfo_viewmodel.dart';
class Url {
static get system => "/api/system";
static get login => "/api/user/login";
static get loginOld => "/api/login";