|
...
|
...
|
@@ -3,8 +3,10 @@ |
|
|
|
namespace App\Http\Controllers\File;
|
|
|
|
|
|
|
|
use App\Enums\Common\Code;
|
|
|
|
use App\Helper\Translate;
|
|
|
|
use App\Models\File\ErrorFile;
|
|
|
|
use App\Models\File\File;
|
|
|
|
use App\Models\File\Image as ImageModel;
|
|
|
|
use App\Models\Project\Project;
|
|
|
|
use App\Services\AmazonS3Service;
|
|
|
|
use App\Services\CosService;
|
|
...
|
...
|
@@ -120,7 +122,7 @@ class FileController |
|
|
|
if($file_hash !== false){
|
|
|
|
return $this->response('资源',Code::SUCCESS,$this->responseData($file_hash['path'], $name));
|
|
|
|
}
|
|
|
|
$fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
|
|
|
|
$fileName = $this->getOnlyFilename($name,$param['project_id'] ?? 0);
|
|
|
|
//同步数据到cos
|
|
|
|
if($this->upload_location == 0){
|
|
|
|
$cosService = new CosService();
|
|
...
|
...
|
@@ -155,6 +157,40 @@ class FileController |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取唯一名称
|
|
|
|
* @name :getOnlyFilename
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/4/26 16:10
|
|
|
|
*/
|
|
|
|
public function getOnlyFilename($name,$project_id = 0){
|
|
|
|
$nameArr = explode('.',$name);
|
|
|
|
$enName = generateRoute(Translate::tran($nameArr[0], 'en'));
|
|
|
|
$i=1;
|
|
|
|
while($this->onlyName($enName.'.'.$nameArr[1],$project_id)){
|
|
|
|
$enName = $enName .'-'.$i;
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
return $enName.'.'.$nameArr[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :唯一名称
|
|
|
|
* @name :onlyName
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/4/26 16:21
|
|
|
|
*/
|
|
|
|
public function onlyName($enName,$project_id){
|
|
|
|
$fileModel = new File();
|
|
|
|
$info = $fileModel->read(['project_id' => $project_id, 'en_name' => $enName]);
|
|
|
|
if($info !== false){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 接口上传单文件
|
|
|
|
* @param $files
|
|
|
|
* @return array
|
|
...
|
...
|
@@ -254,7 +290,7 @@ class FileController |
|
|
|
}
|
|
|
|
$url = $this->config['root'].'/'.$this->path;
|
|
|
|
$file_type = $file->getClientOriginalExtension();
|
|
|
|
$fileName = uniqid().rand(10000,99999).'.'.$file_type;
|
|
|
|
$fileName = $this->getOnlyFilename($name,$param['project_id'] ?? 0);
|
|
|
|
//同步数据到cos
|
|
|
|
if($this->upload_location == 0){
|
|
|
|
$cosService = new CosService();
|
...
|
...
|
|