diff --git a/app/api/controller/BaseController.php b/app/api/controller/BaseController.php index 6acce58..2bc7313 100644 --- a/app/api/controller/BaseController.php +++ b/app/api/controller/BaseController.php @@ -69,21 +69,21 @@ class BaseController $user = ['id'=>0]; } $savePath = $request->post('savePath','files'); - $validate = Validate::rule('savePath', 'alphaNum'); $data = ['savePath' => $savePath]; if (!$validate->check($data)) { return $this->fail( '参数错误:'.$validate->getError()); } $savePath = trim($savePath,'/'); - $savePath = 'upload/'.$savePath.'/'.$user['id']; + //$savePath = 'upload/'.$savePath.'/'.$user['id']; + $savePath = $savePath.'/'.$user['id']; \support\Log::alert('savePath:'.$savePath); $mimetype = explode(',',Config('site.upload_mimetype')); $maxsize = Config('site.upload_maxsize')*1024*1024; //多文件上传 $files = $request->file(); try { - $result = Storage::adapter('public') + $result = Storage::adapter('minio') ->path($savePath) ->size($maxsize) ->extYes($mimetype) @@ -92,16 +92,18 @@ class BaseController foreach($result as $k=>$fileinfo){ $save_datas[] = [ 'user_id' => $user['id'], - 'category' => 'default', - 'title' => $fileinfo->origin_name, - 'path' => $fileinfo->file_name, - 'size' => $fileinfo->size, - 'mime_type' => $fileinfo->mime_type, - 'extension' => $fileinfo->extension, - 'height' => $fileinfo->file_height, - 'width' => $fileinfo->file_width, - 'sha1' => sha1_file(public_path($fileinfo->file_name)), - 'use_count' => 0, + 'category' => 'default', + 'adapter' => $fileinfo->adapter, + 'origin_name' => $fileinfo->origin_name, + 'file_name' => $fileinfo->file_name, + 'size' => $fileinfo->size, + 'mime_type' => $fileinfo->mime_type, + 'extension' => $fileinfo->extension, + 'file_height' => $fileinfo->file_height, + 'file_width' => $fileinfo->file_width, + 'file_url' => $fileinfo->file_url, + 'sha1' => $fileinfo->storage_key ?:sha1_file(public_path($fileinfo->file_name)), + 'use_count' => 0, ]; } \app\model\Files::insertAll($save_datas); diff --git a/composer.json b/composer.json index f04e3b0..5a3d3d0 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,8 @@ "firebase/php-jwt": "6.8", "php-mcp/server": "^3.3", "intervention/image": "^2.7.2", - "guzzlehttp/guzzle": "^7.5.0" + "guzzlehttp/guzzle": "^7.5.0", + "league/flysystem-aws-s3-v3": "^3.0" }, "suggest": { "ext-event": "For better performance. " diff --git a/config/plugin/shopwwi/filesystem/app.php b/config/plugin/shopwwi/filesystem/app.php index 756f6ff..fdbd781 100644 --- a/config/plugin/shopwwi/filesystem/app.php +++ b/config/plugin/shopwwi/filesystem/app.php @@ -64,16 +64,16 @@ return [ 'minio' => [ 'driver' => \Shopwwi\WebmanFilesystem\Adapter\S3AdapterFactory::class, 'credentials' => [ - 'key' => 'S3_KEY', - 'secret' => 'S3_SECRET', + 'key' => '8cF8LM6VD3uZHzibS9qB', + 'secret' => 'jKXbzKi8rKPHSOqPPNj3Xwr6z2OBSwGH0d48I8p7', ], 'region' => 'S3_REGION', 'version' => 'latest', 'bucket_endpoint' => false, 'use_path_style_endpoint' => true, - 'endpoint' => 'S3_ENDPOINT', - 'bucket_name' => 'S3_BUCKET', - 'url' => '' // 静态文件访问域名 + 'endpoint' => 'http://localhost:10005/', + 'bucket_name' => 'openim', + 'url' => 'http://156.238.245.175:10005/openim' // 静态文件访问域名 ], 'oss' => [ 'driver' => \Shopwwi\WebmanFilesystem\Adapter\AliyunOssAdapterFactory::class, diff --git a/plugin/admin/app/controller/AttachController.php b/plugin/admin/app/controller/AttachController.php deleted file mode 100644 index 6eceee8..0000000 --- a/plugin/admin/app/controller/AttachController.php +++ /dev/null @@ -1,168 +0,0 @@ -model = new \app\model\Files(); - } - function list(Request $request) - { - return view('', [ - - ]); - } - function feupload(Request $request): Response - { - $user = ['id'=>admin_id()]; - $savePath = $request->post('savePath','files'); - $validate = Validate::rule('savePath', 'alphaNum'); - $data = ['savePath' => $savePath]; - if (!$validate->check($data)) { - return $this->fail( '参数错误:'.$validate->getError()); - } - $savePath = trim($savePath,'/'); - $savePath = 'upload/'.$savePath.'/'.$user['id']; - $maxSize = 1024*1024*100; //100M - //多文件上传 - $files = $request->file(); - try { - $result = Storage::adapter('public') - ->path($savePath) - ->size(1024*1024*10) - ->extYes(['image/jpeg','image/png']) - ->uploads($files,0,$maxSize,false); - $save_datas = []; - foreach($result as $k=>$fileinfo){ - $save_datas[] = [ - 'user_id' => $user['id'], - 'title' => $fileinfo->origin_name, - 'path' => $fileinfo->file_name, - 'size' => $fileinfo->size, - 'mime_type' => $fileinfo->mime_type, - 'extension' => $fileinfo->extension, - 'height' => $fileinfo->file_height, - 'width' => $fileinfo->file_width, - 'sha1' => sha1_file(public_path($fileinfo->file_name)), - 'use_count' => 0, - ]; - } - \app\model\Files::saveAll($save_datas); - return $this->success(__('successful'),[ - 'link' => $result[0]['path'], - ]); - }catch (\Exception $e){ - return $this->fail($e->getMessage()); - } - } - function upload(Request $request): Response - { - log_alert(0); - $savePath = $request->post('savePath','files'); - $validate = Validate::rule('savePath', 'alphaNum'); - $data = ['savePath' => $savePath]; - log_alert($data); - if (!$validate->check($data)) { - cp($validate->getError()); - return $this->fail( '参数错误:'.$validate->getError()); - } - log_alert('1'); - $file = current($request->file()); - if (!$file || !$file->isValid()) { - return $this->fail('未找到文件'); - } - log_alert('2'); - try { - $data = $this->base($request, $savePath); - } catch (\Exception $e) { - log_alert($e->getMessage()); - //throw $th; - } - log_alert('3'); - //cp($data); - return $this->success( '上传成功', [ - 'url' => $data['realpath'], - 'name' => $data['name'], - 'fullurl' => $data['url'], - 'size' => $data['size'], - 'url1' => $data['url'], - ]); - } - - /** - * 获取上传数据 - * @param Request $request - * @param $savePath 保存位置 - * @return array - * @throws \Exception - */ - protected function base(Request $request, $savePath): array - { - $user = ['id'=>admin_id()]; - // 适配器 local默认是存储在runtime目录下 public默认是存储在public目录下 - // 可访问的静态文件建议public - // 默认适配器是local - //Storage::adapter('public'); - $savePath = trim($savePath,'/'); - $savePath = 'upload/'.$savePath; - cp($savePath); - $file = current($request->file()); - cp($file); - $mimetype = explode(',',Config('site.upload_mimetype')); - $maxsize = Config('site.upload_maxsize')*1024*1024; - $result = Storage::adapter('public') - ->path($savePath) - ->size($maxsize) - ->extYes($mimetype) - ->upload($file); - cp($result); - - $save_datas = [ - 'user_id' => $user['id'], - 'category' => 'default', - 'title' => $result->origin_name, - 'path' => $result->file_name, - 'size' => $result->size, - 'mime_type' => $result->mime_type, - 'extension' => $result->extension, - 'height' => $result->file_height, - 'width' => $result->file_width, - 'sha1' => sha1_file(public_path($result->file_name)), - 'use_count' => 0, - ]; - (new \app\model\Files)->save($save_datas); - return [ - 'code' => 0, - 'url' => $result->file_url, - 'name' => $result->origin_name, - 'realpath' => '/'.$result->file_name, - 'size' => $result->size, - 'mime_type' => $result->mime_type, - 'image_with'=> $result->file_width, - 'image_height' => $result->file_height, - 'ext' => $result->extension, - ]; - } -} diff --git a/plugin/admin/app/controller/FilesController.php b/plugin/admin/app/controller/FilesController.php index 0238bd1..755eb40 100644 --- a/plugin/admin/app/controller/FilesController.php +++ b/plugin/admin/app/controller/FilesController.php @@ -2,6 +2,7 @@ namespace plugin\admin\app\controller; +use Exception; use support\Request; use support\Response; use support\think\Db; @@ -30,80 +31,38 @@ class FilesController extends Crud } function list(Request $request) { - return view('', [ + $list = $this->model->paginate(); + return $this->success(__('successful'),$list); + + } + function felist(Request $request) + { + $list = $this->model->paginate(); + $result = []; + $list->each(function($item)use(&$result){ + array_push($result,[ + 'tag' => "test", + 'name' => $item["origin_name"], + //'thumb'=> $item["file_url"], + 'url' => $item["file_url"], + ]); + }); + return json($result); - ]); } function feupload(Request $request): Response { - $user = ['id'=>admin_id()]; $savePath = $request->post('savePath','files'); - $validate = Validate::rule('savePath', 'alphaNum'); - $data = ['savePath' => $savePath]; - if (!$validate->check($data)) { - return $this->fail( '参数错误:'.$validate->getError()); - } - $savePath = trim($savePath,'/'); - $savePath = 'upload/'.$savePath.'/'.$user['id']; - $maxSize = 1024*1024*100; //100M - //多文件上传 - $files = $request->file(); - try { - $result = Storage::adapter('public') - ->path($savePath) - ->size(1024*1024*10) - ->extYes(['image/jpeg','image/png']) - ->uploads($files,0,$maxSize,false); - $save_datas = []; - foreach($result as $k=>$fileinfo){ - $save_datas[] = [ - 'user_id' => $user['id'], - 'title' => $fileinfo->origin_name, - 'path' => $fileinfo->file_name, - 'size' => $fileinfo->size, - 'mime_type' => $fileinfo->mime_type, - 'extension' => $fileinfo->extension, - 'height' => $fileinfo->file_height, - 'width' => $fileinfo->file_width, - 'sha1' => sha1_file(public_path($fileinfo->file_name)), - 'use_count' => 0, - ]; - } - \app\model\Files::saveAll($save_datas); - return $this->success(__('successful'),[ - 'link' => $result[0]['path'], - ]); - }catch (\Exception $e){ - return $this->fail($e->getMessage()); - } + $data = $this->base($request, $savePath); + return json([ + 'link' => $data['file_url'], + ]); } function upload(Request $request): Response { - cp('0'); $savePath = $request->post('savePath','files'); - $validate = Validate::rule('savePath', 'alphaNum'); - $data = ['savePath' => $savePath]; - cp($data); - if (!$validate->check($data)) { - cp($validate->getError()); - return $this->fail( '参数错误:'.$validate->getError()); - } - cp('1'); - $file = current($request->file()); - if (!$file || !$file->isValid()) { - return $this->fail('未找到文件'); - } - cp('2'); $data = $this->base($request, $savePath); - cp('3'); - //cp($data); - return $this->success( '上传成功', [ - 'url' => $data['realpath'], - 'name' => $data['name'], - 'fullurl' => $data['url'], - 'size' => $data['size'], - 'url1' => $data['url'], - ]); + return $this->success( '上传成功', $data); } /** @@ -113,48 +72,47 @@ class FilesController extends Crud * @return array * @throws \Exception */ - protected function base(Request $request, $savePath): array + protected function base(Request $request, $savePath): mixed { - $user = ['id'=>admin_id()]; // 适配器 local默认是存储在runtime目录下 public默认是存储在public目录下 // 可访问的静态文件建议public // 默认适配器是local //Storage::adapter('public'); + $validate = Validate::rule('savePath', 'alphaNum'); + $data = ['savePath' => $savePath]; + if (!$validate->check($data)) { + throw new Exception( '参数错误:'.$validate->getError()); + } $savePath = trim($savePath,'/'); - $savePath = 'upload/'.$savePath; + //$savePath = 'upload/'.$savePath; + //$savePath = $savePath; $file = current($request->file()); + if (!$file || !$file->isValid()) { + throw new Exception( '未找到文件'); + } $mimetype = explode(',',Config('site.upload_mimetype')); $maxsize = Config('site.upload_maxsize')*1024*1024; - $result = Storage::adapter('public') + $result = Storage::adapter('minio') ->path($savePath) ->size($maxsize) ->extYes($mimetype) ->upload($file); - $save_datas = [ - 'user_id' => $user['id'], - 'category' => 'default', - 'title' => $result->origin_name, - 'path' => $result->file_name, - 'size' => $result->size, - 'mime_type' => $result->mime_type, - 'extension' => $result->extension, - 'height' => $result->file_height, - 'width' => $result->file_width, - 'sha1' => sha1_file(public_path($result->file_name)), - 'use_count' => 0, - ]; - (new \app\model\Files)->save($save_datas); - return [ - 'code' => 0, - 'url' => $result->file_url, - 'name' => $result->origin_name, - 'realpath' => '/'.$result->file_name, - 'size' => $result->size, - 'mime_type' => $result->mime_type, - 'image_with'=> $result->file_width, - 'image_height' => $result->file_height, - 'ext' => $result->extension, + 'admin_id' => admin_id(), + 'category' => 'default', + 'adapter' => $result->adapter, + 'origin_name' => $result->origin_name, + 'file_name' => $result->file_name, + 'size' => $result->size, + 'mime_type' => $result->mime_type, + 'extension' => $result->extension, + 'file_height' => $result->file_height, + 'file_width' => $result->file_width, + 'file_url' => $result->file_url, + 'sha1' => $result->storage_key ?:sha1_file(public_path($result->file_name)), + 'use_count' => 0, ]; + + return \app\model\Files::create($save_datas); } } diff --git a/plugin/admin/app/functions.php b/plugin/admin/app/functions.php index 9b77ff3..5b28941 100644 --- a/plugin/admin/app/functions.php +++ b/plugin/admin/app/functions.php @@ -103,40 +103,10 @@ function refresh_admin_session(bool $force = false) $session->set('admin', $admin); } -function getConfig($name=''){ - if($name){ - if(strpos($name,'.')>-1){ - $name = explode('.',$name); - if(Config('site.'.$name[0].'.type') == 'array'){ - return Config('site.'.$name[0].'.value.'.$name[1]); - }else{ - return Config('site.'.$name[0].'.value'); - } - }else{ - return Config('site.'.$name); - } - }else{ - return Config('site'); - } -} function null($var='',$defaut=''){ if(isset($var) && !$var){ return $defaut; }else{ return $var; } -} -function buildFileInput($name='',$value='',$type='image',$limit=0,$allowChoose=true){ - $tpl = ' - - '; - return $tpl; } \ No newline at end of file diff --git a/plugin/admin/app/middleware/Config.php b/plugin/admin/app/middleware/Config.php index 377d29a..7d9b1a9 100644 --- a/plugin/admin/app/middleware/Config.php +++ b/plugin/admin/app/middleware/Config.php @@ -28,6 +28,7 @@ class Config implements MiddlewareInterface $config['action'] = $request->action_name; $config['moduleurl'] = admin_path(); $config['admin_path'] = admin_path(); + $config['domain'] = env_get('server.domain',''); $request->_view_vars = array_merge((array) $request->_view_vars,[ 'user' => session('admin'), 'config' => $config diff --git a/plugin/admin/app/view/account/profile.html b/plugin/admin/app/view/account/profile.html index 2ae5fad..1ff423d 100644 --- a/plugin/admin/app/view/account/profile.html +++ b/plugin/admin/app/view/account/profile.html @@ -47,8 +47,8 @@ diff --git a/plugin/admin/app/view/admin/update.html b/plugin/admin/app/view/admin/update.html index 84ffab5..825e4b8 100644 --- a/plugin/admin/app/view/admin/update.html +++ b/plugin/admin/app/view/admin/update.html @@ -65,8 +65,8 @@ diff --git a/plugin/admin/app/view/archives/update.html b/plugin/admin/app/view/archives/update.html index ed8e597..effbffc 100644 --- a/plugin/admin/app/view/archives/update.html +++ b/plugin/admin/app/view/archives/update.html @@ -102,8 +102,8 @@ @@ -114,8 +114,8 @@ diff --git a/plugin/admin/app/view/config/index.html b/plugin/admin/app/view/config/index.html index e599ec8..d6f0574 100644 --- a/plugin/admin/app/view/config/index.html +++ b/plugin/admin/app/view/config/index.html @@ -115,10 +115,7 @@ {case value="image" break="0"}{/case} {case value="images"}
- - {html:upload name="$item.name" value="$item.value" tip="$item.tip" /} + {html:upload name="$item.name" value="$item.value" tip="$item.tip" extend="$item.extend" /}
{/case} {case value="file" break="0"}{/case} diff --git a/plugin/admin/app/view/dev/form.html b/plugin/admin/app/view/dev/form.html index 16985f0..9d1a432 100644 --- a/plugin/admin/app/view/dev/form.html +++ b/plugin/admin/app/view/dev/form.html @@ -40,12 +40,12 @@