Progress.
This commit is contained in:
parent
c53b930554
commit
a41da84e3f
src/snek
@ -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) => {
|
||||
|
@ -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()
|
||||
|
@ -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();
|
||||
});
|
||||
|
@ -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})
|
||||
|
Loading…
Reference in New Issue
Block a user