✨ Added info if quiz on kahoot is private
This commit is contained in:
@@ -14,17 +14,11 @@ class _Response(BaseModel):
|
|||||||
kahoot: _Kahoot
|
kahoot: _Kahoot
|
||||||
|
|
||||||
|
|
||||||
async def get(game_id: str) -> _Response | None:
|
async def get(game_id: str) -> _Response | int:
|
||||||
async with ClientSession() as session, session.get(
|
async with ClientSession() as session, session.get(
|
||||||
f"https://create.kahoot.it/rest/kahoots/{game_id}/card/?includeKahoot=true"
|
f"https://create.kahoot.it/rest/kahoots/{game_id}/card/?includeKahoot=true"
|
||||||
) as response:
|
) as response:
|
||||||
if response.status == 200:
|
if response.status == 200:
|
||||||
return _Response(**await response.json())
|
return _Response(**await response.json())
|
||||||
elif response.status == 404:
|
|
||||||
return None
|
|
||||||
elif response.status == 400:
|
|
||||||
return None
|
|
||||||
elif response.status == 403:
|
|
||||||
return None
|
|
||||||
else:
|
else:
|
||||||
raise Exception(f"Unexpected response status: {response.status}")
|
return response.status
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ async def handle_image_upload(url: str, user: User) -> StorageItem:
|
|||||||
return file_obj
|
return file_obj
|
||||||
|
|
||||||
|
|
||||||
async def import_quiz(quiz_id: str, user: User) -> Quiz | str:
|
async def import_quiz(quiz_id: str, user: User) -> Quiz | int:
|
||||||
"""
|
"""
|
||||||
Imports a quiz from Kahoot.
|
Imports a quiz from Kahoot.
|
||||||
:param user: The user object
|
:param user: The user object
|
||||||
@@ -56,8 +56,8 @@ async def import_quiz(quiz_id: str, user: User) -> Quiz | str:
|
|||||||
"""
|
"""
|
||||||
kahoot_quiz_id = quiz_id
|
kahoot_quiz_id = quiz_id
|
||||||
quiz = await get_quiz(kahoot_quiz_id)
|
quiz = await get_quiz(kahoot_quiz_id)
|
||||||
if quiz is None:
|
if type(quiz) is int:
|
||||||
return "quiz not found"
|
return quiz
|
||||||
quiz_questions: list[dict] = []
|
quiz_questions: list[dict] = []
|
||||||
quiz_id = uuid.uuid4()
|
quiz_id = uuid.uuid4()
|
||||||
meilisearch.delete_index(settings.meilisearch_index)
|
meilisearch.delete_index(settings.meilisearch_index)
|
||||||
|
|||||||
@@ -171,11 +171,14 @@ async def get_quiz_list(user: User = Depends(get_current_user), page_size: int |
|
|||||||
async def import_quiz_route(quiz_id: str, user: User = Depends(get_current_user)):
|
async def import_quiz_route(quiz_id: str, user: User = Depends(get_current_user)):
|
||||||
if user.storage_used > settings.free_storage_limit:
|
if user.storage_used > settings.free_storage_limit:
|
||||||
raise HTTPException(status_code=409, detail="Storage limit reached")
|
raise HTTPException(status_code=409, detail="Storage limit reached")
|
||||||
|
resp_data = await import_quiz(quiz_id, user)
|
||||||
try:
|
try:
|
||||||
return await import_quiz(quiz_id, user)
|
if type(resp_data) is int:
|
||||||
except ValidationError as e:
|
raise HTTPException(status_code=resp_data, detail="kahoot")
|
||||||
print(e)
|
else:
|
||||||
raise HTTPException(status_code=400, detail="This quiz isn't (yet) supported")
|
return resp_data
|
||||||
|
except ValidationError:
|
||||||
|
raise HTTPException(400, detail="unsupported")
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/delete/{quiz_id}")
|
@router.delete("/delete/{quiz_id}")
|
||||||
|
|||||||
@@ -44,13 +44,15 @@ SPDX-License-Identifier: MPL-2.0
|
|||||||
body: "This quiz isn't (yet) supported!"
|
body: "This quiz isn't (yet) supported!"
|
||||||
});*/
|
});*/
|
||||||
alert("This quiz isn't (yet) supported!");
|
alert("This quiz isn't (yet) supported!");
|
||||||
} else {
|
} else if (res.status === 403) {
|
||||||
/* alertModal.set({
|
/* alertModal.set({
|
||||||
open: true,
|
open: true,
|
||||||
title: 'Import failed',
|
title: 'Import failed',
|
||||||
body: 'Unknown error while importing the quiz!'
|
body: 'Unknown error while importing the quiz!'
|
||||||
});*/
|
});*/
|
||||||
alert('Import failed with unknown reason');
|
alert('Quiz is probably private!');
|
||||||
|
} else {
|
||||||
|
alert(`Kahoot replied with ${res.status}`);
|
||||||
}
|
}
|
||||||
is_loading = false;
|
is_loading = false;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user