作者 李宇航

合并分支 'master-server' 到 'master'

合并水印功能



查看合并请求 !717
@@ -32,7 +32,7 @@ class SyncTimeFiles extends Command @@ -32,7 +32,7 @@ class SyncTimeFiles extends Command
32 public function handle() 32 public function handle()
33 { 33 {
34 $fileModel = new File(); 34 $fileModel = new File();
35 - $start = '2024-08-10 00:00:00'; 35 + $start = '2024-08-26 00:00:00';
36 $end = date('Y-m-d H:i:s'); 36 $end = date('Y-m-d H:i:s');
37 $lists = $fileModel->list(['created_at'=>['between',[$start,$end]]]); 37 $lists = $fileModel->list(['created_at'=>['between',[$start,$end]]]);
38 foreach ($lists as $v){ 38 foreach ($lists as $v){
@@ -207,8 +207,9 @@ class ImageController extends Controller @@ -207,8 +207,9 @@ class ImageController extends Controller
207 $fileName = $this->getOnlyFilename($name,$param['project_id'] ?? 0); 207 $fileName = $this->getOnlyFilename($name,$param['project_id'] ?? 0);
208 //上传到cos 208 //上传到cos
209 if($this->upload_location == 0){ 209 if($this->upload_location == 0){
  210 + $watermarkOptions = $this->getProjectConfig($this->cache['project_id'] ?? 0);
210 $cosService = new CosService(); 211 $cosService = new CosService();
211 - $cosService->uploadFile($files,$this->path,$fileName); 212 + $cosService->uploadFile($files,$this->path,$fileName,false,$watermarkOptions);
212 }else{ 213 }else{
213 //TODO::上传亚马逊 214 //TODO::上传亚马逊
214 $amazonS3Service = new AmazonS3Service(); 215 $amazonS3Service = new AmazonS3Service();
@@ -342,7 +343,7 @@ class ImageController extends Controller @@ -342,7 +343,7 @@ class ImageController extends Controller
342 if($this->upload_location == 0){ 343 if($this->upload_location == 0){
343 $watermarkOptions = $this->getProjectConfig($this->cache['project_id'] ?? 0); 344 $watermarkOptions = $this->getProjectConfig($this->cache['project_id'] ?? 0);
344 $cosService = new CosService(); 345 $cosService = new CosService();
345 - $cosService->uploadFile($file,$this->path,$fileName,$watermarkOptions); 346 + $cosService->uploadFile($file,$this->path,$fileName,false,$watermarkOptions);
346 }else{ 347 }else{
347 //TODO::上传亚马逊 348 //TODO::上传亚马逊
348 $amazonS3Service = new AmazonS3Service(); 349 $amazonS3Service = new AmazonS3Service();
@@ -365,37 +366,44 @@ class ImageController extends Controller @@ -365,37 +366,44 @@ class ImageController extends Controller
365 * @time :2024/8/24 11:03 366 * @time :2024/8/24 11:03
366 */ 367 */
367 public function getProjectConfig($project_id = 0){ 368 public function getProjectConfig($project_id = 0){
  369 + $str = '';
368 $imageSettingModel = new ImageSetting(); 370 $imageSettingModel = new ImageSetting();
369 $settingInfo = $imageSettingModel->read(['project_id'=>$project_id]); 371 $settingInfo = $imageSettingModel->read(['project_id'=>$project_id]);
370 if($settingInfo !== false){ 372 if($settingInfo !== false){
371 if($settingInfo['status'] == 1 && !empty($settingInfo['image_data'])){ 373 if($settingInfo['status'] == 1 && !empty($settingInfo['image_data'])){
372 $image_data = json_decode($settingInfo['image_data'],true); 374 $image_data = json_decode($settingInfo['image_data'],true);
373 foreach ($image_data as $k => $v){ 375 foreach ($image_data as $k => $v){
374 - $arr = implode('/',$v);  
375 - if ($arr[0] == 'image') {  
376 - $arr[1] = urlSafeBase64Encode($arr[1]); 376 + if (str_starts_with($v, "image/")) {
  377 + $v = 'image/'.urlSafeBase64Encode(substr($v, strlen("image/")));
377 } 378 }
378 $image_data[$k] = $v; 379 $image_data[$k] = $v;
379 } 380 }
  381 + $str = 'watermark/1/'.implode('/',$image_data);
  382 + return $str;
380 } 383 }
381 if($settingInfo['status'] == 2 && !empty($settingInfo['str_data'])){ 384 if($settingInfo['status'] == 2 && !empty($settingInfo['str_data'])){
382 $str_data = json_decode($settingInfo['str_data'],true); 385 $str_data = json_decode($settingInfo['str_data'],true);
383 foreach ($str_data as $k => $v){ 386 foreach ($str_data as $k => $v){
384 - $arr = implode('/',$v); 387 + $arr = explode('/',$v);
385 if ($arr[0] == 'text') { 388 if ($arr[0] == 'text') {
386 $arr[1] = urlSafeBase64Encode($arr[1]); 389 $arr[1] = urlSafeBase64Encode($arr[1]);
  390 + $v = implode('/',$arr);
387 } 391 }
388 if ($arr[0] == 'font') { 392 if ($arr[0] == 'font') {
389 $arr[1] = urlSafeBase64Encode($arr[1]); 393 $arr[1] = urlSafeBase64Encode($arr[1]);
  394 + $v = implode('/',$arr);
390 } 395 }
391 if ($arr[0] == 'fill') { 396 if ($arr[0] == 'fill') {
392 $arr[1] = urlSafeBase64Encode($arr[1]); 397 $arr[1] = urlSafeBase64Encode($arr[1]);
  398 + $v = implode('/',$arr);
393 } 399 }
394 - $str_data[$k] = $arr; 400 + $str_data[$k] = $v;
395 } 401 }
396 } 402 }
  403 + $str = 'watermark/2/'.implode('/',$str_data);
  404 + return $str;
397 } 405 }
398 - return null; 406 + return $str;
399 } 407 }
400 408
401 /** 409 /**
@@ -726,10 +734,10 @@ class ImageController extends Controller @@ -726,10 +734,10 @@ class ImageController extends Controller
726 if($info === false){ 734 if($info === false){
727 $this->response('请先设置水印',Code::SYSTEM_ERROR); 735 $this->response('请先设置水印',Code::SYSTEM_ERROR);
728 } 736 }
729 - if($info['status'] == 1 && !empty($info['image_data'])){ 737 + if($info['status'] == 1 && empty($info['image_data'])){
730 $this->response('请先设置水印',Code::SYSTEM_ERROR); 738 $this->response('请先设置水印',Code::SYSTEM_ERROR);
731 } 739 }
732 - if($info['status'] == 2 && !empty($info['str_data'])){ 740 + if($info['status'] == 2 && empty($info['str_data'])){
733 $this->response('请先设置水印',Code::SYSTEM_ERROR); 741 $this->response('请先设置水印',Code::SYSTEM_ERROR);
734 } 742 }
735 $imageSetting->edit(['status'=>$this->param['status']],['project_id'=>$this->cache['project_id']]); 743 $imageSetting->edit(['status'=>$this->param['status']],['project_id'=>$this->cache['project_id']]);
@@ -753,7 +761,9 @@ class ImageController extends Controller @@ -753,7 +761,9 @@ class ImageController extends Controller
753 if(!empty($info['str_data'])){ 761 if(!empty($info['str_data'])){
754 $info['str_data'] = json_decode($info['str_data'],true); 762 $info['str_data'] = json_decode($info['str_data'],true);
755 } 763 }
  764 + $info['domain'] = 'http://globalso-v6-1309677403.cos.ap-hongkong.myqcloud.com';
756 } 765 }
  766 +
757 $this->response('success',Code::SUCCESS,$info); 767 $this->response('success',Code::SUCCESS,$info);
758 } 768 }
759 } 769 }
@@ -23,7 +23,7 @@ class CosService @@ -23,7 +23,7 @@ class CosService
23 * @method :post 23 * @method :post
24 * @time :2023/7/19 15:28 24 * @time :2023/7/19 15:28
25 */ 25 */
26 - public function uploadFile(&$files,$path,$filename, $binary = false,$watermarkOptions = null) 26 + public function uploadFile(&$files,$path,$filename, $binary = false,$watermarkOptions = '')
27 { 27 {
28 $cos = config('filesystems.disks.cos'); 28 $cos = config('filesystems.disks.cos');
29 $cosClient = new Client([ 29 $cosClient = new Client([
@@ -42,18 +42,18 @@ class CosService @@ -42,18 +42,18 @@ class CosService
42 ]; 42 ];
43 //水印 43 //水印
44 if ($watermarkOptions) { 44 if ($watermarkOptions) {
45 - $options['Pic-Operations'] = json_encode([ 45 + $options['PicOperations'] = json_encode([
46 'is_pic_info' => 1, 46 'is_pic_info' => 1,
47 'rules' => [ 47 'rules' => [
48 [ 48 [
49 - 'fileid' => $filename, // 使用相同的文件名保存  
50 - 'rule' => 'watermark/1/'.implode('/',$watermarkOptions), 49 + 'fileid' => $key, // 使用相同的文件名保存
  50 + 'rule' => $watermarkOptions,
51 ] 51 ]
52 ] 52 ]
53 - ]); 53 + ], true);
54 } 54 }
55 - // 上传文件  
56 - $cosClient->putObject($options); 55 + $res = $cosClient->putObject($options);
  56 + @file_put_contents(storage_path('logs/lyh_error.log'), var_export($res, true) . PHP_EOL, FILE_APPEND);
57 return $key; 57 return $key;
58 } 58 }
59 59