diff --git a/litecord/blueprints/attachments.py b/litecord/blueprints/attachments.py
new file mode 100644
index 0000000..408843d
--- /dev/null
+++ b/litecord/blueprints/attachments.py
@@ -0,0 +1,29 @@
+"""
+
+Litecord
+Copyright (C) 2018 Luna Mendes
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, version 3 of the License.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see .
+
+"""
+
+from quart import Blueprint
+
+bp = Blueprint(__name__)
+
+@bp.route('///.',
+ 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
diff --git a/litecord/blueprints/channel/messages.py b/litecord/blueprints/channel/messages.py
index b089e5c..b3f9eee 100644
--- a/litecord/blueprints/channel/messages.py
+++ b/litecord/blueprints/channel/messages.py
@@ -388,6 +388,8 @@ async def _add_attachment(message_id: int, attachment_file) -> int:
attachment_id, attachment_file.filename, file_size,
is_image, img_width, img_height)
+ # TODO: save a file
+
# add the newly created attachment to the message
await app.db.execute("""
INSERT INTO message_attachments (message_id, attachment_id)
diff --git a/litecord/storage.py b/litecord/storage.py
index 6b99dd3..04fe411 100644
--- a/litecord/storage.py
+++ b/litecord/storage.py
@@ -31,6 +31,7 @@ from litecord.blueprints.user.billing import PLAN_ID_TO_TYPE
from litecord.types import timestamp_
from litecord.utils import pg_set_json
+from litecord.embed.sanitizer import proxify
log = Logger(__name__)
@@ -636,6 +637,34 @@ class Storage:
# they were defined in the first loop.
return list(map(react_stats.get, emoji))
+ async def get_attachments(self, message_id: int) -> List[Dict[str, Any]]:
+ """Get a list of attachment objects tied to the message."""
+ attachment_ids = await self.db.fetch("""
+ SELECT attachment_id
+ FROM message_attachments
+ WHERE message_id = $1
+ """, message_id)
+
+ res = []
+
+ for attachment_id in attachment_ids:
+ row = await self.db.fetchrow("""
+ SELECT id::text, filename, filesize, image, height, width
+ FROM attachments
+ WHERE id = $1
+ """, attachment_id)
+
+ drow = dict(row)
+
+ drow['size'] = drow['filesize']
+ drow.pop('size')
+
+ # TODO: url, proxy_url
+
+ res.append(drow)
+
+ return res
+
async def get_message(self, message_id: int, user_id=None) -> Dict:
"""Get a single message's payload."""
row = await self.fetchrow_with_json("""
@@ -703,7 +732,7 @@ class Storage:
res.pop('author_id')
# TODO: res['attachments']
- res['attachments'] = []
+ res['attachments'] = await self.get_attachments(message_id)
# TODO: res['member'] for partial member data
# of the author