Update.
This commit is contained in:
parent
c5b55399a1
commit
93462d4c4b
src/snek
@ -61,6 +61,8 @@ class SocketService(BaseService):
|
||||
async def add(self, ws, user_uid):
|
||||
s = self.Socket(ws, await self.app.services.user.get(uid=user_uid))
|
||||
self.sockets.add(s)
|
||||
s.user["last_ping"] = now()
|
||||
await self.app.services.user.save(s.user)
|
||||
logger.info(f"Added socket for user {s.user['username']}")
|
||||
if not self.users.get(user_uid):
|
||||
self.users[user_uid] = set()
|
||||
@ -89,8 +91,7 @@ class SocketService(BaseService):
|
||||
async for user_uid in self.services.channel_member.get_user_uids(
|
||||
channel_uid
|
||||
):
|
||||
await self.send_to_user(user_uid, message)
|
||||
sent += 1
|
||||
sent += await self.send_to_user(user_uid, message)
|
||||
except Exception as ex:
|
||||
print(ex, flush=True)
|
||||
logger.info(f"Broadcasted a message to {sent} users.")
|
||||
|
@ -144,9 +144,11 @@
|
||||
getInputField().focus();
|
||||
})
|
||||
document.querySelector("upload-button").addEventListener("uploaded",function(e){
|
||||
let message = ""
|
||||
e.detail.files.forEach((file)=>{
|
||||
app.rpc.sendMessage(channelUid,`[${file.name}](/channel/attachment/${file.relative_url})`)
|
||||
message += `[${file.name}](/channel/attachment/${file.relative_url})`
|
||||
})
|
||||
app.rpc.sendMessage(channelUid,message)
|
||||
})
|
||||
textBox.addEventListener("paste", async (e) => {
|
||||
try {
|
||||
|
@ -17,20 +17,21 @@ class ChannelAttachmentView(BaseView):
|
||||
relative_url=relative_path
|
||||
)
|
||||
|
||||
current_format = mimetypes.guess_type(channel_attachment["path"])[0]
|
||||
|
||||
format = self.request.query.get("format")
|
||||
original_format = mimetypes.guess_type(channel_attachment["path"])[0]
|
||||
format_ = self.request.query.get("format")
|
||||
width = self.request.query.get("width")
|
||||
height = self.request.query.get("height")
|
||||
|
||||
if any([format, width, height]) and current_format.startswith("image/"):
|
||||
if any([format_, width, height]) and original_format.startswith("image/"):
|
||||
if not format_:
|
||||
format_ = original_format.split("/")[1]
|
||||
with Image.open(channel_attachment["path"]) as image:
|
||||
response = web.StreamResponse(
|
||||
status=200,
|
||||
reason="OK",
|
||||
headers={
|
||||
"Cache-Control": f"public, max-age={1337 * 420}",
|
||||
"Content-Type": f"image/{format}" if format else current_format,
|
||||
"Content-Type": f"image/{format_}",
|
||||
"Content-Disposition": f'attachment; filename="{channel_attachment["name"]}"',
|
||||
},
|
||||
)
|
||||
@ -65,19 +66,21 @@ class ChannelAttachmentView(BaseView):
|
||||
)
|
||||
|
||||
await response.prepare(self.request)
|
||||
|
||||
# response.write is async but image.save is not
|
||||
naughty_steal = response.write
|
||||
loop = asyncio.get_event_loop()
|
||||
|
||||
tasks = []
|
||||
def sync_writer(*args, **kwargs):
|
||||
return loop.run_until_complete(naughty_steal(*args, **kwargs))
|
||||
|
||||
tasks.append(naughty_steal(*args, **kwargs))
|
||||
return True
|
||||
|
||||
setattr(response, "write", sync_writer)
|
||||
|
||||
image.save(response, format=self.request.query["format"])
|
||||
image.save(response, format=format_)
|
||||
|
||||
setattr(response, "write", naughty_steal)
|
||||
|
||||
await asyncio.gather(*tasks)
|
||||
|
||||
return response
|
||||
else:
|
||||
response = web.FileResponse(channel_attachment["path"])
|
||||
|
Loading…
Reference in New Issue
Block a user