|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @remark :
|
|
|
|
* @name :SyncVideo.php
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/8/14 13:50
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Console\Commands\Test;
|
|
|
|
|
|
|
|
use App\Models\File\ErrorFile;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
|
|
|
class SyncVideo extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'sync_video {file}';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = '同步图片与文件';
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$file = $this->argument('file');
|
|
|
|
$file_path = $this->getUrl($file, 0,$this->param['location']);
|
|
|
|
$cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$this->param['path'].'" https://v6-file.globalso.com/upload.php';
|
|
|
|
echo date('Y-m-d H:i:s') . ' | ' . $cmd . PHP_EOL;
|
|
|
|
$code = shell_exec($cmd);
|
|
|
|
if(200 != (int)$code){
|
|
|
|
$errorFileModel = new ErrorFile();
|
|
|
|
$errorFileModel->add(['path'=>$this->param['path'].'/'.$this->param['name']]);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取图片文件链接
|
|
|
|
* @name :getUrl
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/5/22 11:53
|
|
|
|
*/
|
|
|
|
public function getUrl($path,$storage_type,$location){
|
|
|
|
if(is_array($path)){
|
|
|
|
$url =[];
|
|
|
|
foreach ($path as $v){
|
|
|
|
$url[] = $this->getUrl($v,$storage_type,$location);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
if(empty($path)){
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
if((strpos($path,'https://')!== false) || (strpos($path,'http://') !== false)){
|
|
|
|
return $path;
|
|
|
|
}
|
|
|
|
if(substr($path,0,2) == '//'){
|
|
|
|
return 'https:'.$path;
|
|
|
|
}
|
|
|
|
if($location == 0){
|
|
|
|
$cos = config('filesystems.disks.cos');
|
|
|
|
$cosCdn = ($storage_type == 0) ? $cos['cdn'] : $cos['cdn1'];
|
|
|
|
$url = $cosCdn.$path;
|
|
|
|
}else{
|
|
|
|
$s3 = config('filesystems.disks.s3');
|
|
|
|
$cdn = $s3['cdn'];
|
|
|
|
$url = $cdn.$path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $url;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|