mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
add task
This commit is contained in:
@@ -39,6 +39,16 @@ class Api {
|
||||
}
|
||||
|
||||
static Future<HttpResponse<TaskDetailBean>> addTask(String name, String command, String cron, {String? id}) async {
|
||||
return await Http.put<TaskDetailBean>(Url.ADD_TASK, {"name": name, "command": command, "schedule": cron, "_id": id});
|
||||
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.post<TaskDetailBean>(Url.ADD_TASK, data);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> delTask(String cron) async {
|
||||
return await Http.delete<NullResponse>(Url.ADD_TASK, [cron]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,31 +36,46 @@ class Http {
|
||||
}
|
||||
|
||||
static Future<HttpResponse<T>> get<T>(String uri, Map<String, String>? json, {bool compute = true}) async {
|
||||
_init();
|
||||
var response = await _dio!.get(uri, queryParameters: json);
|
||||
try {
|
||||
_init();
|
||||
var response = await _dio!.get(uri, queryParameters: json);
|
||||
|
||||
return decodeResponse<T>(response, compute);
|
||||
return decodeResponse<T>(response, compute);
|
||||
} on DioError catch (e) {
|
||||
return HttpResponse(success: false, message: e.message, code: 0);
|
||||
}
|
||||
}
|
||||
|
||||
static Future<HttpResponse<T>> post<T>(String uri, dynamic json, {bool compute = true}) async {
|
||||
_init();
|
||||
var response = await _dio!.post(uri, data: json);
|
||||
try {
|
||||
_init();
|
||||
var response = await _dio!.post(uri, data: json);
|
||||
|
||||
return decodeResponse<T>(response, compute);
|
||||
return decodeResponse<T>(response, compute);
|
||||
} on DioError catch (e) {
|
||||
return HttpResponse(success: false, message: e.message, code: 0);
|
||||
}
|
||||
}
|
||||
|
||||
static Future<HttpResponse<T>> delete<T>(String uri, dynamic json, {bool compute = true}) async {
|
||||
_init();
|
||||
var response = await _dio!.delete(uri, data: json);
|
||||
try {
|
||||
_init();
|
||||
var response = await _dio!.delete(uri, data: json);
|
||||
|
||||
return decodeResponse<T>(response, compute);
|
||||
return decodeResponse<T>(response, compute);
|
||||
} on DioError catch (e) {
|
||||
return HttpResponse(success: false, message: e.message, code: 0);
|
||||
}
|
||||
}
|
||||
|
||||
static Future<HttpResponse<T>> put<T>(String uri, dynamic json, {bool compute = true}) async {
|
||||
_init();
|
||||
var response = await _dio!.put(uri, data: json);
|
||||
|
||||
return decodeResponse<T>(response, compute);
|
||||
try {
|
||||
_init();
|
||||
var response = await _dio!.put(uri, data: json);
|
||||
return decodeResponse<T>(response, compute);
|
||||
} on DioError catch (e) {
|
||||
return HttpResponse(success: false, message: e.message, code: 0);
|
||||
}
|
||||
}
|
||||
|
||||
static HttpResponse<T> decodeResponse<T>(
|
||||
@@ -173,4 +188,4 @@ void decode<T>() async {
|
||||
compute(DeserializeAction.invokeJson, DeserializeAction<T>({}));
|
||||
}
|
||||
|
||||
class NullResponse{}
|
||||
class NullResponse {}
|
||||
|
||||
@@ -7,7 +7,7 @@ class TokenInterceptor extends Interceptor {
|
||||
if (userInfoViewModel.token != null) {
|
||||
options.headers["Authorization"] = "Bearer " + userInfoViewModel.token!;
|
||||
}
|
||||
options.queryParameters["t"] = DateTime.now().millisecondsSinceEpoch;
|
||||
options.queryParameters["t"] = (DateTime.now().millisecondsSinceEpoch~/1000).toString();
|
||||
return handler.next(options);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user