Common.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. //
  3. //namespace app\api\controller;
  4. //
  5. //use app\common\controller\Api;
  6. //use app\common\exception\UploadException;
  7. //use app\common\library\Upload;
  8. //use app\common\model\Area;
  9. //use app\common\model\Version;
  10. //use fast\Random;
  11. //use think\Config;
  12. //use think\Hook;
  13. //
  14. ///**
  15. // * 公共接口
  16. // */
  17. //class Common extends Api
  18. //{
  19. // protected array $noNeedLogin = ['init'];
  20. // protected $noNeedRight = '*';
  21. //
  22. // /**
  23. // * 加载初始化
  24. // *
  25. // * @param string $version 版本号
  26. // * @param string $lng 经度
  27. // * @param string $lat 纬度
  28. // */
  29. // public function init()
  30. // {
  31. // if ($version = $this->request->request('version')) {
  32. // $lng = $this->request->request('lng');
  33. // $lat = $this->request->request('lat');
  34. //
  35. // //配置信息
  36. // $upload = Config::get('upload');
  37. // //如果非服务端中转模式需要修改为中转
  38. // if ($upload['storage'] != 'local' && isset($upload['uploadmode']) && $upload['uploadmode'] != 'server') {
  39. // //临时修改上传模式为服务端中转
  40. // set_addon_config($upload['storage'], ["uploadmode" => "server"], false);
  41. //
  42. // $upload = \app\common\model\Config::upload();
  43. // // 上传信息配置后
  44. // Hook::listen("upload_config_init", $upload);
  45. //
  46. // $upload = Config::set('upload', array_merge(Config::get('upload'), $upload));
  47. // }
  48. //
  49. // $upload['cdnurl'] = $upload['cdnurl'] ? $upload['cdnurl'] : cdnurl('', true);
  50. // $upload['uploadurl'] = preg_match("/^((?:[a-z]+:)?\/\/)(.*)/i", $upload['uploadurl']) ? $upload['uploadurl'] : url($upload['storage'] == 'local' ? '/api/common/upload' : $upload['uploadurl'], '', false, true);
  51. //
  52. // $content = [
  53. // 'citydata' => Area::getCityFromLngLat($lng, $lat),
  54. // 'versiondata' => Version::check($version),
  55. // 'uploaddata' => $upload,
  56. // 'coverdata' => Config::get("cover"),
  57. // ];
  58. // $this->success('', $content);
  59. // } else {
  60. // $this->error(__('Invalid parameters'));
  61. // }
  62. // }
  63. //
  64. // /**
  65. // * 上传文件
  66. // * @ApiMethod (POST)
  67. // * @param File $file 文件流
  68. // */
  69. // public function upload()
  70. // {
  71. // Config::set('default_return_type', 'json');
  72. // //必须设定cdnurl为空,否则cdnurl函数计算错误
  73. // Config::set('upload.cdnurl', '');
  74. // $chunkid = $this->request->post("chunkid");
  75. // if ($chunkid) {
  76. // if (!Config::get('upload.chunking')) {
  77. // $this->error(__('Chunk file disabled'));
  78. // }
  79. // $action = $this->request->post("action");
  80. // $chunkindex = $this->request->post("chunkindex/d");
  81. // $chunkcount = $this->request->post("chunkcount/d");
  82. // $filename = $this->request->post("filename");
  83. // $method = $this->request->method(true);
  84. // if ($action == 'merge') {
  85. // $attachment = null;
  86. // //合并分片文件
  87. // try {
  88. // $upload = new Upload();
  89. // $attachment = $upload->merge($chunkid, $chunkcount, $filename);
  90. // } catch (UploadException $e) {
  91. // $this->error($e->getMessage());
  92. // }
  93. // $this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]);
  94. // } elseif ($method == 'clean') {
  95. // //删除冗余的分片文件
  96. // try {
  97. // $upload = new Upload();
  98. // $upload->clean($chunkid);
  99. // } catch (UploadException $e) {
  100. // $this->error($e->getMessage());
  101. // }
  102. // $this->success();
  103. // } else {
  104. // //上传分片文件
  105. // //默认普通上传文件
  106. // $file = $this->request->file('file');
  107. // try {
  108. // $upload = new Upload($file);
  109. // $upload->chunk($chunkid, $chunkindex, $chunkcount);
  110. // } catch (UploadException $e) {
  111. // $this->error($e->getMessage());
  112. // }
  113. // $this->success();
  114. // }
  115. // } else {
  116. // $attachment = null;
  117. // //默认普通上传文件
  118. // $file = $this->request->file('file');
  119. // try {
  120. // $upload = new Upload($file);
  121. // $attachment = $upload->upload();
  122. // } catch (UploadException $e) {
  123. // $this->error($e->getMessage());
  124. // }
  125. //
  126. // $this->success(__('Uploaded successful'), ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]);
  127. // }
  128. //
  129. // }
  130. //}