Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 25, 2024
1 parent c240b83 commit ce31cab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion classquiz/routers/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ async def upload_raw_file(request: Request, user: User = Depends(get_current_use


@router.post("/raw/{filename}")
async def upload_raw_file_with_filename(filename: str, request: Request, user: User = Depends(get_current_user)) -> PublicStorageItem:
async def upload_raw_file_with_filename(
filename: str, request: Request, user: User = Depends(get_current_user)
) -> PublicStorageItem:
if user.storage_used > settings.free_storage_limit:
raise HTTPException(status_code=409, detail="Storage limit reached")
file_id = uuid4()
Expand Down
12 changes: 10 additions & 2 deletions classquiz/worker/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ async def calculate_hash(ctx, file_id_as_str: str):
user.storage_used += file_data.size
await user.update()

async def manage_resources(removed_images: list[str | uuid.UUID], removed_musics: list[str | uuid.UUID], added_images: list[str | uuid.UUID], added_musics: list[str | uuid.UUID], new_quiz: Quiz):

async def manage_resources(
removed_images: list[str | uuid.UUID],
removed_musics: list[str | uuid.UUID],
added_images: list[str | uuid.UUID],
added_musics: list[str | uuid.UUID],
new_quiz: Quiz,
):
change_made = False
for image in removed_images:
if "--" in image:
Expand Down Expand Up @@ -112,6 +119,7 @@ async def manage_resources(removed_images: list[str | uuid.UUID], removed_musics

return change_made


# skipcq: PYL-W0613
async def quiz_update(ctx, old_quiz: Quiz, quiz_id: uuid.UUID):
new_quiz: Quiz = await Quiz.objects.get(id=quiz_id)
Expand All @@ -131,7 +139,7 @@ async def quiz_update(ctx, old_quiz: Quiz, quiz_id: uuid.UUID):
added_images = list(set(new_images) - set(old_images))
added_musics = list(set(new_musics) - set(old_musics))

change_made = await manage_resources(removed_images, removed_musics, added_images, added_musics, new_quiz);
change_made = await manage_resources(removed_images, removed_musics, added_images, added_musics, new_quiz)

if change_made:
await new_quiz.update()

0 comments on commit ce31cab

Please sign in to comment.