Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add image serving #57

Merged
merged 2 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions app/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import asyncio
import time
import uuid
from pathlib import Path
from typing import Annotated
Expand All @@ -15,6 +15,7 @@
)
from fastapi.responses import HTMLResponse, PlainTextResponse
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from fastapi_filter import FilterDepends
from fastapi_pagination import Page, add_pagination
Expand Down Expand Up @@ -123,7 +124,7 @@ def authentication(
crud.create_user(db, user=user)
return {"access_token": token, "token_type": "bearer"}
elif r.status_code == 403:
asyncio.sleep(2) # prevents brute-force
time.sleep(2) # prevents brute-force
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Invalid authentication credentials",
Expand Down Expand Up @@ -253,3 +254,4 @@ def robots_txt():


add_pagination(app)
app.mount("/images", StaticFiles(directory=str(settings.images_dir)), name="images")
3 changes: 2 additions & 1 deletion app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pydantic_settings import BaseSettings, SettingsConfigDict

ROOT_DIR = Path(__file__).parent.parent
DATA_DIR = ROOT_DIR / "data"


class LoggingLevel(Enum):
Expand Down Expand Up @@ -38,7 +39,7 @@ class Settings(BaseSettings):
oauth2_server_url: str | None = None
sentry_dns: str | None = None
log_level: LoggingLevel = LoggingLevel.INFO
images_dir: Path = ROOT_DIR / "data/images"
images_dir: Path = DATA_DIR / "images"

model_config = SettingsConfigDict(env_file=".env", extra="ignore")

Expand Down
Loading