fix: Fix file not found error with individual recipe export/download. (#3579)

This commit is contained in:
nephlm
2024-05-20 18:53:14 -04:00
committed by GitHub
parent c610ec1344
commit c70a5cb72c
6 changed files with 115 additions and 80 deletions

View File

@@ -1,10 +1,9 @@
import shutil
from pathlib import Path
from fastapi import Depends, File, HTTPException, UploadFile, status
from fastapi import File, HTTPException, UploadFile, status
from pydantic import UUID4
from mealie.core.dependencies.dependencies import temporary_dir
from mealie.core.dependencies import get_temporary_path
from mealie.pkgs import cache, img
from mealie.routes._base import BaseUserController, controller
from mealie.routes._base.routers import UserAPIRouter
@@ -21,19 +20,19 @@ class UserImageController(BaseUserController):
self,
id: UUID4,
profile: UploadFile = File(...),
temp_dir: Path = Depends(temporary_dir),
):
"""Updates a User Image"""
assert_user_change_allowed(id, self.user)
temp_img = temp_dir.joinpath(profile.filename)
with get_temporary_path() as temp_path:
assert_user_change_allowed(id, self.user)
temp_img = temp_path.joinpath(profile.filename)
with temp_img.open("wb") as buffer:
shutil.copyfileobj(profile.file, buffer)
with temp_img.open("wb") as buffer:
shutil.copyfileobj(profile.file, buffer)
image = img.PillowMinifier.to_webp(temp_img)
dest = PrivateUser.get_directory(id) / "profile.webp"
image = img.PillowMinifier.to_webp(temp_img)
dest = PrivateUser.get_directory(id) / "profile.webp"
shutil.copyfile(image, dest)
shutil.copyfile(image, dest)
self.repos.users.patch(id, {"cache_key": cache.new_key()})