diff --git a/src/snek/static/chat-input.js b/src/snek/static/chat-input.js index 0800f61..90f3979 100644 --- a/src/snek/static/chat-input.js +++ b/src/snek/static/chat-input.js @@ -181,8 +181,8 @@ class ChatInputComponent extends NjetComponent { this.dispatchEvent(new CustomEvent("uploaded", e)); }); this.uploadButton.addEventListener("click", (e) => { - // e.preventDefault(); - // this.fileUploadGrid.openFileDialog() + e.preventDefault(); + this.fileUploadGrid.openFileDialog() }) this.subscribe("file-uploading", (e) => { diff --git a/src/snek/static/file-upload-grid.js b/src/snek/static/file-upload-grid.js index 3aae7ba..0a623f6 100644 --- a/src/snek/static/file-upload-grid.js +++ b/src/snek/static/file-upload-grid.js @@ -130,7 +130,8 @@ class FileUploadGrid extends NjetComponent { startUpload(file, tile, progress) { this.publish('file-uploading', {file: file, tile: tile, progress: progress}); - + console.info("File uploading",file) + const protocol = location.protocol === "https:" ? "wss://" : "ws://"; const ws = new WebSocket(`${protocol}${location.host}/channel/${this.channelUid}/attachment.sock`); ws.binaryType = 'arraybuffer'; @@ -148,7 +149,7 @@ class FileUploadGrid extends NjetComponent { }; ws.onmessage = (event) => { - + cconsole.info(event.data) const data = JSON.parse(event.data); if (data.type === 'progress') { @@ -161,7 +162,7 @@ class FileUploadGrid extends NjetComponent { this.publish('file-uploaded', {file: file, tile: tile, progress: progress}); progress.style.width = '100%'; tile.classList.add('fug-done'); - + console.info("Closed") ws.close(); this.reset() diff --git a/src/snek/static/upload-button.js b/src/snek/static/upload-button.js index 243fc8b..a789c96 100644 --- a/src/snek/static/upload-button.js +++ b/src/snek/static/upload-button.js @@ -112,9 +112,9 @@ class UploadButtonElement extends HTMLElement { this.channelUid = this.getAttribute("channel"); this.uploadButton = this.container.querySelector(".upload-button"); this.fileInput = this.container.querySelector(".hidden-input"); - this.uploadButton.addEventListener("click", () => { + /*this.uploadButton.addEventListener("click", () => { this.fileInput.click(); - }); + });*/ this.fileInput.addEventListener("change", () => { this.uploadFiles(); }); diff --git a/src/snek/view/channel.py b/src/snek/view/channel.py index 0ed975d..604725a 100644 --- a/src/snek/view/channel.py +++ b/src/snek/view/channel.py @@ -192,13 +192,18 @@ class ChannelAttachmentUploadView(BaseView): channel_uid=channel_uid, name=filename, user_uid=user_uid ) pathlib.Path(attachment["path"]).parent.mkdir(parents=True, exist_ok=True) - async with aiofiles.open(attachment["path"], "wb") as f: + + async with aiofiles.open(attachment["path"], "wb") as file: + print("File openend.", filename) async for msg in ws: if msg.type == web.WSMsgType.BINARY: + print("Binary",filename) if file is not None: await file.write(msg.data) - await ws.send_json({"type": "progress", "filename": filename, "bytes": file.tell()}) + await ws.send_json({"type": "progress", "filename": filename, "bytes": await file.tell()}) elif msg.type == web.WSMsgType.TEXT: + print("TExt",filename) + print(msg.json()) data = msg.json() if data.get('type') == 'end': await ws.send_json({"type": "done", "filename": filename})