diff --git a/litecord/blueprints/attachments.py b/litecord/blueprints/attachments.py index 220b9b1..be05980 100644 --- a/litecord/blueprints/attachments.py +++ b/litecord/blueprints/attachments.py @@ -17,14 +17,26 @@ along with this program. If not, see . """ -from quart import Blueprint +from quart import Blueprint, send_file, current_app as app bp = Blueprint('attachments', __name__) @bp.route('/attachments' - '///.', + '///', methods=['GET']) async def _get_attachment(channel_id: int, message_id: int, - filename: str, ext: str): - # TODO: get the attachment id with given metadata - return '', 204 + filename: str): + attach_id = await app.db.fetchval(""" + SELECT id + FROM attachments + WHERE channel_id = $1 + AND message_id = $2 + AND filename = $3 + """, channel_id, message_id, filename) + + if attach_id is None: + return '', 404 + + ext = filename.split('.')[-1] + + return await send_file(f'./attachments/{attach_id}.{ext}') diff --git a/litecord/blueprints/channel/messages.py b/litecord/blueprints/channel/messages.py index ccdc90a..90da95e 100644 --- a/litecord/blueprints/channel/messages.py +++ b/litecord/blueprints/channel/messages.py @@ -389,7 +389,7 @@ async def _add_attachment(message_id: int, channel_id: int, INSERT INTO attachments (id, channel_id, message_id, filename, filesize, - image, height, width) + image, width, height) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) """,