完善视频上传

This commit is contained in:
none
2023-03-08 15:56:06 +08:00
parent b12fb1d7a9
commit 9428cf1785
7 changed files with 56 additions and 47 deletions

View File

@@ -18,7 +18,7 @@ export const UploadImageSub = (props: PropsInterface) => {
multiple: true,
action:
config.app_url +
"/backend/v1/upload/image?category_id=" +
"/backend/v1/upload/file?category_id=" +
props.categoryId,
headers: {
authorization: "Bearer " + getToken(),

View File

@@ -13,9 +13,8 @@ import {
import Dragger from "antd/es/upload/Dragger";
import { useRef, useState } from "react";
import { generateUUID, parseVideo } from "../../utils";
import { minioUploadId } from "../../api/upload";
import { minioMergeVideo, minioUploadId } from "../../api/upload";
import { UploadChunk } from "../../js/minio-upload-chunk";
import { storeResource } from "../../api/resource";
interface PropsInterface {
categoryId: number;
@@ -24,6 +23,8 @@ interface PropsInterface {
interface FileItem {
id: string;
filename: string;
uploadId: string;
name: string;
duration: number;
size: number;
@@ -36,6 +37,7 @@ interface FileItem {
isErr: boolean;
errMsg: string;
remoteName: string;
poster: string;
}
export const UploadVideoButton = (props: PropsInterface) => {
@@ -52,6 +54,7 @@ export const UploadVideoButton = (props: PropsInterface) => {
multiple: true,
beforeUpload: async (file: File) => {
if (file.type === "video/mp4") {
// 视频封面解析 || 视频时长解析
let videoInfo = await parseVideo(file);
// 添加到本地待上传
let data = await getMinioUploadId();
@@ -59,6 +62,8 @@ export const UploadVideoButton = (props: PropsInterface) => {
let item: FileItem = {
id: generateUUID(),
duration: videoInfo.duration,
filename: data["filename"],
uploadId: data["upload_id"],
name: file.name,
size: file.size,
progress: 0,
@@ -70,25 +75,21 @@ export const UploadVideoButton = (props: PropsInterface) => {
isErr: false,
errMsg: "",
remoteName: data["filename"],
poster: videoInfo.poster,
};
item.run.on("success", (url: string) => {
item.isSuc = true;
setFileList([...localFileList.current]);
// 创建上传记录
storeResource(
item.run.on("success", () => {
minioMergeVideo(
item.filename,
item.uploadId,
props.categoryId,
item.file.name,
item.name,
"mp4",
item.file.size,
"minio",
"",
item.remoteName,
url,
{
duration: item.duration,
}
item.size,
item.duration,
item.poster
).then(() => {
item.isSuc = true;
setFileList([...localFileList.current]);
message.success(`${item.file.name} 上传成功`);
});
});