mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: init impl video watch
This commit is contained in:
parent
c425b55c93
commit
0997ea4135
3 changed files with 36 additions and 22 deletions
|
|
@ -8,6 +8,7 @@ import { useRouter } from "next/router";
|
||||||
import React, { useMemo } from "react";
|
import React, { useMemo } from "react";
|
||||||
import Layout from "../../../../../../../components/ui/Layout";
|
import Layout from "../../../../../../../components/ui/Layout";
|
||||||
import { getElement } from "../../../../../../../services/courses/elements";
|
import { getElement } from "../../../../../../../services/courses/elements";
|
||||||
|
import { getBackendUrl } from "../../../../../../../services/config";
|
||||||
|
|
||||||
function ElementPage() {
|
function ElementPage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
@ -31,25 +32,30 @@ function ElementPage() {
|
||||||
|
|
||||||
const output = useMemo(() => {
|
const output = useMemo(() => {
|
||||||
if (router.isReady && !isLoading) {
|
if (router.isReady && !isLoading) {
|
||||||
console.log( "el",element.content);
|
console.log(element);
|
||||||
|
|
||||||
let content = Object.keys(element.content).length > 0 ? element.content : {
|
if (element.type == "dynamic") {
|
||||||
"type": "doc",
|
let content =
|
||||||
"content": [
|
Object.keys(element.content).length > 0
|
||||||
{
|
? element.content
|
||||||
"type": "paragraph",
|
: {
|
||||||
"content": [
|
type: "doc",
|
||||||
{
|
content: [
|
||||||
"type": "text",
|
{
|
||||||
"text": "Hello world, this is a example Canva ⚡️"
|
type: "paragraph",
|
||||||
}
|
content: [
|
||||||
]
|
{
|
||||||
}
|
type: "text",
|
||||||
]
|
text: "Hello world, this is a example Canva ⚡️",
|
||||||
}
|
},
|
||||||
console.log("element", content);
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
console.log("element", content);
|
||||||
|
|
||||||
return generateHTML(content, [Document, StarterKit, Paragraph, Text, Bold]);
|
return generateHTML(content, [Document, StarterKit, Paragraph, Text, Bold]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [element.content]);
|
}, [element.content]);
|
||||||
|
|
||||||
|
|
@ -62,7 +68,12 @@ function ElementPage() {
|
||||||
<p>element</p>
|
<p>element</p>
|
||||||
<h1>{element.name} </h1>
|
<h1>{element.name} </h1>
|
||||||
<hr />
|
<hr />
|
||||||
<div dangerouslySetInnerHTML={{ __html: output } as any}></div>
|
|
||||||
|
{element.type == "dynamic" && <div dangerouslySetInnerHTML={{ __html: output } as any}></div>}
|
||||||
|
{/* todo : use apis & streams instead of this */}
|
||||||
|
{element.type == "video" && (
|
||||||
|
<video controls src={`${getBackendUrl()}content/uploads/video/${element.content.video.element_id}/${element.content.video.filename}`}></video>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ async def create_video_element(name: str, coursechapter_id: str, current_user:
|
||||||
# generate element_id
|
# generate element_id
|
||||||
element_id = str(f"element_{uuid4()}")
|
element_id = str(f"element_{uuid4()}")
|
||||||
|
|
||||||
|
video_format = video_file.filename.split(".")[-1]
|
||||||
element_object = ElementInDB(
|
element_object = ElementInDB(
|
||||||
element_id=element_id,
|
element_id=element_id,
|
||||||
coursechapter_id=coursechapter_id,
|
coursechapter_id=coursechapter_id,
|
||||||
|
|
@ -24,7 +25,7 @@ async def create_video_element(name: str, coursechapter_id: str, current_user:
|
||||||
type="video",
|
type="video",
|
||||||
content={
|
content={
|
||||||
"video": {
|
"video": {
|
||||||
"filename": video_file.filename,
|
"filename": "video."+video_format,
|
||||||
"element_id": element_id,
|
"element_id": element_id,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
@ -45,6 +46,8 @@ async def create_video_element(name: str, coursechapter_id: str, current_user:
|
||||||
# upload video
|
# upload video
|
||||||
if video_file:
|
if video_file:
|
||||||
print("uploading video")
|
print("uploading video")
|
||||||
|
# get videofile format
|
||||||
|
|
||||||
await upload_video(video_file, video_file.filename, element_id)
|
await upload_video(video_file, video_file.filename, element_id)
|
||||||
|
|
||||||
# todo : choose whether to update the chapter or not
|
# todo : choose whether to update the chapter or not
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,12 @@ async def upload_thumbnail(thumbnail_file, name_in_disk):
|
||||||
|
|
||||||
async def upload_video(video_file, name_in_disk, element_id):
|
async def upload_video(video_file, name_in_disk, element_id):
|
||||||
contents = video_file.file.read()
|
contents = video_file.file.read()
|
||||||
|
video_format = video_file.filename.split(".")[-1]
|
||||||
# create folder
|
# create folder
|
||||||
os.mkdir(f"content/uploads/video/{element_id}")
|
os.mkdir(f"content/uploads/video/{element_id}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(f"content/uploads/video/{element_id}/{name_in_disk}", 'wb') as f:
|
with open(f"content/uploads/video/{element_id}/video.{video_format}", 'wb') as f:
|
||||||
f.write(contents)
|
f.write(contents)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue