|
@@ -1,35 +1,58 @@
|
|
|
<?php
|
|
|
-
|
|
|
-declare(strict_types=1);
|
|
|
-
|
|
|
+declare (strict_types = 1);
|
|
|
namespace App\Controller;
|
|
|
|
|
|
-use App\Service\MinioService;
|
|
|
-use Hyperf\HttpServer\Annotation\Controller;
|
|
|
-use Hyperf\HttpServer\Annotation\RequestMapping;
|
|
|
-use Psr\Http\Message\ResponseInterface;
|
|
|
-use function Sodium\version_string;
|
|
|
+use App\JsonRpc\PublicRpcServiceInterface;
|
|
|
use App\Tools\Result;
|
|
|
+use Hyperf\Di\Annotation\Inject;
|
|
|
+use Hyperf\Validation\Contract\ValidatorFactoryInterface;
|
|
|
|
|
|
class MinioController extends AbstractController
|
|
|
{
|
|
|
+ #[Inject]
|
|
|
+ protected ValidatorFactoryInterface $validationFactory;
|
|
|
/**
|
|
|
- * @Inject
|
|
|
- * @var MinioService
|
|
|
+ * @var PublicRpcServiceInterface
|
|
|
*/
|
|
|
- protected $minioService;
|
|
|
+ #[Inject]
|
|
|
+ private $publicServiceClient;
|
|
|
|
|
|
/**
|
|
|
- * 获取所有MinIO存储桶列表
|
|
|
- *
|
|
|
- * @RequestMapping(path="buckets", methods="get")
|
|
|
+ * 获取所有的buckets
|
|
|
+ * @return array
|
|
|
*/
|
|
|
public function listBuckets()
|
|
|
{
|
|
|
- $result = new MinioService();
|
|
|
- // 调用服务层的方法获取存储桶列表
|
|
|
- $bucketsResponse =$result->listBuckets();
|
|
|
+ $result = $this->publicServiceClient->getBuckets([]);
|
|
|
// 直接返回服务层生成的响应
|
|
|
- return Result::success($bucketsResponse);
|
|
|
+ return Result::success($result['data']);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传文件
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function uploadFiles()
|
|
|
+ {
|
|
|
+ $uploadedFile = $this->request->file('file');
|
|
|
+ if ($uploadedFile && $uploadedFile->isValid()) {
|
|
|
+ $filename = $uploadedFile->getClientFilename();
|
|
|
+ $fileContent = base64_encode(file_get_contents($uploadedFile->getRealPath()));
|
|
|
+ $mimeType = $uploadedFile->getMimeType();
|
|
|
+ $data['fileContent'] = $fileContent;
|
|
|
+ $data['fileName'] = $filename;
|
|
|
+ $data['contentType'] = $mimeType;
|
|
|
+ $data['ext'] = $uploadedFile->getExtension();
|
|
|
+ $data['size'] = $uploadedFile->getSize();
|
|
|
+ $result = $this->publicServiceClient->uploadFile($data);
|
|
|
+ if($result['code']==200){
|
|
|
+ return Result::success($result['data']);
|
|
|
+ }else{
|
|
|
+ return Result::error("上传失败了!");
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ return Result::error("请选择需要上传的文件");
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|