Skip to content

Commit ccebd40

Browse files
committed
Fixes
1 parent ecc7199 commit ccebd40

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

lib/callbacks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def raise_http_exception(request: Request) -> Callable[[Exception | str], Awaita
2424
"""Callback to raise an HTTPException with a specific status code."""
2525

2626
async def _raise_http_exception(error: Exception | str) -> None:
27-
code = error.status_code if isinstance(error, HTTPException) else 405
27+
code = error.status_code if isinstance(error, HTTPException) else 502
2828
raise StreamTerminated(f"{code}: {str(error)}") from error
2929

3030
return _raise_http_exception

lib/metadata.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from starlette.datastructures import Headers
2-
from pydantic import BaseModel, Field, field_validator, ByteSize, ConfigDict, AliasChoices
2+
from pydantic import BaseModel, Field, StrictStr, field_validator, ByteSize, ConfigDict, AliasChoices
33
from typing import Optional, Self, Annotated
44

55

66
class FileMetadata(BaseModel):
7-
name: str = Field(description="File name", min_length=1, max_length=255)
7+
name: StrictStr = Field(description="File name", min_length=1, max_length=255)
88
size: ByteSize = Field(description="Size in bytes", gt=0)
9-
type: str = Field(description="MIME type", default='application/octet-stream')
9+
type: StrictStr = Field(description="MIME type", default='application/octet-stream')
1010

1111
model_config = ConfigDict(title="File transfer metadata", alias_generator=lambda s: f'file_{s}', populate_by_name=True, validate_by_name=True)
1212

@@ -29,7 +29,7 @@ def get_from_http_headers(cls, headers: Headers, filename: str) -> Self:
2929
return cls(
3030
name=filename,
3131
size=headers.get('content-length', '0'),
32-
type=headers.get('content-type', '')
32+
type=headers.get('content-type', '') # Must be a string
3333
)
3434

3535
@classmethod

lib/transfer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ async def consume_upload(self, stream: AsyncIterator[bytes], on_error: Callable[
9191
raise TransferError("Incomplete upload", propagate=True)
9292

9393
await self.store.add_chunk(self.DONE_FLAG)
94-
self.debug(f"△ Upload complete: {self.bytes_uploaded} bytes")
94+
self.debug(f"△ All data chunks uploaded: {self.bytes_uploaded} bytes")
9595

9696
except (ClientDisconnect, WebSocketDisconnect):
9797
self.error(f"△ Sender disconnected")
@@ -122,7 +122,7 @@ async def produce_download(self, on_error: Callable[[Exception | str], Awaitable
122122

123123
if chunk == self.DONE_FLAG:
124124
if self.bytes_downloaded >= self.file.size:
125-
self.debug(f"▼ Download complete: {self.bytes_downloaded} bytes")
125+
self.debug(f"▼ All data chunks downloaded: {self.bytes_downloaded} bytes")
126126
break
127127

128128
self.bytes_downloaded += len(chunk)

views/http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async def http_upload(request: Request, uid: str, filename: str):
3737
raise HTTPException(status_code=400, detail="Cannot decode file metadata from HTTP headers.")
3838
except ValidationError as e:
3939
log.error("△ Invalid file metadata.", exc_info=e)
40-
raise HTTPException(status_code=400, detail=f"Invalid file metadata: {e.errors(False, False, True)}")
40+
raise HTTPException(status_code=400, detail=f"Invalid file metadata: {e.errors(include_url=False, include_context=True, include_input=False)}")
4141

4242
if file.size > 1024**3:
4343
raise HTTPException(status_code=413, detail="File too large. 1GiB maximum for HTTP.")

0 commit comments

Comments
 (0)