Skip to content

Commit

Permalink
хранение обновлённых фото профиля в отдельном volume: backend_static
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyHlim committed Jul 5, 2024
1 parent 368d5e0 commit 8d9f809
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/models/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

def _random_photo(path: Path):
"""Возвращает рандомный файл из указанной папки."""
files = [f'cats/{file.name}' for file in path.iterdir()]
files = [f'default_photo/{file.name}' for file in path.iterdir()]
random_index = randint(0, len(files) - 1)
return str(files[random_index])

Expand All @@ -44,7 +44,7 @@ class Profile(Base):
image: Mapped[str] = Column(
String(),
nullable=True,
default=_random_photo(settings.base_dir / settings.media_url / 'cats/')
default=_random_photo(settings.base_dir / settings.media_url / 'default_photo/')
)

def __repr__(self):
Expand Down
2 changes: 1 addition & 1 deletion app/services/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def end(self):
def create_filename(file: UploadFile) -> str:
"""Создаёт имя файла."""
file_extension = file.filename.split('.')[-1]
return f'{uuid4()}.{file_extension}'
return f'photo_profile/{uuid4()}.{file_extension}'


async def save_content(file: UploadFile):
Expand Down
3 changes: 3 additions & 0 deletions infra/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ services:
- ./.env
depends_on:
- db
volumes:
- backend_static:/app/media/photo_profile/

nginx:
container_name: proxy
Expand All @@ -39,3 +41,4 @@ services:

volumes:
db_volume_qactf:
backend_static:
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes

0 comments on commit 8d9f809

Please sign in to comment.