mirror of https://gitlab.com/litecord/litecord.git
channel.message: fix issues related to file stream
- storage: remove mime fetch
This commit is contained in:
parent
501b82b4f0
commit
7e17b6965e
|
|
@ -27,4 +27,4 @@ bp = Blueprint('attachments', __name__)
|
|||
async def _get_attachment(channel_id: int, message_id: int,
|
||||
filename: str, ext: str):
|
||||
# TODO: get the attachment id with given metadata
|
||||
return
|
||||
return '', 204
|
||||
|
|
|
|||
|
|
@ -377,7 +377,9 @@ async def _add_attachment(message_id: int, channel_id: int,
|
|||
# open with pillow, extract image size
|
||||
image = Image.open(attachment_file.stream)
|
||||
img_width, img_height = image.size
|
||||
image.close()
|
||||
|
||||
# NOTE: DO NOT close the image, as closing the image will
|
||||
# also close the stream.
|
||||
|
||||
# reset it to 0 for later usage
|
||||
attachment_file.stream.seek(0)
|
||||
|
|
@ -397,7 +399,7 @@ async def _add_attachment(message_id: int, channel_id: int,
|
|||
|
||||
ext = filename.split('.')[-1]
|
||||
|
||||
with open(f'attachments/{attachment_id}.{ext}') as attach_file:
|
||||
with open(f'attachments/{attachment_id}.{ext}', 'wb') as attach_file:
|
||||
attach_file.write(attachment_file.stream.read())
|
||||
|
||||
log.debug('written {} bytes for attachment id {}',
|
||||
|
|
|
|||
|
|
@ -645,11 +645,13 @@ class Storage:
|
|||
WHERE message_id = $1
|
||||
""", message_id)
|
||||
|
||||
attachment_ids = [r['id'] for r in attachment_ids]
|
||||
|
||||
res = []
|
||||
|
||||
for attachment_id in attachment_ids:
|
||||
row = await self.db.fetchrow("""
|
||||
SELECT id::text, message_id, channel_id, mime
|
||||
SELECT id::text, message_id, channel_id,
|
||||
filename, filesize, image, height, width
|
||||
FROM attachments
|
||||
WHERE id = $1
|
||||
|
|
@ -659,7 +661,6 @@ class Storage:
|
|||
|
||||
drow.pop('message_id')
|
||||
drow.pop('channel_id')
|
||||
drow.pop('mime')
|
||||
|
||||
drow['size'] = drow['filesize']
|
||||
drow.pop('size')
|
||||
|
|
|
|||
Loading…
Reference in New Issue