feat: 添加视频上传接口

This commit is contained in:
2025-02-19 16:33:36 +08:00
parent 65b83b5f9b
commit 4f43341534
7 changed files with 182 additions and 0 deletions

View File

@@ -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('上传失败');
}
}

View File

@@ -0,0 +1,12 @@
<?php
declare (strict_types = 1);
namespace app\admin\controller\v1;
/**
* 视频管理控制器
*/
class Video
{
}