Update.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2022 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // | 免费声明 ( https://thinkadmin.top/disclaimer )
  11. // +----------------------------------------------------------------------
  12. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  13. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  14. // +----------------------------------------------------------------------
  15. namespace app\admin\controller\api;
  16. use think\admin\Controller;
  17. use think\admin\service\ModuleService;
  18. use think\admin\service\SystemService;
  19. /**
  20. * 安装服务端支持
  21. * Class Update
  22. * @package app\admin\controller\api
  23. */
  24. class Update extends Controller
  25. {
  26. /**
  27. * 访问环境拦截
  28. */
  29. protected function initialize()
  30. {
  31. if (!SystemService::checkRunMode()) {
  32. $this->error('只允许访问本地或官方代码!');
  33. }
  34. }
  35. /**
  36. * 读取文件内容
  37. */
  38. public function get()
  39. {
  40. $filename = decode(input('encode', '0'));
  41. if (!ModuleService::checkAllowDownload($filename)) {
  42. $this->error('下载的文件不在认证规则中!');
  43. }
  44. if (file_exists($realname = $this->app->getRootPath() . $filename)) {
  45. $this->success('读取文件内容成功!', [
  46. 'content' => base64_encode(file_get_contents($realname)),
  47. ]);
  48. } else {
  49. $this->error('读取文件内容失败!');
  50. }
  51. }
  52. /**
  53. * 读取文件列表
  54. */
  55. public function node()
  56. {
  57. $this->success('获取文件列表成功!', ModuleService::getChanges(
  58. json_decode($this->request->post('rules', '[]', ''), true),
  59. json_decode($this->request->post('ignore', '[]', ''), true)
  60. ));
  61. }
  62. /**
  63. * 获取模块信息
  64. */
  65. public function version()
  66. {
  67. $this->success('获取模块信息成功!', ModuleService::getModules());
  68. }
  69. }