作者 赵彬吉

Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into develop

... ... @@ -4,7 +4,6 @@ namespace App\Http\Controllers\File;
use App\Enums\Common\Code;
use App\Models\File\File;
use App\Models\File\Image as ImageModel;
use App\Models\Project\Project;
use App\Services\CosService;
use Illuminate\Http\Exceptions\HttpResponseException;
... ... @@ -114,7 +113,6 @@ class FileController
}
/**
* @param $files
* @remark :单文件上传
* @name :single
* @author :lyh
... ... @@ -127,10 +125,10 @@ class FileController
$fileModel = new File();
$file_hash = $fileModel->read(['hash'=>$hash]);
if($file_hash !== false){
return $this->response('资源',Code::SUCCESS,['file'=>$hash,'file_link'=>$this->getFileUrl($fileModel,$hash)]);
return $this->response('资源',Code::SUCCESS,$this->responseData($fileModel,$hash));
}
$url = $this->config['root'].$this->path;
$fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
$fileName = uniqid().rand(10000,99999).'.'.$file_type;
//同步数据到cos
if($this->upload_location == 1){
$cosService = new CosService();
... ... @@ -142,7 +140,7 @@ class FileController
}
}
$this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location);
return $this->response('资源',Code::SUCCESS,['file'=>$hash,'file_link'=>$this->getFileUrl($fileModel,$hash)]);
return $this->response('资源',Code::SUCCESS,$this->responseData($fileModel,$hash));
}
/**
... ... @@ -170,7 +168,6 @@ class FileController
}
/**
* @param $files
* @remark :多文件上传(暂时未用)
* @name :multi
* @author :lyh
... ... @@ -184,11 +181,12 @@ class FileController
$hash = hash_file('md5', $file->getPathname());
$file_hash = $fileModel->read(['hash'=>$hash]);
if($file_hash !== false){
$data[] = ['file'=>$hash,'file_link'=>$this->getFileUrl($fileModel,$hash)];
$data[] = $this->responseData($fileModel,$hash);
continue;
}
$url = $this->config['root'].'/'.$this->path;
$fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
$file_type = $file->getClientOriginalExtension();
$fileName = uniqid().rand(10000,99999).'.'.$file_type;
//同步数据到cos
if($this->upload_location == 1){
$cosService = new CosService();
... ... @@ -200,20 +198,14 @@ class FileController
}
}
$size = $file->getSize();
$file_type = $file->getClientOriginalExtension();
$this->saveMysql($fileModel,$size,$file_type,$fileName,$hash,$this->upload_location);
$data[] = ['file'=>$hash,'file_link'=>$this->getFileUrl($fileModel,$hash)];
$data[] = $this->responseData($fileModel,$hash);
}
return $this->response('资源',Code::SUCCESS,$data);
$this->response('资源',Code::SUCCESS,$data);
}
/**
* @param $msg
* @param string $code
* @param $data
* @param $result_code
* @param $type
* @remark :统一返回接口
* @name :response
* @author :lyh
... ... @@ -326,4 +318,37 @@ class FileController
}
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @remark :统一返回参数处理
* @name :responseData
* @author :lyh
* @method :post
* @time :2023/7/26 13:41
*/
public function responseData(&$fileModel,$hash){
$data = [
'file'=>$hash,
'file_link'=>$this->getFileUrl($fileModel,$hash),
'file_download'=>url('a/download/files?hash='.$hash),
];
return $data;
}
/**
* @remark :获取下载链接
* @name :getDownloadUrl
* @author :lyh
* @method :post
* @time :2023/7/26 14:00
*/
public function getDownloadUrl(){
$fileModel = new File();
$info = $fileModel->read(['hash' => $this->param['hash']]);
if ($info === false) {
$this->response('指定文件不存在!', Code::USER_ERROR);
}
$data = ['file_download'=>url('a/downLoad/files?hash='.$this->param['hash'])];
$this->response('success',Code::SUCCESS,$data);
}
}
... ...
... ... @@ -12,7 +12,6 @@ use App\Services\TencentCosService;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\Facades\Image;
class ImageController extends Controller
... ... @@ -62,9 +61,6 @@ class ImageController extends Controller
}
/**
* @param $hash
* @param $w
* @param $h
* @name :index
* @author :lyh
* @method :post
... ... @@ -152,7 +148,7 @@ class ImageController extends Controller
$imageModel = new ImageModel();
$image_hash = $imageModel->read(['hash'=>$hash]);
if($image_hash !== false){
return $this->response('图片资源',Code::SUCCESS,['image'=>$hash,'image_link'=>$this->getImageUrl($hash)]);
return $this->response('图片资源',Code::SUCCESS,$this->responseData($hash));
}
$url = $this->config['root'].$this->path;
$fileName = uniqid().rand(10000,99999).'.'.$image_type;
... ... @@ -167,7 +163,7 @@ class ImageController extends Controller
}
}
$this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location);
return $this->response('图片资源',Code::SUCCESS,['image'=>$hash,'image_link'=>$this->getImageUrl($hash)]);
return $this->response('图片资源',Code::SUCCESS,$this->responseData($hash));
}
/**
... ... @@ -227,7 +223,7 @@ class ImageController extends Controller
$hash = hash_file('md5', $file->getPathname());
$image_hash = $imageModel->read(['hash'=>$hash]);
if($image_hash !== false){
$data[] = ['image'=>$hash,'image_link'=>$this->getImageUrl($hash)];
$data[] = $this->responseData($hash);
continue;
}
$url = $this->config['root'].$this->path;
... ... @@ -239,14 +235,14 @@ class ImageController extends Controller
}else{
$res = $file->move($url,$fileName);
if ($res === false) {
return $this->response($file->getError(), Code::USER_ERROR);
$this->response($file->getError(), Code::USER_ERROR);
}
}
//批量存储
$this->saveMysql($imageModel,$size,$image_type,$fileName,$hash,$this->upload_location);
$data[] = ['image'=>$hash,'image_link'=>$this->getImageUrl($hash)];
$data[] = $this->responseData($hash);
}
return $this->response('图片资源',Code::SUCCESS,$data);
$this->response('图片资源',Code::SUCCESS,$data);
}
/**
... ... @@ -257,17 +253,31 @@ class ImageController extends Controller
* @method :post
* @time :2023/7/19 17:59
*/
public function download($filename){
$path = Storage::path($filename);
return response()->download($path,time().rand(1,100000));
public function download(){
$imageModel = new ImageModel();
$info = $imageModel->read(['hash' => $this->param['hash']]);
if ($info === false) {
$this->response('指定文件不存在!', Code::USER_ERROR);
}
if($info['is_cos'] == 1){
$cos = new CosService();
$fileUrl = $cos->getImageUrl($info['path']);
}else{
$fileUrl = $this->config['root'].$info['path'];
if (!is_file($fileUrl)) {
$this->response('指定图片已被系统删除!', Code::USER_ERROR);
}
}
$fileName = basename($info['path']); // 要保存的文件名
// 设置响应头
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $fileName . '"');
// 下载文件
readfile($fileUrl);
}
/**
* @param $msg
* @param string $code
* @param $data
* @param $result_code
* @param $type
* @remark :统一返回
* @name :response
* @author :lyh
... ... @@ -349,4 +359,37 @@ class ImageController extends Controller
}
return $url;
}
/**
* @remark :统一返回参数处理
* @name :responseData
* @author :lyh
* @method :post
* @time :2023/7/26 13:41
*/
public function responseData($hash){
$data = [
'image'=>$hash,
'image_link'=>$this->getImageUrl($hash),
'image_download'=>url('a/downLoad/images?hash='.$hash),
];
return $data;
}
/**
* @remark :获取下载链接
* @name :getDownloadUrl
* @author :lyh
* @method :post
* @time :2023/7/26 14:00
*/
public function getDownloadUrl(){
$imageModel = new ImageModel();
$info = $imageModel->read(['hash' => $this->param['hash']]);
if ($info === false) {
$this->response('指定文件不存在!', Code::USER_ERROR);
}
$data = ['image_download'=>url('a/downLoad/images?hash='.$this->param['hash'])];
$this->response('success',Code::SUCCESS,$data);
}
}
... ...
... ... @@ -188,11 +188,13 @@ Route::middleware(['aloginauth'])->group(function () {
});
//图片操作
Route::prefix('images')->group(function () {
Route::post('/upload', [\App\Http\Controllers\File\ImageController::class, 'upload'])->name('image_upload');
Route::post('/upload', [\App\Http\Controllers\File\ImageController::class, 'upload'])->name('images_upload');
Route::post('/getDownloadUrl', [\App\Http\Controllers\File\ImageController::class, 'getDownloadUrl'])->name('images_getDownloadUrl');
});
//文件操作
Route::prefix('files')->group(function () {
Route::post('/upload', [\App\Http\Controllers\File\FileController::class, 'upload'])->name('files_upload');
Route::post('/getDownloadUrl', [\App\Http\Controllers\File\FileController::class, 'getDownloadUrl'])->name('files_getDownloadUrl');
});
//谷歌流量系统
Route::prefix('projects')->group(function () {
... ... @@ -247,7 +249,8 @@ Route::group([], function () {
Route::any('/login', [Aside\LoginController::class, 'login'])->name('admin.login.white');
Route::any('/image/{hash}/{w?}/{h?}', [\App\Http\Controllers\File\ImageController::class, 'index'])->name('admin.image_show');
Route::any('/file/{hash}', [\App\Http\Controllers\File\FileController::class, 'index'])->name('admin.file_show');
Route::any('/downLoad', [\App\Http\Controllers\File\FileController::class, 'downLoad'])->name('files_downLoad');
Route::any('/downLoad/files', [\App\Http\Controllers\File\FileController::class, 'downLoad'])->name('admin.files_downLoad');
Route::any('/downLoad/images', [\App\Http\Controllers\File\ImageController::class, 'downLoad'])->name('admin.images_downLoad');
Route::any('/notice/project', [Aside\NoticeController::class, 'project'])->name('admin.notice.project');
//放开模版上传
// 公共主题模版
... ...
... ... @@ -208,10 +208,10 @@ Route::middleware(['bloginauth'])->group(function () {
});
//文件操作
Route::prefix('file')->group(function () {
Route::post('/upload', [\App\Http\Controllers\Bside\FileController::class, 'upload'])->name('file_upload');
Route::get('/lists', [\App\Http\Controllers\Bside\FileController::class, 'lists'])->name('file_lists');
});
// Route::prefix('file')->group(function () {
// Route::post('/upload', [\App\Http\Controllers\Bside\FileController::class, 'upload'])->name('file_upload');
// Route::get('/lists', [\App\Http\Controllers\Bside\FileController::class, 'lists'])->name('file_lists');
// });
//图片操作
Route::prefix('images')->group(function () {
Route::post('/upload', [\App\Http\Controllers\File\ImageController::class, 'upload'])->name('image_upload');
... ... @@ -337,6 +337,5 @@ Route::group([], function () {
Route::any('/login', [\App\Http\Controllers\Bside\ComController::class, 'login'])->name('login');
Route::any('/stringTranslation', [\App\Http\Controllers\Bside\ComController::class, 'stringTranslation'])->name('com_stringTranslation');
Route::any('/sendLoginSms', [\App\Http\Controllers\Bside\ComController::class, 'sendLoginSms'])->name('sendLoginSms');
Route::get('/file/download', [\App\Http\Controllers\Bside\FileController::class, 'download'])->name('file_download');
Route::any('/autologin', [\App\Http\Controllers\Bside\ComController::class, 'autologin'])->name('autologin');
});
... ...