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/login/user_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 'url.dart'; class Api { static Future> login( String userName, String passWord, ) async { return await Http.post( Url.login, { "username": userName, "password": passWord, }, ); } static Future> loginTwo( String userName, String passWord, String code, ) async { return await Http.put( Url.loginTwo, { "username": userName, "password": passWord, "code": code, }, ); } static Future> loginByClientId( String id, String secret, ) async { return await Http.get( Url.loginByClientId, { "client_id": id, "client_secret": secret, }, ); } static Future> user() async { return await Http.get( Url.user, null, ); } static Future>> crons() async { return await Http.get>( Url.tasks, {"searchValue": ""}, ); } static Future> startTasks(List crons) async { return await Http.put( Url.runTasks, crons, ); } static Future> stopTasks(List crons) async { return await Http.put( Url.runTasks, crons, ); } static Future> updatePassword(String name, String password) async { return await Http.put( Url.updatePassword, { "username": name, "password": password, }, ); } static Future> inTimeLog(String cron) async { return await Http.get( Url.intimeLog(cron), null, ); } static Future> addTask(String name, String command, String cron, {String? id}) async { var data = {"name": name, "command": command, "schedule": cron}; if (id != null) { data["_id"] = id; data["id"] = id; return await Http.put( Url.addTask, data, ); } return await Http.post( Url.addTask, data, ); } static Future> delTask(String cron) async { return await Http.delete( Url.addTask, [cron], ); } static Future> pinTask(String cron) async { return await Http.put( Url.pinTask, [cron], ); } static Future> unpinTask(String cron) async { return await Http.put( Url.unpinTask, [cron], ); } static Future> enableTask(String cron) async { return await Http.put( Url.enableTask, [cron], ); } static Future> disableTask(String cron) async { return await Http.put( Url.disableTask, [cron], ); } static Future>> files() async { return await Http.get>( Url.files, null, ); } static Future> content(String name) async { return await Http.get( Url.configContent + name, null, ); } static Future> saveFile(String name, String content) async { return await Http.post( Url.saveFile, {"content": content, "name": name}, ); } static Future>> envs(String search) async { return await Http.get>( Url.envs, {"searchValue": search}, ); } static Future> enableEnv(String id) async { return await Http.put( Url.enableEnvs, [id], ); } static Future> disableEnv(String id) async { return await Http.put( Url.disableEnvs, [id], ); } static Future> delEnv(String id) async { return await Http.delete( Url.delEnv, [id], ); } static Future> addEnv(String name, String value, String remarks, {String? id}) async { var data = { "value": value, "remarks": remarks, "name": name, }; if (id != null) { data["_id"] = id; data["id"] = id; return await Http.put( Url.addEnv, data, ); } return await Http.post( Url.addEnv, [data], ); } static Future> moveEnv(String id, int fromIndex, int toIndex) async { return await Http.put( Url.envMove(id), {"fromIndex": fromIndex, "toIndex": toIndex}, ); } static Future>> loginLog() async { return await Http.get>( Url.loginLog, null, ); } static Future>> taskLog() async { return await Http.get>(Url.taskLog, null, serializationName: "dirs"); } static Future> taskLogDetail(String name) async { return await Http.get( Url.taskLogDetail + name, null, ); } static Future>> scripts() async { return await Http.get>( Url.scripts, null, ); } static Future> updateScript(String name, String path, String content) async { return await Http.put( Url.scriptDetail, { "filename": name, "path": path, "content": content, }, ); } static Future> delScript(String name, String path) async { return await Http.delete( Url.scriptDetail, { "filename": name, "path": path, }, ); } static Future> scriptDetail(String name, String? path) async { return await Http.get( Url.scriptDetail + name, { "path": path, }, ); } static Future>> dependencies(String type) async { return await Http.get>( Url.dependencies, { "type": type.toString(), }, ); } static Future> dependencyReinstall(String id) async { return await Http.put( Url.dependencies, [id], ); } static Future> dependencyLog(String id) async { return await Http.get( Url.dependencies + "/" + id, null, ); } static Future> addDependency(String name, int type) async { return await Http.post( Url.dependencies, [ { "name": name, "type": type, } ], ); } static Future> delDependency(String id) async { return await Http.delete( Url.dependencies, [id], ); } }