作者 lyh

gx

@@ -6,6 +6,8 @@ use App\Enums\Common\Code; @@ -6,6 +6,8 @@ use App\Enums\Common\Code;
6 use App\Helper\Translate; 6 use App\Helper\Translate;
7 use App\Http\Controllers\Controller; 7 use App\Http\Controllers\Controller;
8 use App\Http\Controllers\type; 8 use App\Http\Controllers\type;
  9 +use App\Jobs\CopyProjectJob;
  10 +use App\Jobs\SyncImageFileJob;
9 use App\Models\File\ErrorFile; 11 use App\Models\File\ErrorFile;
10 use App\Models\File\Image as ImageModel; 12 use App\Models\File\Image as ImageModel;
11 use App\Models\Project\Project; 13 use App\Models\Project\Project;
@@ -262,14 +264,14 @@ class ImageController extends Controller @@ -262,14 +264,14 @@ class ImageController extends Controller
262 * @time :2024/4/8 11:10 264 * @time :2024/4/8 11:10
263 */ 265 */
264 public function synchronizationImage($fileName){ 266 public function synchronizationImage($fileName){
265 - //同步到大文件  
266 - $file_path = getImageUrl($this->path.'/'.$fileName,$this->cache['storage_type'] ?? 0);  
267 - $cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$this->path.'" https://v6-file.globalso.com/upload.php';  
268 - $code = shell_exec($cmd);  
269 - if(200 != (int)$code){  
270 - $errorFileModel = new ErrorFile();  
271 - $errorFileModel->add(['path'=>$this->path.'/'.$fileName]);  
272 - } 267 + SyncImageFileJob::dispatch(['path'=>$this->path,'name'=>$fileName]);
  268 +// $file_path = getImageUrl($this->path.'/'.$fileName,$this->cache['storage_type'] ?? 0);
  269 +// $cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$this->path.'" https://v6-file.globalso.com/upload.php';
  270 +// $code = shell_exec($cmd);
  271 +// if(200 != (int)$code){
  272 +// $errorFileModel = new ErrorFile();
  273 +// $errorFileModel->add(['path'=>$this->path.'/'.$fileName]);
  274 +// }
273 return true; 275 return true;
274 } 276 }
275 277
  1 +<?php
  2 +
  3 +namespace App\Jobs;
  4 +
  5 +use App\Events\CopyImageFile;
  6 +use App\Models\File\ErrorFile;
  7 +use App\Models\File\File as FileModel;
  8 +use App\Models\File\Image as ImageModel;
  9 +use App\Services\AmazonS3Service;
  10 +use Illuminate\Bus\Queueable;
  11 +use Illuminate\Contracts\Queue\ShouldQueue;
  12 +use Illuminate\Foundation\Bus\Dispatchable;
  13 +use Illuminate\Queue\InteractsWithQueue;
  14 +use Illuminate\Queue\SerializesModels;
  15 +
  16 +class SyncImageFileJob implements ShouldQueue
  17 +{
  18 + use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  19 + public $tries = 3; // 可配置任务重试次数
  20 +
  21 + protected $param;
  22 +
  23 + /**
  24 + * Create a new job instance.
  25 + *
  26 + * @param CopyImageFile $event
  27 + * @return void
  28 + */
  29 + public function __construct($data)
  30 + {
  31 + $this->param = $data;
  32 + }
  33 +
  34 + /**
  35 + * Execute the job.
  36 + *
  37 + * @return void
  38 + */
  39 + public function handle()
  40 + {
  41 + $file_path = getImageUrl($this->param['path'].'/'.$this->param['name'], 0);
  42 + $cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$this->param['path'].'" https://v6-file.globalso.com/upload.php';
  43 + $code = shell_exec($cmd);
  44 + if(200 != (int)$code){
  45 + $errorFileModel = new ErrorFile();
  46 + $errorFileModel->add(['path'=>$this->param['path'].'/'.$this->param['name']]);
  47 + }
  48 + return true;
  49 + }
  50 +}
@@ -60,6 +60,10 @@ class RouteMap extends Base @@ -60,6 +60,10 @@ class RouteMap extends Base
60 } 60 }
61 $i=1; 61 $i=1;
62 $sign = generateRoute($title); 62 $sign = generateRoute($title);
  63 + $length = strlen($sign);
  64 + if($length > 100){
  65 + $sign = trim(mb_substr($sign, 0, 100, 'UTF-8'),'-');
  66 + }
63 $info = self::where(['project_id' => $project_id, 'source' => $source, 'source_id'=>$source_id])->first(); 67 $info = self::where(['project_id' => $project_id, 'source' => $source, 'source_id'=>$source_id])->first();
64 $suffix = ''; 68 $suffix = '';
65 if(empty($info)){ 69 if(empty($info)){