|
|
@@ -249,15 +249,16 @@ class ImageGenerationController extends BaseController
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 批量上传图片
|
|
|
+ * 批量上传图片或视频
|
|
|
*
|
|
|
* @param Request $request
|
|
|
* @return void
|
|
|
*/
|
|
|
public function batchUploadImg(Request $request) {
|
|
|
$refImgUrls = [];
|
|
|
+ $refVideoUrls = [];
|
|
|
|
|
|
- // 处理上传的文件
|
|
|
+ // 处理上传的图片文件
|
|
|
if ($request->hasFile('ref_img_file')) {
|
|
|
$refImgFiles = is_array($request->file('ref_img_file'))
|
|
|
? $request->file('ref_img_file')
|
|
|
@@ -290,7 +291,7 @@ class ImageGenerationController extends BaseController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 处理二进制内容(ref_img数组)
|
|
|
+ // 处理图片二进制内容(ref_img数组)
|
|
|
if ($request->has('ref_img')) {
|
|
|
$refImgs = $request->input('ref_img');
|
|
|
|
|
|
@@ -346,6 +347,74 @@ class ImageGenerationController extends BaseController
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return $this->success(['image_urls' => $refImgUrls]);
|
|
|
+ // 处理上传的视频文件
|
|
|
+ if ($request->hasFile('ref_video_file')) {
|
|
|
+ $refVideoFiles = is_array($request->file('ref_video_file'))
|
|
|
+ ? $request->file('ref_video_file')
|
|
|
+ : [$request->file('ref_video_file')];
|
|
|
+
|
|
|
+ foreach ($refVideoFiles as $index => $refVideoFile) {
|
|
|
+ // 验证视频文件大小(最大100MB)
|
|
|
+ if ($refVideoFile->getSize() > 100 * 1024 * 1024) {
|
|
|
+ Utils::throwError('1003:视频' . ($index + 1) . '大小不能超过100MB');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证视频文件类型
|
|
|
+ $allowedMimeTypes = ['video/mp4', 'video/mpeg', 'video/quicktime', 'video/x-msvideo'];
|
|
|
+ if (!in_array($refVideoFile->getMimeType(), $allowedMimeTypes)) {
|
|
|
+ Utils::throwError('1003:视频' . ($index + 1) . '格式无效,仅支持mp4、mpeg、mov、avi格式');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 上传视频到服务器并获取URL
|
|
|
+ $filename = randStr(10) . '.' . $refVideoFile->getClientOriginalExtension();
|
|
|
+ $uploaded_url = uploadStreamByTos('video', file_get_contents($refVideoFile->getPathname()), $filename);
|
|
|
+ if (!$uploaded_url) {
|
|
|
+ Utils::throwError('1003:视频' . ($index + 1) . '保存失败');
|
|
|
+ }
|
|
|
+ $refVideoUrls[] = $uploaded_url;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理视频二进制内容(ref_video数组)
|
|
|
+ if ($request->has('ref_video')) {
|
|
|
+ $refVideos = $request->input('ref_video');
|
|
|
+
|
|
|
+ // 确保是数组格式
|
|
|
+ if (!is_array($refVideos)) {
|
|
|
+ $refVideos = [$refVideos];
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($refVideos as $index => $refVideoBinary) {
|
|
|
+ try {
|
|
|
+ // 解码base64(如果是base64格式)
|
|
|
+ if (preg_match('/^data:video\/(\w+);base64,/', $refVideoBinary, $matches)) {
|
|
|
+ $extension = $matches[1];
|
|
|
+ $refVideoBinary = base64_decode(substr($refVideoBinary, strpos($refVideoBinary, ',') + 1));
|
|
|
+ } else {
|
|
|
+ $extension = 'mp4'; // 默认扩展名
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证视频大小(最大100MB)
|
|
|
+ if (strlen($refVideoBinary) > 100 * 1024 * 1024) {
|
|
|
+ Utils::throwError('1003:视频' . ($index + 1) . '大小不能超过100MB');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 上传视频到服务器并获取URL
|
|
|
+ $filename = randStr(10) . '.' . $extension;
|
|
|
+ $uploaded_url = uploadStreamByTos('video', $refVideoBinary, $filename);
|
|
|
+ if (!$uploaded_url) {
|
|
|
+ Utils::throwError('1003:视频' . ($index + 1) . '保存失败');
|
|
|
+ }
|
|
|
+ $refVideoUrls[] = $uploaded_url;
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Utils::throwError('1003:视频' . ($index + 1) . '处理失败:' . $e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->success([
|
|
|
+ 'image_urls' => $refImgUrls,
|
|
|
+ 'video_urls' => $refVideoUrls
|
|
|
+ ]);
|
|
|
}
|
|
|
}
|