Update.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\admin\controller\api;
  3. use think\admin\Controller;
  4. use think\admin\service\ModuleService;
  5. use think\admin\service\SystemService;
  6. /**
  7. * 安装服务端支持
  8. * Class Update
  9. * @package app\admin\controller\api
  10. */
  11. class Update extends Controller
  12. {
  13. /**
  14. * 访问环境拦截
  15. */
  16. protected function initialize()
  17. {
  18. if (!SystemService::instance()->checkRunMode('dev')) {
  19. $this->error('只允许访问本地或官方代码!');
  20. }
  21. }
  22. /**
  23. * 读取文件内容
  24. */
  25. public function get()
  26. {
  27. $filename = decode(input('encode', '0'));
  28. if (!ModuleService::instance()->checkAllowDownload($filename)) {
  29. $this->error('下载的文件不在认证规则中!');
  30. }
  31. if (file_exists($realname = $this->app->getRootPath() . $filename)) {
  32. $this->success('读取文件内容成功!', [
  33. 'content' => base64_encode(file_get_contents($realname)),
  34. ]);
  35. } else {
  36. $this->error('读取文件内容失败!');
  37. }
  38. }
  39. /**
  40. * 读取文件列表
  41. */
  42. public function node()
  43. {
  44. $this->success('获取文件列表成功!', ModuleService::instance()->getChanges(
  45. json_decode($this->request->post('rules', '[]', ''), true),
  46. json_decode($this->request->post('ignore', '[]', ''), true)
  47. ));
  48. }
  49. /**
  50. * 获取模块信息
  51. */
  52. public function version()
  53. {
  54. $this->success('获取模块信息成功!', ModuleService::instance()->getModules());
  55. }
  56. }