feat: 添加视频上传接口
This commit is contained in:
@@ -4,6 +4,7 @@ declare (strict_types = 1);
|
||||
namespace app\admin\controller\v1;
|
||||
|
||||
use app\admin\model\v1\SysImageModel;
|
||||
use app\admin\model\v1\SysVideoModel;
|
||||
use Intervention\Image\ImageManager;
|
||||
use think\facade\Filesystem;
|
||||
|
||||
@@ -76,4 +77,62 @@ class Upload
|
||||
|
||||
return error('上传失败');
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传视频
|
||||
*/
|
||||
public function video()
|
||||
{
|
||||
$param = request()->param(['module' => 'unknown']);
|
||||
if (is_null($param)) {
|
||||
return error('请确定请求参数正确');
|
||||
}
|
||||
$file = request()->file('video');
|
||||
if (is_null($file)) {
|
||||
return error('请确定上传对象或字段是否正确');
|
||||
}
|
||||
|
||||
try {
|
||||
$validate = validate([
|
||||
'module' => 'require|max:64',
|
||||
'image' => 'fileSize:52428800|fileExt:mp4'
|
||||
]);
|
||||
if (!$validate->check(['module' => $param['module'], 'image' => $file])) {
|
||||
return error($validate->getError());
|
||||
}
|
||||
|
||||
$storage = config('filesystem.disks.video.url');
|
||||
|
||||
$filemd5 = $file->md5();
|
||||
$filesha1 = $file->sha1();
|
||||
|
||||
$video = SysVideoModel::md5($filemd5)->find();
|
||||
if (is_null($video)) {
|
||||
$filename = Filesystem::disk('video')->putFile($param['module'], $file);
|
||||
|
||||
// 保存视频
|
||||
$video = new SysVideoModel();
|
||||
$video->language_id = $param['language_id'];
|
||||
$video->module = $param['module'];
|
||||
$video->video_path = $filename;
|
||||
$video->video_size = $file->getSize();
|
||||
$video->video_type = $file->getOriginalMime();
|
||||
$video->video_md5 = $filemd5;
|
||||
$video->video_sha1 = $filesha1;
|
||||
if (!$video->save()) {
|
||||
return error('上传失败');
|
||||
}
|
||||
}
|
||||
|
||||
return success('上传成功', [
|
||||
'url' => $storage . '/' . $video->video_path,
|
||||
'file_md5' => $video->file_md5,
|
||||
'file_sha1' => $video->file_sha1
|
||||
]);
|
||||
} catch (\Throwable $th) {
|
||||
return error($th->getMessage());
|
||||
}
|
||||
|
||||
return error('上传失败');
|
||||
}
|
||||
}
|
||||
|
||||
12
app/admin/controller/v1/Video.php
Normal file
12
app/admin/controller/v1/Video.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\admin\controller\v1;
|
||||
|
||||
/**
|
||||
* 视频管理控制器
|
||||
*/
|
||||
class Video
|
||||
{
|
||||
|
||||
}
|
||||
19
app/admin/model/v1/SysVideoModel.php
Normal file
19
app/admin/model/v1/SysVideoModel.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\admin\model\v1;
|
||||
|
||||
use app\common\model\SysVideoBaseModel;
|
||||
|
||||
/**
|
||||
* 视频上传模型
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class SysVideoModel extends SysVideoBaseModel
|
||||
{
|
||||
// 根据md5查询
|
||||
public function scopeMd5($query, $value)
|
||||
{
|
||||
$query->where('video_md5', '=', $value);
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,12 @@ Route::group('v1', function () {
|
||||
Route::post('/:module/upload', 'Upload/image');
|
||||
});
|
||||
|
||||
// 视频管理
|
||||
Route::group('video', function () {
|
||||
// 视频上传
|
||||
Route::post('/:module/upload', 'Upload/video');
|
||||
});
|
||||
|
||||
// 文章模块
|
||||
Route::group('article', function () {
|
||||
// 文章列表
|
||||
|
||||
Reference in New Issue
Block a user