图片缓存
This commit is contained in:
@@ -12,6 +12,7 @@ use app\model\VehicleRu;
|
|||||||
use app\service\OssService;
|
use app\service\OssService;
|
||||||
use plugin\admin\app\common\Util;
|
use plugin\admin\app\common\Util;
|
||||||
use plugin\admin\app\model\Location;
|
use plugin\admin\app\model\Location;
|
||||||
|
use support\Cache;
|
||||||
use support\Log;
|
use support\Log;
|
||||||
use support\Request;
|
use support\Request;
|
||||||
use support\Response;
|
use support\Response;
|
||||||
@@ -485,8 +486,10 @@ class VehicleController extends Crud
|
|||||||
];
|
];
|
||||||
$translations = array_merge($required_translations, $translations);
|
$translations = array_merge($required_translations, $translations);
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = Vehicle::where('id', $id)->first();
|
// $data = Vehicle::where('id', $id)->first();
|
||||||
|
list($vehicleModel,$local) = $this->getModel($lang);
|
||||||
|
$data = $vehicleModel::where('id', $id)->first();
|
||||||
if (!$data) {
|
if (!$data) {
|
||||||
return json(['code' => 1, 'msg' => $translations['data_not_found'] ?? '数据不存在']);
|
return json(['code' => 1, 'msg' => $translations['data_not_found'] ?? '数据不存在']);
|
||||||
}
|
}
|
||||||
@@ -550,6 +553,15 @@ class VehicleController extends Crud
|
|||||||
|
|
||||||
if(!str_starts_with($item['img_url'], 'http')){
|
if(!str_starts_with($item['img_url'], 'http')){
|
||||||
try {
|
try {
|
||||||
|
$img_url = Cache::get('img_dibai_'.$vehicle->id);
|
||||||
|
if ($img_url) {
|
||||||
|
$item['img_url'] = $img_url;
|
||||||
|
} else {
|
||||||
|
$ossservice = new OssService();
|
||||||
|
$img_url = $ossservice->generatePrivateUrl($vehicle['img_url'],86400);
|
||||||
|
$item['img_url'] = $img_url;
|
||||||
|
Cache::set('img_dibai_'.$vehicle->id, $img_url, 86390);
|
||||||
|
}
|
||||||
$ossservice = new OssService();
|
$ossservice = new OssService();
|
||||||
$img_url = $ossservice->generatePrivateUrl($item['img_url']);
|
$img_url = $ossservice->generatePrivateUrl($item['img_url']);
|
||||||
|
|
||||||
@@ -560,7 +572,7 @@ class VehicleController extends Crud
|
|||||||
'generated_url' => $img_url,
|
'generated_url' => $img_url,
|
||||||
'current_time' => time()
|
'current_time' => time()
|
||||||
]);
|
]);
|
||||||
$item['img_url'] = $img_url;
|
// $item['img_url'] = $img_url;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::error("Vehicle image URL generation failed:", [
|
Log::error("Vehicle image URL generation failed:", [
|
||||||
'error' => $e->getMessage(),
|
'error' => $e->getMessage(),
|
||||||
|
|||||||
Reference in New Issue
Block a user