mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
fix: typing issues
This commit is contained in:
parent
193b3b289f
commit
9cd1ec35cf
5 changed files with 24 additions and 24 deletions
|
|
@ -25,7 +25,7 @@ async def api_get_current_user(current_user: User = Depends(get_current_user)):
|
||||||
return current_user.dict()
|
return current_user.dict()
|
||||||
|
|
||||||
@router.get("/profile_metadata")
|
@router.get("/profile_metadata")
|
||||||
async def api_get_current_user(current_user: User = Depends(get_current_user)):
|
async def api_get_current_user_metadata(current_user: User = Depends(get_current_user)):
|
||||||
"""
|
"""
|
||||||
Get current user
|
Get current user
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ from src.services.users import PublicUser
|
||||||
from fastapi import FastAPI, HTTPException, status, Request, Response, BackgroundTasks, UploadFile, File
|
from fastapi import FastAPI, HTTPException, status, Request, Response, BackgroundTasks, UploadFile, File
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CourseChapter(BaseModel):
|
class CourseChapter(BaseModel):
|
||||||
name: str
|
name: str
|
||||||
description: str
|
description: str
|
||||||
|
|
@ -187,21 +186,19 @@ async def get_coursechapters_meta(course_id: str, current_user: PublicUser):
|
||||||
chapters[coursechapter.coursechapter_id] = {
|
chapters[coursechapter.coursechapter_id] = {
|
||||||
"id": coursechapter.coursechapter_id, "name": coursechapter.name, "elementIds": coursechapter_elementIds
|
"id": coursechapter.coursechapter_id, "name": coursechapter.name, "elementIds": coursechapter_elementIds
|
||||||
}
|
}
|
||||||
|
|
||||||
# elements
|
# elements
|
||||||
elements_list = {}
|
elements_list = {}
|
||||||
for element in elements.find({"element_id": {"$in": coursechapter_elementIds_global}}):
|
for element in elements.find({"element_id": {"$in": coursechapter_elementIds_global}}):
|
||||||
element = ElementInDB(**element)
|
element = ElementInDB(**element)
|
||||||
elements_list[element.element_id] = {
|
elements_list[element.element_id] = {
|
||||||
"id": element.element_id, "name": element.name, "type": element.type , "content": element.content
|
"id": element.element_id, "name": element.name, "type": element.type, "content": element.content
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
final = {
|
final = {
|
||||||
"chapters": chapters,
|
"chapters": chapters,
|
||||||
"chapterOrder": course.chapters,
|
"chapterOrder": course.chapters,
|
||||||
"elements" : elements_list
|
"elements": elements_list
|
||||||
}
|
}
|
||||||
|
|
||||||
return final
|
return final
|
||||||
|
|
@ -216,16 +213,13 @@ async def update_coursechapters_meta(course_id: str, coursechapters_metadata: Co
|
||||||
courseInDB = courses.update_one({"course_id": course_id}, {
|
courseInDB = courses.update_one({"course_id": course_id}, {
|
||||||
"$set": {"chapters": coursechapters_metadata.chapterOrder}})
|
"$set": {"chapters": coursechapters_metadata.chapterOrder}})
|
||||||
|
|
||||||
|
|
||||||
# update elements in coursechapters
|
# update elements in coursechapters
|
||||||
# TODO : performance/optimization improvement
|
# TODO : performance/optimization improvement
|
||||||
for coursechapter in coursechapters_metadata.chapters:
|
for coursechapter in coursechapters_metadata.chapters.__dict__.items():
|
||||||
coursechapters.update_one({"coursechapter_id": coursechapter}, {
|
coursechapters.update_one({"coursechapter_id": coursechapter}, {
|
||||||
"$set": {"elements": coursechapters_metadata.chapters[coursechapter]["elementIds"]}})
|
"$set": {"elements": coursechapters_metadata.chapters[coursechapter]["elementIds"]}})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return {"ok"}
|
return {"detail": "coursechapters metadata updated"}
|
||||||
|
|
||||||
#### Security ####################################################
|
#### Security ####################################################
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,11 @@ 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()}")
|
||||||
|
|
||||||
|
# check if video_file is not None
|
||||||
|
if not video_file:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_409_CONFLICT, detail="Video : No video file provided")
|
||||||
|
|
||||||
video_format = video_file.filename.split(".")[-1]
|
video_format = video_file.filename.split(".")[-1]
|
||||||
element_object = ElementInDB(
|
element_object = ElementInDB(
|
||||||
element_id=element_id,
|
element_id=element_id,
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@ async def create_picture_file(picture_file: UploadFile, element_id: str):
|
||||||
|
|
||||||
# create file
|
# create file
|
||||||
file = await picture_file.read()
|
file = await picture_file.read()
|
||||||
|
|
||||||
|
|
||||||
# get file size
|
# get file size
|
||||||
file_size = len(file)
|
file_size = len(file)
|
||||||
|
|
@ -95,14 +94,15 @@ async def get_picture_file(file_id: str, current_user: PublicUser):
|
||||||
|
|
||||||
photo_file = photos.find_one({"file_id": file_id})
|
photo_file = photos.find_one({"file_id": file_id})
|
||||||
|
|
||||||
# check media type
|
|
||||||
if photo_file.format not in ["jpg", "jpeg", "png", "gif"]:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_409_CONFLICT, detail="Photo file format not supported")
|
|
||||||
|
|
||||||
# TODO : check if user has access to file
|
# TODO : check if user has access to file
|
||||||
|
|
||||||
if photo_file:
|
if photo_file:
|
||||||
|
|
||||||
|
# check media type
|
||||||
|
if photo_file.format not in ["jpg", "jpeg", "png", "gif"]:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_409_CONFLICT, detail="Photo file format not supported")
|
||||||
|
|
||||||
# stream file
|
# stream file
|
||||||
photo_file = PhotoFile(**photo_file)
|
photo_file = PhotoFile(**photo_file)
|
||||||
file_format = photo_file.file_format
|
file_format = photo_file.file_format
|
||||||
|
|
|
||||||
|
|
@ -94,14 +94,15 @@ async def get_video_file(file_id: str, current_user: PublicUser):
|
||||||
|
|
||||||
video_file = photos.find_one({"file_id": file_id})
|
video_file = photos.find_one({"file_id": file_id})
|
||||||
|
|
||||||
# check media type
|
|
||||||
if video_file.format not in ["mp4", "webm", "ogg"]:
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_409_CONFLICT, detail="Video file format not supported")
|
|
||||||
|
|
||||||
# TODO : check if user has access to file
|
# TODO : check if user has access to file
|
||||||
|
|
||||||
if video_file:
|
if video_file:
|
||||||
|
|
||||||
|
# check media type
|
||||||
|
if video_file.format not in ["mp4", "webm", "ogg"]:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_409_CONFLICT, detail="Video file format not supported")
|
||||||
|
|
||||||
# stream file
|
# stream file
|
||||||
video_file = VideoFile(**video_file)
|
video_file = VideoFile(**video_file)
|
||||||
file_format = video_file.file_format
|
file_format = video_file.file_format
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue