|
...
|
...
|
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\File; |
|
|
|
use App\Enums\Common\Code;
|
|
|
|
use App\Models\File\File;
|
|
|
|
use App\Models\Project\Project;
|
|
|
|
use App\Services\AmazonS3Service;
|
|
|
|
use App\Services\CosService;
|
|
|
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
...
|
...
|
@@ -121,14 +122,13 @@ class FileController |
|
|
|
$url = $this->config['root'].$this->path;
|
|
|
|
$fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
|
|
|
|
//同步数据到cos
|
|
|
|
if($this->upload_location == 1){
|
|
|
|
if($this->upload_location == 0){
|
|
|
|
$cosService = new CosService();
|
|
|
|
$cosService->uploadFile($files,$this->path,$fileName);
|
|
|
|
}else{
|
|
|
|
$res = $files->move($url,$fileName);
|
|
|
|
if ($res === false) {
|
|
|
|
return $this->response($files->getError(), Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
//TODO::上传亚马逊
|
|
|
|
$amazonS3Service = new AmazonS3Service();
|
|
|
|
$amazonS3Service->uploadFiles($files,$this->path,$fileName);
|
|
|
|
}
|
|
|
|
$this->saveMysql($fileModel,$files->getSize(),$files->getClientOriginalExtension(),$fileName,$hash,$this->upload_location,$files->getMimeType(),$name);
|
|
|
|
$this->response('资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName, $name));
|
|
...
|
...
|
@@ -165,7 +165,9 @@ class FileController |
|
|
|
$cosService = new CosService();
|
|
|
|
$cosService->uploadFile($files, $this->path, $fileName);
|
|
|
|
} else {
|
|
|
|
$res = $files->move($url, $fileName);
|
|
|
|
//TODO::上传亚马逊
|
|
|
|
$amazonS3Service = new AmazonS3Service();
|
|
|
|
$res = $amazonS3Service->uploadFiles($files,$this->path,$fileName);
|
|
|
|
if ($res === false) {
|
|
|
|
return [
|
|
|
|
'message' => $files->getError(),
|
|
...
|
...
|
@@ -196,7 +198,7 @@ class FileController |
|
|
|
'hash' => $hash,
|
|
|
|
'type'=>$image_type,
|
|
|
|
'refer'=>$this->param['refer'] ?? 1,
|
|
|
|
'is_cos'=>$is_cos,
|
|
|
|
'is_cos'=>($is_cos == 0) ? 1 : 0,
|
|
|
|
'mime'=>$mime,
|
|
|
|
'project_id'=>$this->cache['project_id'] ?? 0,
|
|
|
|
'name'=>$name,
|
|
...
|
...
|
@@ -234,14 +236,13 @@ class FileController |
|
|
|
$file_type = $file->getClientOriginalExtension();
|
|
|
|
$fileName = uniqid().rand(10000,99999).'.'.$file_type;
|
|
|
|
//同步数据到cos
|
|
|
|
if($this->upload_location == 1){
|
|
|
|
if($this->upload_location == 0){
|
|
|
|
$cosService = new CosService();
|
|
|
|
$cosService->uploadFile($files,$this->path,$fileName);
|
|
|
|
}else{
|
|
|
|
$res = $files->move($url,$fileName);
|
|
|
|
if ($res === false) {
|
|
|
|
return $this->response($files->getError(), Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
//TODO::上传亚马逊
|
|
|
|
$amazonS3Service = new AmazonS3Service();
|
|
|
|
$amazonS3Service->uploadFiles($files,$this->path,$fileName);
|
|
|
|
}
|
|
|
|
$size = $file->getSize();
|
|
|
|
$mime = $file->getMimeType();
|
|
...
|
...
|
@@ -313,7 +314,7 @@ class FileController |
|
|
|
$projectModel = new Project();
|
|
|
|
$project_info = $projectModel->read(['id' => $this->cache['project_id']], ['project_location']);
|
|
|
|
if ($project_info['project_location'] != 0) {//通项目时 上传到cos
|
|
|
|
$this->upload_location = 0;//1:上传到本地
|
|
|
|
$this->upload_location = 1;//1:上传到本地
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->path = $this->uploads['path_b'].'/'.$this->cache['project_id'].'/'.$this->file_type[$this->param['refer']].'/'.date('Y-m');
|
|
...
|
...
|
@@ -335,7 +336,7 @@ class FileController |
|
|
|
$fileModel = new File();
|
|
|
|
$lists = $fileModel->list($this->map,'id',['id','hash','type','path','created_at','name']);
|
|
|
|
foreach ($lists as $k => $v){
|
|
|
|
$v['file_link'] = getFileUrl($v['path']);
|
|
|
|
$v['file_link'] = getFileUrl($v['path'],$this->cache['project_location'] ?? 0,$this->cache['storage_type'] ?? 0);
|
|
|
|
$lists[$k] = $v;
|
|
|
|
}
|
|
|
|
$this->response('success',Code::SUCCESS,$lists);
|
|
...
|
...
|
@@ -351,7 +352,7 @@ class FileController |
|
|
|
public function responseData($path, $name){
|
|
|
|
$data = [
|
|
|
|
'file'=>$path,
|
|
|
|
'file_link'=>getFileUrl($path,$this->upload_location),
|
|
|
|
'file_link'=>getFileUrl($path,$this->cache['project_location'] ?? 0,$this->cache['storage_type'] ?? 0),
|
|
|
|
'name'=>$name,
|
|
|
|
'file_download'=>url('a/download_files?path='.$path)
|
|
|
|
];
|
...
|
...
|
|