mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Port synaps/rest/client/media.py to async/await
This commit is contained in:
parent
fca3a541e7
commit
281f887090
@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from twisted.internet import defer
|
|
||||||
|
|
||||||
from synapse.api.errors import AuthError
|
from synapse.api.errors import AuthError
|
||||||
from synapse.http.servlet import RestServlet, parse_integer
|
from synapse.http.servlet import RestServlet, parse_integer
|
||||||
from synapse.rest.admin._base import (
|
from synapse.rest.admin._base import (
|
||||||
@ -40,12 +38,11 @@ class QuarantineMediaInRoom(RestServlet):
|
|||||||
self.store = hs.get_datastore()
|
self.store = hs.get_datastore()
|
||||||
self.auth = hs.get_auth()
|
self.auth = hs.get_auth()
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
async def on_POST(self, request, room_id):
|
||||||
def on_POST(self, request, room_id):
|
requester = await self.auth.get_user_by_req(request)
|
||||||
requester = yield self.auth.get_user_by_req(request)
|
await assert_user_is_admin(self.auth, requester.user)
|
||||||
yield assert_user_is_admin(self.auth, requester.user)
|
|
||||||
|
|
||||||
num_quarantined = yield self.store.quarantine_media_ids_in_room(
|
num_quarantined = await self.store.quarantine_media_ids_in_room(
|
||||||
room_id, requester.user.to_string()
|
room_id, requester.user.to_string()
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -62,14 +59,13 @@ class ListMediaInRoom(RestServlet):
|
|||||||
self.store = hs.get_datastore()
|
self.store = hs.get_datastore()
|
||||||
self.auth = hs.get_auth()
|
self.auth = hs.get_auth()
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
async def on_GET(self, request, room_id):
|
||||||
def on_GET(self, request, room_id):
|
requester = await self.auth.get_user_by_req(request)
|
||||||
requester = yield self.auth.get_user_by_req(request)
|
is_admin = await self.auth.is_server_admin(requester.user)
|
||||||
is_admin = yield self.auth.is_server_admin(requester.user)
|
|
||||||
if not is_admin:
|
if not is_admin:
|
||||||
raise AuthError(403, "You are not a server admin")
|
raise AuthError(403, "You are not a server admin")
|
||||||
|
|
||||||
local_mxcs, remote_mxcs = yield self.store.get_media_mxcs_in_room(room_id)
|
local_mxcs, remote_mxcs = await self.store.get_media_mxcs_in_room(room_id)
|
||||||
|
|
||||||
return 200, {"local": local_mxcs, "remote": remote_mxcs}
|
return 200, {"local": local_mxcs, "remote": remote_mxcs}
|
||||||
|
|
||||||
@ -81,14 +77,13 @@ class PurgeMediaCacheRestServlet(RestServlet):
|
|||||||
self.media_repository = hs.get_media_repository()
|
self.media_repository = hs.get_media_repository()
|
||||||
self.auth = hs.get_auth()
|
self.auth = hs.get_auth()
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
async def on_POST(self, request):
|
||||||
def on_POST(self, request):
|
await assert_requester_is_admin(self.auth, request)
|
||||||
yield assert_requester_is_admin(self.auth, request)
|
|
||||||
|
|
||||||
before_ts = parse_integer(request, "before_ts", required=True)
|
before_ts = parse_integer(request, "before_ts", required=True)
|
||||||
logger.info("before_ts: %r", before_ts)
|
logger.info("before_ts: %r", before_ts)
|
||||||
|
|
||||||
ret = yield self.media_repository.delete_old_remote_media(before_ts)
|
ret = await self.media_repository.delete_old_remote_media(before_ts)
|
||||||
|
|
||||||
return 200, ret
|
return 200, ret
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user