Skip to content

Let's use AI to Earn!

feat: Add a cover to the video material and upload it

gaoSir59c75165faa7
diff --git a/src/app/[lng]/material/album/[id]/page.tsx b/src/app/[lng]/material/album/[id]/page.tsx
index c21b7f01..8394fd4c 100644
--- a/src/app/[lng]/material/album/[id]/page.tsx
+++ b/src/app/[lng]/material/album/[id]/page.tsx
@@ -7,6 +7,7 @@ import styles from "./album.module.scss";
import { createMedia, deleteMedia, getMediaList } from "@/api/media";
import { uploadToOss } from "@/api/oss";
import { getOssUrl } from "@/utils/oss";
+import { formatImg, VideoGrabFrame } from "@/components/PublishDialog/PublishDialog.util";
interface Media {
_id: string;
@@ -120,13 +121,24 @@ export default function AlbumPage() {
try {
const url = await uploadToOss(file);
-
+ let thumbUrl: string;
+ if (file.type.startsWith('video/')) {
+ const res = await VideoGrabFrame(URL.createObjectURL(file), 0);
+ const blob = res.cover.file;
+ const fileName = file.name.replace(/\.[^/.]+$/, "") + "_cover.png";
+ const coverFile = new File([blob], fileName, {
+ type: blob.type || "image/png",
+ });
+ thumbUrl = await uploadToOss(coverFile);
+ }
+
await createMedia({
groupId: albumId,
type: file.type.startsWith('video/') ? 'video' : file.type.startsWith('image/') ? 'img' : 'img', // 音频暂时不支持
url,
title: file.name,
- desc: ''
+ desc: '',
+ thumbUrl
});
message.success('上传成功');
@@ -252,4 +264,4 @@ export default function AlbumPage() {
)}
</div>
);
-}
\ No newline at end of file
+}
diff --git a/src/components/PublishDialog/compoents/PubParmasTextarea/PubParmasTextareaUpload.tsx b/src/components/PublishDialog/compoents/PubParmasTextarea/PubParmasTextareaUpload.tsx
index c89667bd..0f143daf 100644
--- a/src/components/PublishDialog/compoents/PubParmasTextarea/PubParmasTextareaUpload.tsx
+++ b/src/components/PublishDialog/compoents/PubParmasTextarea/PubParmasTextareaUpload.tsx
@@ -183,11 +183,16 @@ const PubParmasTextareaUpload = memo(
imagefile["ossUrl"] = item.url;
onImgUpdateFinish([imagefile]);
} else {
- // TODO 视频素材,需要封面
+ const coverOss = getOssUrl(item.thumbUrl || "");
const video: any = {
ossUrl: ossUrl,
videoUrl: ossUrl,
+ cover: {
+ ossUrl: coverOss,
+ imgUrl: coverOss,
+ },
};
+ console.log(video);
onVideoUpdateFinish(video);
}
} catch (e) {