Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Aug 22, 2024
1 parent a0bd017 commit 080ab20
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
14 changes: 8 additions & 6 deletions server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
NotFoundException,
)
from litestar.response import Template
from litestar.static_files import create_static_files_router
from litestar.status_codes import HTTP_500_INTERNAL_SERVER_ERROR
from litestar.stores.redis import RedisStore
from litestar.template import TemplateConfig
Expand Down Expand Up @@ -71,13 +72,14 @@ def static_file_handler(fp: str) -> Response[bytes]:

else:

@router
@litestar.get("/static/{fp:path}", sync_to_thread=True)
def static_file_handler(fp: str) -> Response[bytes]:
# fp is '/...', so we need to remove prefix make it relative
return Response(
static_path.joinpath(fp[1:]).read_bytes(), media_type=mimetypes.guess_type(fp)[0]
router(
create_static_files_router(
path="/static/",
directories=[static_path],
send_as_attachment=False,
html_mode=False,
)
)


async def __fetch_users(rows: list[asyncpg.Record]) -> dict[int, asyncpg.Record]:
Expand Down
3 changes: 2 additions & 1 deletion server/router.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from collections.abc import Iterator

import litestar
from litestar.types import AnyCallable
from typing_extensions import TypeVar


T = TypeVar("T", bound=AnyCallable)
T = TypeVar("T", bound=AnyCallable | litestar.Router)


class Router:
Expand Down

0 comments on commit 080ab20

Please sign in to comment.