mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-02-07 08:23:12 -05:00
Feature/user photo storage (#877)
* add default assets for user profile * add recipe avatar * change user_id to UUID * add profile image upload * setup image cache keys * cleanup tests and add image tests * purge user data on delete * new user repository tests * add user_id validator for int -> UUID conversion * delete depreciated route * force set content type * refactor tests to use temp directory * validate parent exists before createing * set user_id to correct type * update instruction id * reset primary key on migration
This commit is contained in:
@@ -4,7 +4,7 @@ from pathlib import Path
|
||||
|
||||
import dotenv
|
||||
|
||||
from mealie.core.settings.settings import app_settings_constructor
|
||||
from mealie.core.settings import app_settings_constructor
|
||||
|
||||
from .settings import AppDirectories, AppSettings
|
||||
from .settings.static import APP_VERSION, DB_VERSION
|
||||
@@ -18,11 +18,15 @@ ENV = BASE_DIR.joinpath(".env")
|
||||
|
||||
dotenv.load_dotenv(ENV)
|
||||
PRODUCTION = os.getenv("PRODUCTION", "True").lower() in ["true", "1"]
|
||||
TESTING = os.getenv("TESTING", "True").lower() in ["true", "1"]
|
||||
|
||||
|
||||
def determine_data_dir() -> Path:
|
||||
global PRODUCTION
|
||||
global BASE_DIR
|
||||
global PRODUCTION, TESTING, BASE_DIR
|
||||
|
||||
if TESTING:
|
||||
return BASE_DIR.joinpath("tests/.temp")
|
||||
|
||||
if PRODUCTION:
|
||||
return Path("/app/data")
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import shutil
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from uuid import uuid4
|
||||
@@ -90,7 +91,7 @@ async def get_admin_user(current_user=Depends(get_current_user)) -> PrivateUser:
|
||||
def validate_long_live_token(session: Session, client_token: str, id: int) -> PrivateUser:
|
||||
db = get_database(session)
|
||||
|
||||
tokens: list[LongLiveTokenInDB] = db.api_tokens.get(id, "parent_id", limit=9999)
|
||||
tokens: list[LongLiveTokenInDB] = db.api_tokens.get(id, "user_id", limit=9999)
|
||||
|
||||
for token in tokens:
|
||||
token: LongLiveTokenInDB
|
||||
@@ -150,3 +151,21 @@ async def temporary_dir() -> Path:
|
||||
yield temp_path
|
||||
finally:
|
||||
shutil.rmtree(temp_path)
|
||||
|
||||
|
||||
def temporary_file(ext: str = "") -> Path:
|
||||
"""
|
||||
Returns a temporary file with the specified extension
|
||||
"""
|
||||
|
||||
def func() -> Path:
|
||||
temp_path = app_dirs.TEMP_DIR.joinpath(uuid4().hex + ext)
|
||||
temp_path.touch()
|
||||
|
||||
with tempfile.NamedTemporaryFile(mode="w+b", suffix=ext) as f:
|
||||
try:
|
||||
yield f
|
||||
finally:
|
||||
temp_path.unlink(missing_ok=True)
|
||||
|
||||
return func
|
||||
|
||||
@@ -24,7 +24,7 @@ def create_access_token(data: dict, expires_delta: timedelta = None) -> str:
|
||||
|
||||
expire = datetime.utcnow() + expires_delta
|
||||
|
||||
to_encode.update({"exp": expire})
|
||||
to_encode["exp"] = expire
|
||||
return jwt.encode(to_encode, settings.SECRET, algorithm=ALGORITHM)
|
||||
|
||||
|
||||
|
||||
@@ -57,9 +57,9 @@ class PostgresProvider(AbstractDBProvider, BaseSettings):
|
||||
|
||||
|
||||
def db_provider_factory(provider_name: str, data_dir: Path, env_file: Path, env_encoding="utf-8") -> AbstractDBProvider:
|
||||
if provider_name == "sqlite":
|
||||
return SQLiteProvider(data_dir=data_dir)
|
||||
elif provider_name == "postgres":
|
||||
if provider_name == "postgres":
|
||||
return PostgresProvider(_env_file=env_file, _env_file_encoding=env_encoding)
|
||||
elif provider_name == "sqlite":
|
||||
return SQLiteProvider(data_dir=data_dir)
|
||||
else:
|
||||
return
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
from mealie.assets import templates
|
||||
|
||||
|
||||
class AppDirectories:
|
||||
def __init__(self, data_dir: Path) -> None:
|
||||
@@ -35,3 +38,9 @@ class AppDirectories:
|
||||
|
||||
for dir in required_dirs:
|
||||
dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Boostrap Templates
|
||||
markdown_template = self.TEMPLATE_DIR.joinpath("recipes.md")
|
||||
|
||||
if not markdown_template.exists():
|
||||
shutil.copyfile(templates.recipes_markdown, markdown_template)
|
||||
|
||||
@@ -16,6 +16,7 @@ def determine_secrets(data_dir: Path, production: bool) -> str:
|
||||
with open(secrets_file, "r") as f:
|
||||
return f.read()
|
||||
else:
|
||||
data_dir.mkdir(parents=True, exist_ok=True)
|
||||
with open(secrets_file, "w") as f:
|
||||
new_secret = secrets.token_hex(32)
|
||||
f.write(new_secret)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
APP_VERSION = "v1.0.0b"
|
||||
@@ -6,5 +5,3 @@ DB_VERSION = "v1.0.0b"
|
||||
|
||||
CWD = Path(__file__).parent
|
||||
BASE_DIR = CWD.parent.parent.parent
|
||||
|
||||
PRODUCTION = os.getenv("PRODUCTION", "True").lower() in ["true", "1"]
|
||||
|
||||
Reference in New Issue
Block a user