From 14f05b6cefd6e2aa6f37962d13fac3693a4ee895 Mon Sep 17 00:00:00 2001 From: filesite Date: Thu, 14 Nov 2024 16:29:23 +0800 Subject: [PATCH] add command controller for theme beauty --- controller/CommandController.php | 72 ------------ .../beauty/controller/CommandController.php | 105 ++++++++++++++++++ 2 files changed, 105 insertions(+), 72 deletions(-) create mode 100644 themes/beauty/controller/CommandController.php diff --git a/controller/CommandController.php b/controller/CommandController.php index 1de6544..293d1d3 100644 --- a/controller/CommandController.php +++ b/controller/CommandController.php @@ -18,78 +18,6 @@ eof; exit; } - public function actionConfig() { - $themeName = FSC::$app['config']['theme']; - - $code = 1; - $data = ''; - - //修改配置文件 - $param_do = $this->get('do', 'set'); //支持:set, get, all, del - $param_key = $this->get('key', ''); - $param_value = $this->get('val', ''); - - if ($param_do == 'set' && empty($param_value)) { - throw new Exception("缺少val参数!", 403); - }else if (in_array($param_do, array('set', 'get', 'del')) && empty($param_key)) { - throw new Exception("缺少key参数!", 403); - } - - //val数据格式转换 - if ($param_value === 'false') { - $param_value = false; - }else if ($param_value === 'true') { - $param_value = true; - } - - $config_file = __DIR__ . "/../runtime/custom_config.json"; - if (file_exists($config_file)) { - $content = file_get_contents($config_file); - $configs = @json_decode($content, true); - if (empty($configs)) { - $config_file_template = __DIR__ . "/../conf/custom_config_{$themeName}.json"; - $content = file_get_contents($config_file_template); - $configs = @json_decode($content, true); - } - } - - if (!empty($configs)) { - switch($param_do) { - case 'set': - $configs[$param_key] = $param_value; - file_put_contents($config_file, json_encode($configs, JSON_PRETTY_PRINT)); - $data = $configs; - break; - - case 'get': - $data = !empty($configs[$param_key]) ? $configs[$param_key] : ''; - break; - - case 'del': - unset($configs[$param_key]); - file_put_contents($config_file, json_encode($configs, JSON_PRETTY_PRINT)); - $data = $configs; - break; - - case 'all': - default: - $data = $configs; - break; - } - } - - - $res = compact('code', 'data'); - - echo "命令参数:\n"; - print_r($this->get()); - echo "\n"; - echo "命令执行结果:\n"; - print_r($res); - echo "\n\n"; - exit; - } - public function actionTest() { echo "## App variables:\n"; print_r(FSC::$app); diff --git a/themes/beauty/controller/CommandController.php b/themes/beauty/controller/CommandController.php new file mode 100644 index 0000000..9cfa65b --- /dev/null +++ b/themes/beauty/controller/CommandController.php @@ -0,0 +1,105 @@ +get('do', 'set'); //支持:set, get, all, del + $param_key = $this->get('key', ''); + $param_value = $this->get('val', ''); + + if ($param_do == 'set' && empty($param_value)) { + throw new Exception("缺少val参数!", 403); + }else if (in_array($param_do, array('set', 'get', 'del')) && empty($param_key)) { + throw new Exception("缺少key参数!", 403); + } + + //val数据格式转换 + if ($param_value === 'false') { + $param_value = false; + }else if ($param_value === 'true') { + $param_value = true; + } + + $config_file = __DIR__ . "/../../../runtime/custom_config.json"; + if (file_exists($config_file)) { + $content = file_get_contents($config_file); + $configs = @json_decode($content, true); + if (empty($configs)) { + $config_file_template = __DIR__ . "/../../../conf/custom_config_{$themeName}.json"; + $content = file_get_contents($config_file_template); + $configs = @json_decode($content, true); + } + } + + if (!empty($configs)) { + switch($param_do) { + case 'set': + $configs[$param_key] = $param_value; + file_put_contents($config_file, json_encode($configs, JSON_PRETTY_PRINT)); + $data = $configs; + break; + + case 'get': + $data = !empty($configs[$param_key]) ? $configs[$param_key] : ''; + break; + + case 'del': + unset($configs[$param_key]); + file_put_contents($config_file, json_encode($configs, JSON_PRETTY_PRINT)); + $data = $configs; + break; + + case 'all': + default: + $data = $configs; + break; + } + } + + + $res = compact('code', 'data'); + + echo "命令参数:\n"; + print_r($this->get()); + echo "\n"; + echo "命令执行结果:\n"; + print_r($res); + echo "\n\n"; + exit; + } + + + //服务器端机器人程序,负责图片、视频文件拍摄时间等信息扫描,并缓存结果供前端使用 + public function actionMainBot() { + $thisTime = date('Y-m-d H:i:s'); + echo "Main bot started @{$thisTime}\n"; + + + exit; + } + +}