diff options
author | WlodekM <[email protected]> | 2024-11-30 21:55:35 +0200 |
---|---|---|
committer | WlodekM <[email protected]> | 2024-11-30 21:55:35 +0200 |
commit | 404533f4a056bd56be73bdb76786ca1a8895c977 (patch) | |
tree | 54661701085333647b7ddd79f4c08f00b88ba414 /pages/main/page.js | |
parent | 1f53a4594a148acc6bd9292b91ff2877635e739b (diff) |
mlknjniy
Diffstat (limited to 'pages/main/page.js')
-rw-r--r-- | pages/main/page.js | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/pages/main/page.js b/pages/main/page.js index 090e314..d3357cb 100644 --- a/pages/main/page.js +++ b/pages/main/page.js @@ -62,7 +62,13 @@ export function onload() { if(scrolledToBottom) scrollToBottomOfElement(msgArea.parentElement); } - function createMessage(msg) { + async function createMessage(msg) { + let types = []; + for (const attachment of msg.attachments) { + console.debug(attachment) + const resp = await fetch(attachment.toString()); + types.push(resp.headers.get('content-type')) + } let elem = html('div') .class('message') .child('div') @@ -97,9 +103,21 @@ export function onload() { .class('post-content') .html(md.render(msg?.content)) .child('div') - .for(msg.attachments, a => { - return html('img').class('attachment').attr('src', a)} - ) + .for(msg.attachments, (a, i) => { + if(types[i].startsWith('image')) { + return html('img').class('attachment').attr('src', a) + } else if (types[i].startsWith('video')) { + return html('video') + .class('attachment') + .attr('controls', 1) + .child('source') + .attr('src', a) + .attr('type', types[i]) + .up() + } else { + return html('a').attr('href', a).text(`Attachment ${i + 1} (${a})`) + } + }) .up() .up() .up() |