作者 李宇航

合并分支 'develop' 到 'master'

更新图片文件生成名称规则,同时更新同步s3数据查看



查看合并请求 !511
... ... @@ -125,7 +125,8 @@ class Demo extends Command
if(!empty($fileList)){
$amazonS3Service = new AmazonS3Service();
foreach ($fileList as $k => $v){
$amazonS3Service->syncImageFiles(getImageUrl($v['path']));
echo date('Y-m-d H:i:s') . '执行的数据id:' . $v['id'] . '名称:'.$v['name'] . PHP_EOL;
$amazonS3Service->syncImageFiles(getFileUrl($v['path']));
$fileModel->edit(['is_cos'=>0],['id'=>$v['id']]);
}
}
... ...
... ... @@ -4,7 +4,9 @@ namespace App\Http\Controllers\Bside\FileManage;
use App\Enums\Common\Code;
use App\Helper\Translate;
use App\Http\Controllers\Bside\BaseController;
use App\Models\File\File;
use App\Models\FileManage\FileManage;
use App\Models\Project\Project;
use App\Services\CosService;
... ... @@ -79,18 +81,14 @@ class FileManageController extends BaseController
'file.required'=>'请上传文件',
]);
$file = $request->file('file');
$data = $this->checkFile($file);
$path = '/file_manage/' . $this->user['project_id'] . '/' . date('Ymd');
$fileName = uniqid().rand(10000,99999).'.'.$file->getClientOriginalExtension();
$name = $file->getClientOriginalName();
$fileName = $this->getOnlyFilename($name,$this->user['project_id']);
$cosService = new CosService();
$cosService->uploadFile($file,$path,$fileName);
$data['project_id'] = $this->user['project_id'];
$data['path'] = $path.'/'.$fileName;
$rs = $fileManage->add($data);
if ($rs === false) {
$this->fail('上传失败');
... ... @@ -98,6 +96,41 @@ class FileManageController extends BaseController
$this->response('success');
}
/**
* @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 FileManage();
$info = $fileModel->read(['project_id' => $project_id, 'en_name' => $enName]);
if($info !== false){
return true;
}
return false;
}
protected function checkFile($file){
$count = FileManage::where('project_id', $this->user['project_id'])->count();
if($count >= $this->upload_config['upload_max_num']){
... ...
... ... @@ -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();
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Http\Controllers\File;
use App\Enums\Common\Code;
use App\Helper\Translate;
use App\Http\Controllers\Controller;
use App\Http\Controllers\type;
use App\Models\File\ErrorFile;
... ... @@ -200,7 +201,7 @@ class ImageController extends Controller
if(strlen($image_type) > 7){
$this->response('不支持当前格式',Code::SYSTEM_ERROR);
}
$fileName = uniqid().rand(10000,99999).'.'.$image_type;
$fileName = $this->getOnlyFilename($name,$param['project_id'] ?? 0);
//上传到cos
if($this->upload_location == 0){
$cosService = new CosService();
... ... @@ -216,6 +217,41 @@ class ImageController extends Controller
}
/**
* @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){
$imageModel = new ImageModel();
$info = $imageModel->read(['project_id' => $project_id, 'en_name' => $enName]);
if($info !== false){
return true;
}
return false;
}
/**
* @remark :指定同步文件到獨立177服務器
* @name :synchronizationFile
* @author :lyh
... ... @@ -299,7 +335,7 @@ class ImageController extends Controller
continue;
}
$image_type = $file->getClientOriginalExtension();
$fileName = uniqid().rand(10000,99999).'.'.$image_type;
$fileName = $this->getOnlyFilename($name,$param['project_id'] ?? 0);
//同步数据到cos
if($this->upload_location == 0){
$cosService = new CosService();
... ...
... ... @@ -53,7 +53,7 @@ class CopyImageFileJob implements ShouldQueue
if(!empty($fileList)){
$amazonS3Service = new AmazonS3Service();
foreach ($fileList as $k => $v){
$amazonS3Service->syncImageFiles(getImageUrl($v['path']));
$amazonS3Service->syncImageFiles(getFileUrl($v['path']));
$fileModel->edit(['is_cos'=>0],['id'=>$v['id']]);
}
}
... ...