|
...
|
...
|
@@ -37,55 +37,23 @@ class SyncTimeFiles extends Command |
|
|
|
$lists = $fileModel->list(['created_at'=>['between',[$start,$end]]]);
|
|
|
|
foreach ($lists as $v){
|
|
|
|
$path = $v['path'];
|
|
|
|
$this->param['name'] = basename($path);
|
|
|
|
$this->param['path'] = str_replace('/'.$this->param['name'],'',$path);
|
|
|
|
$file_path = $this->getUrl($this->param['path'].'/'.$this->param['name'], 0,0);
|
|
|
|
$cmd = 'curl -k -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);
|
|
|
|
$code = $this->synchronizationFile($path);
|
|
|
|
if(200 != (int)$code){
|
|
|
|
echo date('Y-m-d H:i:s') . ' | 错误状态:' . $code . PHP_EOL;
|
|
|
|
// $errorFileModel = new ErrorFile();
|
|
|
|
// $errorFileModel->add(['path'=>$this->param['path'].'/'.$this->param['name']]);
|
|
|
|
$errorFileModel = new ErrorFile();
|
|
|
|
$errorFileModel->add(['path'=>$this->param['path'].'/'.$this->param['name']]);
|
|
|
|
}
|
|
|
|
echo date('Y-m-d H:i:s') . ' | ok:' . $code . PHP_EOL;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
public function synchronizationFile($path_name){
|
|
|
|
//同步到大文件
|
|
|
|
$file_path = config('filesystems.disks.cos')['cdn1'].$path_name;
|
|
|
|
$directoryPath = pathinfo($path_name, PATHINFO_DIRNAME);
|
|
|
|
$cmd = 'curl -k -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$directoryPath.'" https://v6-file.globalso.com/upload.php';
|
|
|
|
return shell_exec($cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
} |
...
|
...
|
|