Skip to content
Draft
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: 5 additions & 1 deletion lenny/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
CORSMiddleware,
allow_origins=[
"http://localhost:3000",
"http://127.0.0.1:3000"
"http://127.0.0.1:3000",
"http://localhost:3001",
"http://127.0.0.1:3001",
"http://localhost:3002",

],
allow_credentials=True,
allow_methods=["*"],
Expand Down
2 changes: 1 addition & 1 deletion lenny/core/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def _resolve_ip_to_hostname(cls, client_ip: str) -> str:

@classmethod
def is_allowed_uploader(cls, client_ip: str) -> bool:
if client_ip in ("127.0.0.1", "::1"):
if client_ip in ("127.0.0.1", "::1") or client_ip.startswith("172.18.0."): # localhost and docker internal
return True

if host := cls._resolve_ip_to_hostname(client_ip):
Expand Down
10 changes: 7 additions & 3 deletions lenny/routes/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,13 @@ async def upload(
):

try:
item = LennyAPI.add(
if item := Item.exists(openlibrary_edition):
return HTMLResponse(
status_code=status.HTTP_409_CONFLICT,
content=f"Item with OpenLibrary Edition ID {openlibrary_edition} already exists."
)
if not item:
LennyAPI.add(
openlibrary_edition=openlibrary_edition,
files=[file], # TODO expand to allow multiple
uploader_ip=request.client.host,
Expand All @@ -201,8 +207,6 @@ async def upload(
)
except UploaderNotAllowedError as e:
raise HTTPException(status_code=503, details=str(e))
except ItemExistsError as e:
raise HTTPException(status_code=409, detail=str(e))
except InvalidFileError as e:
raise HTTPException(status_code=400, detail=str(e))
except DatabaseInsertError as e:
Expand Down