Skip to content

Commit

Permalink
Merge pull request #650 from zurdi15/fix/user_custom_avatar
Browse files Browse the repository at this point in the history
Fixed user custom avatar location
  • Loading branch information
zurdi15 authored Feb 9, 2024
2 parents 2cf073c + 0b3b353 commit 0268907
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 2 additions & 1 deletion backend/endpoints/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from fastapi import APIRouter, Depends, HTTPException, Request, status
from handler import auth_handler, db_user_handler, fs_asset_handler
from models.user import Role, User
from config import ASSETS_BASE_PATH

router = APIRouter()

Expand Down Expand Up @@ -133,7 +134,7 @@ def update_user(
user_avatar_path = fs_asset_handler.build_avatar_path(user=user)
file_location = f"{user_avatar_path}/{form_data.avatar.filename}"
cleaned_data["avatar_path"] = file_location
with open(file_location, "wb+") as file_object:
with open(f"{ASSETS_BASE_PATH}/{file_location}", "wb+") as file_object:
file_object.write(form_data.avatar.file.read())

if cleaned_data:
Expand Down
4 changes: 1 addition & 3 deletions backend/handler/fs_handler/fs_assets_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ def user_folder_path(self, user: User):

# /users/557365723a31/profile
def build_avatar_path(self, user: User):
user_avatar_path = os.path.join(
ASSETS_BASE_PATH, self.user_folder_path(user), "profile"
)
user_avatar_path = os.path.join(self.user_folder_path(user), "profile")
Path(user_avatar_path).mkdir(parents=True, exist_ok=True)
return user_avatar_path

Expand Down

0 comments on commit 0268907

Please sign in to comment.