作者 邓超

Merge branch 'develop' into dc

... ... @@ -104,21 +104,12 @@ class BaseController extends Controller
*/
public function response($msg = null,string $code = Code::SUCCESS,$data = [],$result_code = 200,$type = 'application/json'): JsonResponse
{
try {
$code = Code::fromValue($code);
$result = [
'msg' => $msg == ' ' ? $code->description : $msg,
'code' => $code->value,
'data' => $this->_extents($data),
];
}catch (\Throwable $e){
$result = [
'msg' => $msg,
'code' => $code,
'data' => $this->_extents($data),
];
}
$code = Code::fromValue($code);
$result = [
'msg' => $msg == ' ' ? $code->description : $msg,
'code' => $code->value,
'data' => $this->_extents($data),
];
$this->header['Content-Type'] = $type;
$this->header['token'] = $this->token;
$response = response($result,$result_code,$this->header);;
... ...
... ... @@ -4,9 +4,7 @@ namespace App\Http\Controllers\file;
use App\Enums\Common\Code;
use App\Http\Controllers\type;
use App\Http\Controllers\统一返回参数;
use App\Models\File\Image as ImageModel;
use App\Models\User\User as UserModel;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Storage;
... ... @@ -43,7 +41,7 @@ class ImageController
$this->path = $this->config['root'].$this->uploads['path'].'/';
}
public function index($hash = '',$type = self::TYPE, $w = 0 ,$h = 0 ){
public function index($hash = '', $w = 0 ,$h = 0 ){
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) || isset($_SERVER['HTTP_IF_NONE_MATCH'])) {
header("HTTP/1.1 304 Not Modified");
exit;
... ... @@ -54,12 +52,11 @@ class ImageController
$this->response('指定图片不存在!', Code::USER_ERROR);
}
//查看缩略图是否存在
$header['Content-Type'] = 'image/'.$info['type'];
$filename = $this->path . $info['hash'] . $w . '_' . $h;
if(is_file($filename)){
$last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT";
$header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'],
[$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 2, $last_modified_time], $this->upload_img['header']);
[$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 1, $last_modified_time], $this->upload_img['header']);
$content = file_get_contents($filename);
$header['Content-Length'] = $info['size'];
}else{
... ... @@ -70,24 +67,20 @@ class ImageController
$content = '';
$last_modified_time = gmdate(time() + ((30 * 60 * 60 * 24))) . " GMT";
$header = str_replace(['%Expires%', "%etag%", '%Last-Modified%'],
[$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 2, $last_modified_time], $this->upload_img['header']);
[$last_modified_time, $hash . ':' . $w . '_' . $h . '_' . 1, $last_modified_time], $this->upload_img['header']);
if ($w > 0 && $h > 0) {
$path = $this->cacheImage($info, $w, $h);
$content = file_get_contents($path);
$header['Content-Length'] = strlen($content);
} else {
$content = file_get_contents($path);
$header['Content-Length'] = $info['size'];
$header['Content-Length'] = strlen($content);
}
}
$header['Content-Type'] = 'image/'.$info['type'];
$img_type = $info['type'];
$content = base64_encode($content);
$img_base64 = 'data:image/' . $img_type . ';base64,' . $content;
if($type != self::TYPE){
header('Content-Type: image/' . $img_type);
echo base64_decode($content);
exit;
}
return response($img_base64,200,$header);
}
... ...
... ... @@ -30,10 +30,10 @@ class LoginAuthMiddleware
return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']);
}
// 设置数据信息
$project = ProjectServer::useProject($info['project_id']);
if(empty($project)){
return response(['code'=>Code::USER_ERROR,'msg'=>'数据库未配置']);
}
// $project = ProjectServer::useProject($info['project_id']);
// if(empty($project)){
// return response(['code'=>Code::USER_ERROR,'msg'=>'数据库未配置']);
// }
//操作权限设置
$projectRoleModel = new ProjectRoleModel();
$role_info = $projectRoleModel->read(['id'=>$info['role_id']]);
... ...
... ... @@ -260,6 +260,6 @@ Route::group([], function () {
Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login');
// Route::any('/', [\App\Http\Controllers\Bside\ComController::class, 'get_country'])->name('get_country');
Route::get('/file/download', [\App\Http\Controllers\Bside\FileController::class, 'download'])->name('file_download');
Route::any('/image/{hash}/{type?}/{w?}/{h?}', [\App\Http\Controllers\file\ImageController::class,'index'])->name('image_show');
Route::any('/image/{hash}/{w?}/{h?}', [\App\Http\Controllers\file\ImageController::class,'index'])->name('image_show');
Route::any('/file_hash/{hash}/', [\App\Http\Controllers\file\FileController::class,'index'])->name('file_show');
});
... ...