Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
fixup! media/upload: add support for async uploads
Browse files Browse the repository at this point in the history
Signed-off-by: Sumner Evans <me@sumnerevans.com>
  • Loading branch information
sumnerevans committed Nov 9, 2023
1 parent 961bfa0 commit b49a50b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions synapse/media/media_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,14 @@ async def verify_can_upload(self, media_id: str, auth_user: UserID) -> None:
if media is None:
raise SynapseError(404, "Unknow media ID", errcode=Codes.NOT_FOUND)

if media["user_id"] != auth_user.to_string():
if media.user_id != auth_user.to_string():
raise SynapseError(
403,
"Only the creator of the media ID can upload to it",
errcode=Codes.FORBIDDEN,
)

if media.get("media_length") is not None:
if media.media_length is not None:
raise SynapseError(
409,
"Media ID already has content",
Expand Down
8 changes: 6 additions & 2 deletions synapse/storage/databases/main/media_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@
class LocalMedia:
media_id: str
media_type: str
media_length: int
media_length: Optional[int]
upload_name: str
created_ts: int
url_cache: Optional[str]
last_access_ts: int
quarantined_by: Optional[str]
safe_from_quarantine: bool
user_id: Optional[str]


@attr.s(slots=True, frozen=True, auto_attribs=True)
Expand Down Expand Up @@ -222,6 +223,7 @@ async def get_local_media(self, media_id: str) -> Optional[LocalMedia]:
url_cache=row[5],
last_access_ts=row[6],
safe_from_quarantine=row[7],
user_id=row[8],
)

async def get_local_media_by_user_paginate(
Expand Down Expand Up @@ -276,7 +278,8 @@ def get_local_media_by_user_paginate_txn(
url_cache,
last_access_ts,
quarantined_by,
safe_from_quarantine
safe_from_quarantine,
user_id
FROM local_media_repository
WHERE user_id = ?
ORDER BY {order_by_column} {order}, media_id ASC
Expand All @@ -299,6 +302,7 @@ def get_local_media_by_user_paginate_txn(
last_access_ts=row[6],
quarantined_by=row[7],
safe_from_quarantine=bool(row[8]),
user_id=row[9],
)
for row in txn
]
Expand Down

0 comments on commit b49a50b

Please sign in to comment.