refactor: 调整图片/视频上传

This commit is contained in:
2025-02-19 16:58:31 +08:00
parent aa1d6b2916
commit 8fd94f9428
7 changed files with 36 additions and 36 deletions

View File

@@ -56,20 +56,20 @@ class Upload
$image_model->module = $param['module'];
$image_model->image_path = $filename;
$image_model->image_thumb = $thumb_filename;
$image_model->image_size = $file->getSize();
$image_model->image_type = $file->getOriginalMime();
$image_model->image_md5 = $filemd5;
$image_model->image_sha1 = $filesha1;
$image_model->file_size = $file->getSize();
$image_model->file_type = $file->getOriginalMime();
$image_model->file_md5 = $filemd5;
$image_model->file_sha1 = $filesha1;
if (!$image_model->save()) {
return error('上传失败');
}
}
return success('操作成功', [
'url' => $storage . '/' . $image_model->image_path,
'thumb_url' => $storage . '/' . $image_model->image_thumb,
'filemd5' => $image_model->image_md5,
'filesha1' => $image_model->image_sha1
'path' => $storage . '/' . $image_model->image_path,
'thumb_path' => $storage . '/' . $image_model->image_thumb,
'filemd5' => $image_model->file_md5,
'filesha1' => $image_model->file_sha1
]);
} catch (\Throwable $th) {
return error($th->getMessage());
@@ -95,9 +95,9 @@ class Upload
try {
$validate = validate([
'module' => 'require|max:64',
'image' => 'fileSize:52428800|fileExt:mp4'
'video' => 'fileSize:52428800|fileExt:mp4'
]);
if (!$validate->check(['module' => $param['module'], 'image' => $file])) {
if (!$validate->check(['module' => $param['module'], 'video' => $file])) {
return error($validate->getError());
}
@@ -112,20 +112,20 @@ class Upload
// 保存视频
$video = new SysVideoModel();
$video->language_id = $param['language_id'];
$video->language_id = request()->lang_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;
$video->file_size = $file->getSize();
$video->file_type = $file->getOriginalMime();
$video->file_md5 = $filemd5;
$video->file_sha1 = $filesha1;
if (!$video->save()) {
return error('上传失败');
}
}
return success('上传成功', [
'url' => $storage . '/' . $video->video_path,
'path' => $storage . '/' . $video->video_path,
'file_md5' => $video->file_md5,
'file_sha1' => $video->file_sha1
]);

View File

@@ -14,6 +14,6 @@ class SysImageModel extends SysImageBaseModel
// 根据md5获取图片
public function scopeMd5($query, $md5)
{
$query->where('image_md5', '=', $md5);
$query->where('file_md5', '=', $md5);
}
}

View File

@@ -14,6 +14,6 @@ class SysVideoModel extends SysVideoBaseModel
// 根据md5查询
public function scopeMd5($query, $value)
{
$query->where('video_md5', '=', $value);
$query->where('file_md5', '=', $value);
}
}

View File

@@ -23,10 +23,10 @@ class SysImageBaseModel extends Model
'module' => 'string',
'image_path' => 'string',
'image_thumb' => 'string',
'image_size' => 'int',
'image_type' => 'string',
'image_md5' => 'string',
'image_sha1' => 'string',
'file_size' => 'int',
'file_type' => 'string',
'file_md5' => 'string',
'file_sha1' => 'string',
'created_at' => 'datetime',
'deleted_at' => 'datetime',
];

View File

@@ -23,10 +23,10 @@ class SysVideoBaseModel extends Model
'language_id' => 'int',
'module' => 'string',
'video_path' => 'string',
'video_size' => 'int',
'video_type' => 'string',
'video_md5' => 'string',
'video_sha1' => 'string',
'file_size' => 'int',
'file_type' => 'string',
'file_md5' => 'string',
'file_sha1' => 'string',
'created_at' => 'datetime',
'deleted_at' => 'datetime',
];

View File

@@ -32,10 +32,10 @@ class CreateSysImage extends Migrator
->addColumn('module', 'string', ['limit' => 64, 'null' => false, 'comment' => '图片所属模块'])
->addColumn('image_path', 'string', ['limit' => 125, 'null' => false, 'comment' => '图片路径'])
->addColumn('image_thumb', 'string', ['limit' => 125, 'null' => false, 'comment' => '缩略图路径'])
->addColumn('image_size', 'integer', ['null' => false, 'comment' => '图片大小'])
->addColumn('image_type', 'string', ['limit' => 125, 'null' => false, 'comment' => '图片类型'])
->addColumn('image_md5', 'string', ['limit' => 32, 'null' => false, 'comment' => '图片md5值'])
->addColumn('image_sha1', 'string', ['limit' => 40, 'null' => false, 'comment' => '图片sha1值'])
->addColumn('file_size', 'integer', ['null' => false, 'comment' => '图片大小'])
->addColumn('file_type', 'string', ['limit' => 125, 'null' => false, 'comment' => '图片类型'])
->addColumn('file_md5', 'string', ['limit' => 32, 'null' => false, 'comment' => '图片md5值'])
->addColumn('file_sha1', 'string', ['limit' => 40, 'null' => false, 'comment' => '图片sha1值'])
->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'])
->addColumn('deleted_at', 'timestamp', ['null' => true, 'comment' => '删除时间'])
->create();

View File

@@ -32,10 +32,10 @@ class CreateSysVideo extends Migrator
$table->addColumn('language_id', 'integer', ['signed' => false, 'null' => false, 'comment' => '语言ID'])
->addColumn('module', 'string', ['limit' => 64, 'null' => false, 'comment' => '视频所属模块'])
->addColumn('video_path', 'string', ['limit' => 125, 'null' => false, 'comment' => '视频路径'])
->addColumn('video_size', 'integer', ['null' => false, 'comment' => '视频大小'])
->addColumn('video_type', 'string', ['limit' => 125, 'null' => false, 'comment' => '视频类型'])
->addColumn('video_md5', 'string', ['limit' => 32, 'null' => false, 'comment' => '视频md5值'])
->addColumn('video_sha1', 'string', ['limit' => 40, 'null' => false, 'comment' => '视频sha1值'])
->addColumn('file_size', 'integer', ['null' => false, 'comment' => '视频大小'])
->addColumn('file_type', 'string', ['limit' => 125, 'null' => false, 'comment' => '视频类型'])
->addColumn('file_md5', 'string', ['limit' => 32, 'null' => false, 'comment' => '视频md5值'])
->addColumn('file_sha1', 'string', ['limit' => 40, 'null' => false, 'comment' => '视频sha1值'])
->addColumn('created_at', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'])
->addColumn('deleted_at', 'timestamp', ['null' => true, 'comment' => '删除时间'])
->create();