✨ Added info if quiz on kahoot is private
This commit is contained in:
@@ -14,17 +14,11 @@ class _Response(BaseModel):
|
||||
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(
|
||||
f"https://create.kahoot.it/rest/kahoots/{game_id}/card/?includeKahoot=true"
|
||||
) as response:
|
||||
if response.status == 200:
|
||||
return _Response(**await response.json())
|
||||
elif response.status == 404:
|
||||
return None
|
||||
elif response.status == 400:
|
||||
return None
|
||||
elif response.status == 403:
|
||||
return None
|
||||
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
|
||||
|
||||
|
||||
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.
|
||||
: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
|
||||
quiz = await get_quiz(kahoot_quiz_id)
|
||||
if quiz is None:
|
||||
return "quiz not found"
|
||||
if type(quiz) is int:
|
||||
return quiz
|
||||
quiz_questions: list[dict] = []
|
||||
quiz_id = uuid.uuid4()
|
||||
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)):
|
||||
if user.storage_used > settings.free_storage_limit:
|
||||
raise HTTPException(status_code=409, detail="Storage limit reached")
|
||||
resp_data = await import_quiz(quiz_id, user)
|
||||
try:
|
||||
return await import_quiz(quiz_id, user)
|
||||
except ValidationError as e:
|
||||
print(e)
|
||||
raise HTTPException(status_code=400, detail="This quiz isn't (yet) supported")
|
||||
if type(resp_data) is int:
|
||||
raise HTTPException(status_code=resp_data, detail="kahoot")
|
||||
else:
|
||||
return resp_data
|
||||
except ValidationError:
|
||||
raise HTTPException(400, detail="unsupported")
|
||||
|
||||
|
||||
@router.delete("/delete/{quiz_id}")
|
||||
|
||||
@@ -44,13 +44,15 @@ SPDX-License-Identifier: MPL-2.0
|
||||
body: "This quiz isn't (yet) supported!"
|
||||
});*/
|
||||
alert("This quiz isn't (yet) supported!");
|
||||
} else {
|
||||
} else if (res.status === 403) {
|
||||
/* alertModal.set({
|
||||
open: true,
|
||||
title: 'Import failed',
|
||||
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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user