This commit is contained in:
ditiqi 2025-02-23 20:12:20 +08:00
parent 0e9ac6713a
commit cbba92b380
1 changed files with 22 additions and 11 deletions

View File

@ -13,6 +13,7 @@ import { LectureType, LessonTypeLabel, PostType } from "@nice/common";
import { usePost } from "@nice/client"; import { usePost } from "@nice/client";
import toast from "react-hot-toast"; import toast from "react-hot-toast";
import { LectureData } from "./interface"; import { LectureData } from "./interface";
import { env } from "@web/src/env";
interface SortableLectureProps { interface SortableLectureProps {
field: LectureData; field: LectureData;
@ -43,6 +44,11 @@ export const SortableLecture: React.FC<SortableLectureProps> = ({
setLoading(true); setLoading(true);
const values = await form.validateFields(); const values = await form.validateFields();
let result; let result;
const videoUrlId = Array.isArray(values?.videoUrlIds)
? values.videoUrlIds[0]
: typeof values?.videoUrlIds === "string"
? values.videoUrlIds
: undefined;
if (!field.id) { if (!field.id) {
result = await create.mutateAsync({ result = await create.mutateAsync({
@ -52,14 +58,17 @@ export const SortableLecture: React.FC<SortableLectureProps> = ({
title: values?.title, title: values?.title,
meta: { meta: {
type: values?.meta?.type, type: values?.meta?.type,
fileIds: values?.meta?.fileIds, // fileIds: values?.meta?.fileIds,
videoUrl: videoUrlId
? `http://${env.SERVER_IP}:${env.FILE_PORT}/uploads/${videoUrlId}/stream/index.m3u8`
: undefined,
}, },
resources: { resources: {
connect: (values?.meta?.fileIds || []).map( connect: [videoUrlId]
(fileId) => ({ .filter(Boolean)
.map((fileId) => ({
fileId, fileId,
}) })),
),
}, },
content: values?.content, content: values?.content,
}, },
@ -73,14 +82,16 @@ export const SortableLecture: React.FC<SortableLectureProps> = ({
title: values?.title, title: values?.title,
meta: { meta: {
type: values?.meta?.type, type: values?.meta?.type,
fieldIds: values?.meta?.fileIds, videoUrl: videoUrlId
? `http://${env.SERVER_IP}:${env.FILE_PORT}/uploads/${videoUrlId}/stream/index.m3u8`
: undefined,
}, },
resources: { resources: {
connect: (values?.meta?.fileIds || []).map( connect: [videoUrlId]
(fileId) => ({ .filter(Boolean)
.map((fileId) => ({
fileId, fileId,
}) })),
),
}, },
content: values?.content, content: values?.content,
}, },
@ -135,7 +146,7 @@ export const SortableLecture: React.FC<SortableLectureProps> = ({
<div className="mt-4 flex flex-1 "> <div className="mt-4 flex flex-1 ">
{lectureType === LectureType.VIDEO ? ( {lectureType === LectureType.VIDEO ? (
<Form.Item <Form.Item
name={["meta", "fileIds"]} name={"videoUrlIds"}
className="mb-0 flex-1" className="mb-0 flex-1"
rules={[{ required: true }]}> rules={[{ required: true }]}>
<TusUploader multiple={false} /> <TusUploader multiple={false} />