Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into develop
正在显示
4 个修改的文件
包含
111 行增加
和
41 行删除
| @@ -4,7 +4,6 @@ namespace App\Http\Controllers\File; | @@ -4,7 +4,6 @@ namespace App\Http\Controllers\File; | ||
| 4 | 4 | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | use App\Models\File\File; | 6 | use App\Models\File\File; |
| 7 | -use App\Models\File\Image as ImageModel; | ||
| 8 | use App\Models\Project\Project; | 7 | use App\Models\Project\Project; |
| 9 | use App\Services\CosService; | 8 | use App\Services\CosService; |
| 10 | use Illuminate\Http\Exceptions\HttpResponseException; | 9 | use Illuminate\Http\Exceptions\HttpResponseException; |
| @@ -114,7 +113,6 @@ class FileController | @@ -114,7 +113,6 @@ class FileController | ||
| 114 | } | 113 | } |
| 115 | 114 | ||
| 116 | /** | 115 | /** |
| 117 | - * @param $files | ||
| 118 | * @remark :单文件上传 | 116 | * @remark :单文件上传 |
| 119 | * @name :single | 117 | * @name :single |
| 120 | * @author :lyh | 118 | * @author :lyh |
| @@ -127,10 +125,10 @@ class FileController | @@ -127,10 +125,10 @@ class FileController | ||
| 127 | $fileModel = new File(); | 125 | $fileModel = new File(); |
| 128 | $file_hash = $fileModel->read(['hash'=>$hash]); | 126 | $file_hash = $fileModel->read(['hash'=>$hash]); |
| 129 | if($file_hash !== false){ | 127 | if($file_hash !== false){ |
| 130 | - return $this->response('资源',Code::SUCCESS,['file'=>$hash,'file_link'=>$this->getFileUrl($fileModel,$hash)]); | 128 | + return $this->response('资源',Code::SUCCESS,$this->responseData($fileModel,$hash)); |
| 131 | } | 129 | } |
| 132 | $url = $this->config['root'].$this->path; | 130 | $url = $this->config['root'].$this->path; |
| 133 | - $fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension(); | 131 | + $fileName = uniqid().rand(10000,99999).'.'.$file_type; |
| 134 | //同步数据到cos | 132 | //同步数据到cos |
| 135 | if($this->upload_location == 1){ | 133 | if($this->upload_location == 1){ |
| 136 | $cosService = new CosService(); | 134 | $cosService = new CosService(); |
| @@ -142,7 +140,7 @@ class FileController | @@ -142,7 +140,7 @@ class FileController | ||
| 142 | } | 140 | } |
| 143 | } | 141 | } |
| 144 | $this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location); | 142 | $this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location); |
| 145 | - return $this->response('资源',Code::SUCCESS,['file'=>$hash,'file_link'=>$this->getFileUrl($fileModel,$hash)]); | 143 | + return $this->response('资源',Code::SUCCESS,$this->responseData($fileModel,$hash)); |
| 146 | } | 144 | } |
| 147 | 145 | ||
| 148 | /** | 146 | /** |
| @@ -170,7 +168,6 @@ class FileController | @@ -170,7 +168,6 @@ class FileController | ||
| 170 | } | 168 | } |
| 171 | 169 | ||
| 172 | /** | 170 | /** |
| 173 | - * @param $files | ||
| 174 | * @remark :多文件上传(暂时未用) | 171 | * @remark :多文件上传(暂时未用) |
| 175 | * @name :multi | 172 | * @name :multi |
| 176 | * @author :lyh | 173 | * @author :lyh |
| @@ -184,11 +181,12 @@ class FileController | @@ -184,11 +181,12 @@ class FileController | ||
| 184 | $hash = hash_file('md5', $file->getPathname()); | 181 | $hash = hash_file('md5', $file->getPathname()); |
| 185 | $file_hash = $fileModel->read(['hash'=>$hash]); | 182 | $file_hash = $fileModel->read(['hash'=>$hash]); |
| 186 | if($file_hash !== false){ | 183 | if($file_hash !== false){ |
| 187 | - $data[] = ['file'=>$hash,'file_link'=>$this->getFileUrl($fileModel,$hash)]; | 184 | + $data[] = $this->responseData($fileModel,$hash); |
| 188 | continue; | 185 | continue; |
| 189 | } | 186 | } |
| 190 | $url = $this->config['root'].'/'.$this->path; | 187 | $url = $this->config['root'].'/'.$this->path; |
| 191 | - $fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension(); | 188 | + $file_type = $file->getClientOriginalExtension(); |
| 189 | + $fileName = uniqid().rand(10000,99999).'.'.$file_type; | ||
| 192 | //同步数据到cos | 190 | //同步数据到cos |
| 193 | if($this->upload_location == 1){ | 191 | if($this->upload_location == 1){ |
| 194 | $cosService = new CosService(); | 192 | $cosService = new CosService(); |
| @@ -200,20 +198,14 @@ class FileController | @@ -200,20 +198,14 @@ class FileController | ||
| 200 | } | 198 | } |
| 201 | } | 199 | } |
| 202 | $size = $file->getSize(); | 200 | $size = $file->getSize(); |
| 203 | - $file_type = $file->getClientOriginalExtension(); | ||
| 204 | $this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location); | 201 | $this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location); |
| 205 | - $data[] = ['file'=>$hash,'file_link'=>$this->getFileUrl($fileModel,$hash)]; | 202 | + $data[] = $this->responseData($fileModel,$hash); |
| 206 | } | 203 | } |
| 207 | - return $this->response('资源',Code::SUCCESS,$data); | 204 | + $this->response('资源',Code::SUCCESS,$data); |
| 208 | } | 205 | } |
| 209 | 206 | ||
| 210 | 207 | ||
| 211 | /** | 208 | /** |
| 212 | - * @param $msg | ||
| 213 | - * @param string $code | ||
| 214 | - * @param $data | ||
| 215 | - * @param $result_code | ||
| 216 | - * @param $type | ||
| 217 | * @remark :统一返回接口 | 209 | * @remark :统一返回接口 |
| 218 | * @name :response | 210 | * @name :response |
| 219 | * @author :lyh | 211 | * @author :lyh |
| @@ -326,4 +318,37 @@ class FileController | @@ -326,4 +318,37 @@ class FileController | ||
| 326 | } | 318 | } |
| 327 | $this->response('success',Code::SUCCESS,$lists); | 319 | $this->response('success',Code::SUCCESS,$lists); |
| 328 | } | 320 | } |
| 321 | + | ||
| 322 | + /** | ||
| 323 | + * @remark :统一返回参数处理 | ||
| 324 | + * @name :responseData | ||
| 325 | + * @author :lyh | ||
| 326 | + * @method :post | ||
| 327 | + * @time :2023/7/26 13:41 | ||
| 328 | + */ | ||
| 329 | + public function responseData(&$fileModel,$hash){ | ||
| 330 | + $data = [ | ||
| 331 | + 'file'=>$hash, | ||
| 332 | + 'file_link'=>$this->getFileUrl($fileModel,$hash), | ||
| 333 | + 'file_download'=>url('a/download/files?hash='.$hash), | ||
| 334 | + ]; | ||
| 335 | + return $data; | ||
| 336 | + } | ||
| 337 | + | ||
| 338 | + /** | ||
| 339 | + * @remark :获取下载链接 | ||
| 340 | + * @name :getDownloadUrl | ||
| 341 | + * @author :lyh | ||
| 342 | + * @method :post | ||
| 343 | + * @time :2023/7/26 14:00 | ||
| 344 | + */ | ||
| 345 | + public function getDownloadUrl(){ | ||
| 346 | + $fileModel = new File(); | ||
| 347 | + $info = $fileModel->read(['hash' => $this->param['hash']]); | ||
| 348 | + if ($info === false) { | ||
| 349 | + $this->response('指定文件不存在!', Code::USER_ERROR); | ||
| 350 | + } | ||
| 351 | + $data = ['file_download'=>url('a/downLoad/files?hash='.$this->param['hash'])]; | ||
| 352 | + $this->response('success',Code::SUCCESS,$data); | ||
| 353 | + } | ||
| 329 | } | 354 | } |
| @@ -12,7 +12,6 @@ use App\Services\TencentCosService; | @@ -12,7 +12,6 @@ use App\Services\TencentCosService; | ||
| 12 | use Illuminate\Http\Exceptions\HttpResponseException; | 12 | use Illuminate\Http\Exceptions\HttpResponseException; |
| 13 | use Illuminate\Http\JsonResponse; | 13 | use Illuminate\Http\JsonResponse; |
| 14 | use Illuminate\Support\Facades\Cache; | 14 | use Illuminate\Support\Facades\Cache; |
| 15 | -use Illuminate\Support\Facades\Storage; | ||
| 16 | use Intervention\Image\Facades\Image; | 15 | use Intervention\Image\Facades\Image; |
| 17 | 16 | ||
| 18 | class ImageController extends Controller | 17 | class ImageController extends Controller |
| @@ -62,9 +61,6 @@ class ImageController extends Controller | @@ -62,9 +61,6 @@ class ImageController extends Controller | ||
| 62 | } | 61 | } |
| 63 | 62 | ||
| 64 | /** | 63 | /** |
| 65 | - * @param $hash | ||
| 66 | - * @param $w | ||
| 67 | - * @param $h | ||
| 68 | * @name :index | 64 | * @name :index |
| 69 | * @author :lyh | 65 | * @author :lyh |
| 70 | * @method :post | 66 | * @method :post |
| @@ -152,7 +148,7 @@ class ImageController extends Controller | @@ -152,7 +148,7 @@ class ImageController extends Controller | ||
| 152 | $imageModel = new ImageModel(); | 148 | $imageModel = new ImageModel(); |
| 153 | $image_hash = $imageModel->read(['hash'=>$hash]); | 149 | $image_hash = $imageModel->read(['hash'=>$hash]); |
| 154 | if($image_hash !== false){ | 150 | if($image_hash !== false){ |
| 155 | - return $this->response('图片资源',Code::SUCCESS,['image'=>$hash,'image_link'=>$this->getImageUrl($hash)]); | 151 | + return $this->response('图片资源',Code::SUCCESS,$this->responseData($hash)); |
| 156 | } | 152 | } |
| 157 | $url = $this->config['root'].$this->path; | 153 | $url = $this->config['root'].$this->path; |
| 158 | $fileName = uniqid().rand(10000,99999).'.'.$image_type; | 154 | $fileName = uniqid().rand(10000,99999).'.'.$image_type; |
| @@ -167,7 +163,7 @@ class ImageController extends Controller | @@ -167,7 +163,7 @@ class ImageController extends Controller | ||
| 167 | } | 163 | } |
| 168 | } | 164 | } |
| 169 | $this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location); | 165 | $this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location); |
| 170 | - return $this->response('图片资源',Code::SUCCESS,['image'=>$hash,'image_link'=>$this->getImageUrl($hash)]); | 166 | + return $this->response('图片资源',Code::SUCCESS,$this->responseData($hash)); |
| 171 | } | 167 | } |
| 172 | 168 | ||
| 173 | /** | 169 | /** |
| @@ -227,7 +223,7 @@ class ImageController extends Controller | @@ -227,7 +223,7 @@ class ImageController extends Controller | ||
| 227 | $hash = hash_file('md5', $file->getPathname()); | 223 | $hash = hash_file('md5', $file->getPathname()); |
| 228 | $image_hash = $imageModel->read(['hash'=>$hash]); | 224 | $image_hash = $imageModel->read(['hash'=>$hash]); |
| 229 | if($image_hash !== false){ | 225 | if($image_hash !== false){ |
| 230 | - $data[] = ['image'=>$hash,'image_link'=>$this->getImageUrl($hash)]; | 226 | + $data[] = $this->responseData($hash); |
| 231 | continue; | 227 | continue; |
| 232 | } | 228 | } |
| 233 | $url = $this->config['root'].$this->path; | 229 | $url = $this->config['root'].$this->path; |
| @@ -239,14 +235,14 @@ class ImageController extends Controller | @@ -239,14 +235,14 @@ class ImageController extends Controller | ||
| 239 | }else{ | 235 | }else{ |
| 240 | $res = $file->move($url,$fileName); | 236 | $res = $file->move($url,$fileName); |
| 241 | if ($res === false) { | 237 | if ($res === false) { |
| 242 | - return $this->response($file->getError(), Code::USER_ERROR); | 238 | + $this->response($file->getError(), Code::USER_ERROR); |
| 243 | } | 239 | } |
| 244 | } | 240 | } |
| 245 | //批量存储 | 241 | //批量存储 |
| 246 | $this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location); | 242 | $this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location); |
| 247 | - $data[] = ['image'=>$hash,'image_link'=>$this->getImageUrl($hash)]; | 243 | + $data[] = $this->responseData($hash); |
| 248 | } | 244 | } |
| 249 | - return $this->response('图片资源',Code::SUCCESS,$data); | 245 | + $this->response('图片资源',Code::SUCCESS,$data); |
| 250 | } | 246 | } |
| 251 | 247 | ||
| 252 | /** | 248 | /** |
| @@ -257,17 +253,31 @@ class ImageController extends Controller | @@ -257,17 +253,31 @@ class ImageController extends Controller | ||
| 257 | * @method :post | 253 | * @method :post |
| 258 | * @time :2023/7/19 17:59 | 254 | * @time :2023/7/19 17:59 |
| 259 | */ | 255 | */ |
| 260 | - public function download($filename){ | ||
| 261 | - $path = Storage::path($filename); | ||
| 262 | - return response()->download($path,time().rand(1,100000)); | 256 | + public function download(){ |
| 257 | + $imageModel = new ImageModel(); | ||
| 258 | + $info = $imageModel->read(['hash' => $this->param['hash']]); | ||
| 259 | + if ($info === false) { | ||
| 260 | + $this->response('指定文件不存在!', Code::USER_ERROR); | ||
| 261 | + } | ||
| 262 | + if($info['is_cos'] == 1){ | ||
| 263 | + $cos = new CosService(); | ||
| 264 | + $fileUrl = $cos->getImageUrl($info['path']); | ||
| 265 | + }else{ | ||
| 266 | + $fileUrl = $this->config['root'].$info['path']; | ||
| 267 | + if (!is_file($fileUrl)) { | ||
| 268 | + $this->response('指定图片已被系统删除!', Code::USER_ERROR); | ||
| 269 | + } | ||
| 270 | + } | ||
| 271 | + $fileName = basename($info['path']); // 要保存的文件名 | ||
| 272 | + // 设置响应头 | ||
| 273 | + header('Content-Description: File Transfer'); | ||
| 274 | + header('Content-Type: application/octet-stream'); | ||
| 275 | + header('Content-Disposition: attachment; filename="' . $fileName . '"'); | ||
| 276 | + // 下载文件 | ||
| 277 | + readfile($fileUrl); | ||
| 263 | } | 278 | } |
| 264 | 279 | ||
| 265 | /** | 280 | /** |
| 266 | - * @param $msg | ||
| 267 | - * @param string $code | ||
| 268 | - * @param $data | ||
| 269 | - * @param $result_code | ||
| 270 | - * @param $type | ||
| 271 | * @remark :统一返回 | 281 | * @remark :统一返回 |
| 272 | * @name :response | 282 | * @name :response |
| 273 | * @author :lyh | 283 | * @author :lyh |
| @@ -349,4 +359,37 @@ class ImageController extends Controller | @@ -349,4 +359,37 @@ class ImageController extends Controller | ||
| 349 | } | 359 | } |
| 350 | return $url; | 360 | return $url; |
| 351 | } | 361 | } |
| 362 | + | ||
| 363 | + /** | ||
| 364 | + * @remark :统一返回参数处理 | ||
| 365 | + * @name :responseData | ||
| 366 | + * @author :lyh | ||
| 367 | + * @method :post | ||
| 368 | + * @time :2023/7/26 13:41 | ||
| 369 | + */ | ||
| 370 | + public function responseData($hash){ | ||
| 371 | + $data = [ | ||
| 372 | + 'image'=>$hash, | ||
| 373 | + 'image_link'=>$this->getImageUrl($hash), | ||
| 374 | + 'image_download'=>url('a/downLoad/images?hash='.$hash), | ||
| 375 | + ]; | ||
| 376 | + return $data; | ||
| 377 | + } | ||
| 378 | + | ||
| 379 | + /** | ||
| 380 | + * @remark :获取下载链接 | ||
| 381 | + * @name :getDownloadUrl | ||
| 382 | + * @author :lyh | ||
| 383 | + * @method :post | ||
| 384 | + * @time :2023/7/26 14:00 | ||
| 385 | + */ | ||
| 386 | + public function getDownloadUrl(){ | ||
| 387 | + $imageModel = new ImageModel(); | ||
| 388 | + $info = $imageModel->read(['hash' => $this->param['hash']]); | ||
| 389 | + if ($info === false) { | ||
| 390 | + $this->response('指定文件不存在!', Code::USER_ERROR); | ||
| 391 | + } | ||
| 392 | + $data = ['image_download'=>url('a/downLoad/images?hash='.$this->param['hash'])]; | ||
| 393 | + $this->response('success',Code::SUCCESS,$data); | ||
| 394 | + } | ||
| 352 | } | 395 | } |
| @@ -188,11 +188,13 @@ Route::middleware(['aloginauth'])->group(function () { | @@ -188,11 +188,13 @@ Route::middleware(['aloginauth'])->group(function () { | ||
| 188 | }); | 188 | }); |
| 189 | //图片操作 | 189 | //图片操作 |
| 190 | Route::prefix('images')->group(function () { | 190 | Route::prefix('images')->group(function () { |
| 191 | - Route::post('/upload', [\App\Http\Controllers\File\ImageController::class, 'upload'])->name('image_upload'); | 191 | + Route::post('/upload', [\App\Http\Controllers\File\ImageController::class, 'upload'])->name('images_upload'); |
| 192 | + Route::post('/getDownloadUrl', [\App\Http\Controllers\File\ImageController::class, 'getDownloadUrl'])->name('images_getDownloadUrl'); | ||
| 192 | }); | 193 | }); |
| 193 | //文件操作 | 194 | //文件操作 |
| 194 | Route::prefix('files')->group(function () { | 195 | Route::prefix('files')->group(function () { |
| 195 | Route::post('/upload', [\App\Http\Controllers\File\FileController::class, 'upload'])->name('files_upload'); | 196 | Route::post('/upload', [\App\Http\Controllers\File\FileController::class, 'upload'])->name('files_upload'); |
| 197 | + Route::post('/getDownloadUrl', [\App\Http\Controllers\File\FileController::class, 'getDownloadUrl'])->name('files_getDownloadUrl'); | ||
| 196 | }); | 198 | }); |
| 197 | //谷歌流量系统 | 199 | //谷歌流量系统 |
| 198 | Route::prefix('projects')->group(function () { | 200 | Route::prefix('projects')->group(function () { |
| @@ -247,7 +249,8 @@ Route::group([], function () { | @@ -247,7 +249,8 @@ Route::group([], function () { | ||
| 247 | Route::any('/login', [Aside\LoginController::class, 'login'])->name('admin.login.white'); | 249 | Route::any('/login', [Aside\LoginController::class, 'login'])->name('admin.login.white'); |
| 248 | Route::any('/image/{hash}/{w?}/{h?}', [\App\Http\Controllers\File\ImageController::class, 'index'])->name('admin.image_show'); | 250 | Route::any('/image/{hash}/{w?}/{h?}', [\App\Http\Controllers\File\ImageController::class, 'index'])->name('admin.image_show'); |
| 249 | Route::any('/file/{hash}', [\App\Http\Controllers\File\FileController::class, 'index'])->name('admin.file_show'); | 251 | Route::any('/file/{hash}', [\App\Http\Controllers\File\FileController::class, 'index'])->name('admin.file_show'); |
| 250 | - Route::any('/downLoad', [\App\Http\Controllers\File\FileController::class, 'downLoad'])->name('files_downLoad'); | 252 | + Route::any('/downLoad/files', [\App\Http\Controllers\File\FileController::class, 'downLoad'])->name('admin.files_downLoad'); |
| 253 | + Route::any('/downLoad/images', [\App\Http\Controllers\File\ImageController::class, 'downLoad'])->name('admin.images_downLoad'); | ||
| 251 | Route::any('/notice/project', [Aside\NoticeController::class, 'project'])->name('admin.notice.project'); | 254 | Route::any('/notice/project', [Aside\NoticeController::class, 'project'])->name('admin.notice.project'); |
| 252 | //放开模版上传 | 255 | //放开模版上传 |
| 253 | // 公共主题模版 | 256 | // 公共主题模版 |
| @@ -208,10 +208,10 @@ Route::middleware(['bloginauth'])->group(function () { | @@ -208,10 +208,10 @@ Route::middleware(['bloginauth'])->group(function () { | ||
| 208 | }); | 208 | }); |
| 209 | 209 | ||
| 210 | //文件操作 | 210 | //文件操作 |
| 211 | - Route::prefix('file')->group(function () { | ||
| 212 | - Route::post('/upload', [\App\Http\Controllers\Bside\FileController::class, 'upload'])->name('file_upload'); | ||
| 213 | - Route::get('/lists', [\App\Http\Controllers\Bside\FileController::class, 'lists'])->name('file_lists'); | ||
| 214 | - }); | 211 | +// Route::prefix('file')->group(function () { |
| 212 | +// Route::post('/upload', [\App\Http\Controllers\Bside\FileController::class, 'upload'])->name('file_upload'); | ||
| 213 | +// Route::get('/lists', [\App\Http\Controllers\Bside\FileController::class, 'lists'])->name('file_lists'); | ||
| 214 | +// }); | ||
| 215 | //图片操作 | 215 | //图片操作 |
| 216 | Route::prefix('images')->group(function () { | 216 | Route::prefix('images')->group(function () { |
| 217 | Route::post('/upload', [\App\Http\Controllers\File\ImageController::class, 'upload'])->name('image_upload'); | 217 | Route::post('/upload', [\App\Http\Controllers\File\ImageController::class, 'upload'])->name('image_upload'); |
| @@ -337,6 +337,5 @@ Route::group([], function () { | @@ -337,6 +337,5 @@ Route::group([], function () { | ||
| 337 | Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login'); | 337 | Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login'); |
| 338 | Route::any('/stringTranslation', [\App\Http\Controllers\Bside\ComController::class, 'stringTranslation'])->name('com_stringTranslation'); | 338 | Route::any('/stringTranslation', [\App\Http\Controllers\Bside\ComController::class, 'stringTranslation'])->name('com_stringTranslation'); |
| 339 | Route::any('/sendLoginSms', [\App\Http\Controllers\Bside\ComController::class, 'sendLoginSms'])->name('sendLoginSms'); | 339 | Route::any('/sendLoginSms', [\App\Http\Controllers\Bside\ComController::class, 'sendLoginSms'])->name('sendLoginSms'); |
| 340 | - Route::get('/file/download', [\App\Http\Controllers\Bside\FileController::class, 'download'])->name('file_download'); | ||
| 341 | Route::any('/autologin', [\App\Http\Controllers\Bside\ComController::class, 'autologin'])->name('autologin'); | 340 | Route::any('/autologin', [\App\Http\Controllers\Bside\ComController::class, 'autologin'])->name('autologin'); |
| 342 | }); | 341 | }); |
-
请 注册 或 登录 后发表评论