作者 刘锟

upload_remote

... ... @@ -324,22 +324,4 @@ class FileController
$data = ['file_download'=>url('a/download_files?path='.$info['path'])];
$this->response('success',Code::SUCCESS,$data);
}
/**
* 根据远程图片地址上传
* @param $file_url
* @return JsonResponse
* @author Akun
* @date 2023/09/21 9:40
*/
public function upRemoteUrl($file_url){
$ext = explode('.',$file_url);
$fileName = uniqid().rand(10000,99999).'.'.end($ext);
//同步数据到cos
$cosService = new CosService();
$cosService->uploadRemote($file_url,$this->path,$fileName);
return $this->response('资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName));
}
}
... ...
... ... @@ -8,6 +8,7 @@ use App\Http\Logic\Bside\BaseLogic;
use App\Models\News\News;
use App\Models\News\NewsCategory as NewsCategoryModel;
use App\Models\RouteMap\RouteMap;
use App\Services\CosService;
use Illuminate\Support\Facades\DB;
use mysql_xdevapi\Exception;
... ... @@ -275,15 +276,15 @@ class NewsLogic extends BaseLogic
$category_id = $newsCategoryLogic->importNewsCategory($project_id, $user_id, $data[2]);
}
$news = $this->model->read(['name'=>$data[0]]);
if(!$news){
$news = $this->model->read(['name' => $data[0]]);
if (!$news) {
$id = $this->model->addReturnId(
[
'name' => $data[0],
'category_id' => $category_id,
'text' => $data[4],
'remark' => $data[3],
'image' => '',//TODO: 远程图片下载本地
'image' => CosService::uploadRemote($project_id, 'image_news', $data[5]),
'seo_title' => $data[6],
'seo_keywords' => $data[7],
'seo_description' => $data[8],
... ... @@ -293,7 +294,7 @@ class NewsLogic extends BaseLogic
]
);
//更新路由
$route = RouteMap::setRoute($data[0], RouteMap::SOURCE_NEWS, $id, $project_id);
$route = RouteMap::setRoute($data[1] ?: $data[0], RouteMap::SOURCE_NEWS, $id, $project_id);
$this->edit(['url' => $route], ['id' => $id]);
return true;
... ...
... ... @@ -64,15 +64,21 @@ class CosService
/**
* 根据远程图片地址上传
* @param $project_id
* @param $image_type
* @param $file_url
* @param $path
* @param $filename
* @return string
* @author Akun
* @date 2023/09/21 9:39
*/
public function uploadRemote($file_url,$path,$filename)
public static function uploadRemote($project_id,$image_type,$file_url)
{
$ext = explode('.',$file_url);
$filename = uniqid().rand(10000,99999).'.'.end($ext);
$uploads = config('upload.default_file');
$path = $uploads['path_b'].'/'.$project_id.'/'.$image_type.'/'.date('Y-m');
$cos = config('filesystems.disks.cos');
$cosClient = new Client([
'region' => $cos['region'],
... ...
... ... @@ -363,6 +363,4 @@ Route::group([], function () {
Route::any('/qrcode', [\App\Http\Controllers\Bside\LoginController::class, 'qrcode'])->name('qrcode');
Route::any('/globalSo_v6_login', [\App\Http\Controllers\Bside\LoginController::class, 'globalSo_v6_login'])->name('globalSo_v6_login');
Route::any('/getWechatLoginInfo', [\App\Http\Controllers\Bside\LoginController::class, 'getWechatLoginInfo'])->name('getWechatLoginInfo');
Route::post('/upload_remote', [\App\Http\Controllers\File\FileController::class, 'upRemoteUrl'])->name('remote_file_upload');
});
... ...