This commit is contained in:
2025-06-30 14:34:23 +08:00
parent e5a4df1bc0
commit 73e3e7ab5b
3 changed files with 41 additions and 0 deletions
+15
View File
@@ -76,6 +76,21 @@ class ArticleService extends BaseService
$num = $params['num'] ?? 0; $num = $params['num'] ?? 0;
unset($params['num']); unset($params['num']);
// 将OSS直连地址替换为代理地址
$ossDomain = 'https://vehicle-album.oss-cn-beijing.aliyuncs.com/';
$proxyPath = '/console/upload/image/proxy?file=';
$params['content'] = str_replace(
'?Expires=',
'&Expires=',
$params['content']
);
$params['content'] = str_replace(
$ossDomain,
$proxyPath,
$params['content']
);
Db::beginTransaction(); Db::beginTransaction();
try { try {
$info = $this->create($params); $info = $this->create($params);
@@ -65,4 +65,26 @@ class UploadController
return $this->errorResponse($e->getMessage()); return $this->errorResponse($e->getMessage());
} }
} }
public function proxy(Request $request)
{
$filePath = $request->get('file'); // 原OSS文件路径
try {
// 生成签名URL
$signedUrl = (new \app\mzl\modules\upload\service\OssService())->generatePrivateUrl($filePath);
// 获取图片数据并返回
$imageData = file_get_contents($signedUrl);
// 根据文件类型设置Content-Type
$mime = mime_content_type('data://application/octet-stream;base64,'.base64_encode($imageData));
return response($imageData, 200, [
'Content-Type' => $mime,
'Cache-Control' => 'public, max-age=600' // 客户端缓存10分钟
]);
} catch (\Exception $e) {
return response('Image not found '.$e->getMessage(), 404);
}
}
} }
+4
View File
@@ -55,6 +55,9 @@ Route::group('/apis', function() {
//文章列表 //文章列表
Route::any('/article/list', [\app\apis\controller\ArticleController::class, 'index']); Route::any('/article/list', [\app\apis\controller\ArticleController::class, 'index']);
Route::any('/article/{id}/detail', [\app\apis\controller\ArticleController::class, 'detail']); Route::any('/article/{id}/detail', [\app\apis\controller\ArticleController::class, 'detail']);
//图片代理
Route::any('/upload/image/proxy', [\app\mzl\modules\upload\controller\UploadController::class, 'proxy']);
}); });
// ====== ====== ====== 网站 ====== ====== ====== // ====== ====== ====== 网站 ====== ====== ======
@@ -192,6 +195,7 @@ Route::group('/console', function() {
// 上传 // 上传
Route::any('/upload/image', [\app\mzl\modules\upload\controller\UploadController::class, 'uploadImage']); Route::any('/upload/image', [\app\mzl\modules\upload\controller\UploadController::class, 'uploadImage']);
Route::any('/upload/image/proxy', [\app\mzl\modules\upload\controller\UploadController::class, 'proxy']);
// 型号管理 // 型号管理
Route::any('/models/list', [\app\console\controller\ModelController::class, 'index']); Route::any('/models/list', [\app\console\controller\ModelController::class, 'index']);