Progress.
This commit is contained in:
		
							parent
							
								
									c53b930554
								
							
						
					
					
						commit
						a41da84e3f
					
				@ -181,8 +181,8 @@ class ChatInputComponent extends NjetComponent {
 | 
				
			|||||||
      this.dispatchEvent(new CustomEvent("uploaded", e));
 | 
					      this.dispatchEvent(new CustomEvent("uploaded", e));
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    this.uploadButton.addEventListener("click", (e) => {
 | 
					    this.uploadButton.addEventListener("click", (e) => {
 | 
				
			||||||
    //    e.preventDefault();
 | 
					        e.preventDefault();
 | 
				
			||||||
      //  this.fileUploadGrid.openFileDialog()
 | 
					        this.fileUploadGrid.openFileDialog()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
    this.subscribe("file-uploading", (e) => {
 | 
					    this.subscribe("file-uploading", (e) => {
 | 
				
			||||||
 | 
				
			|||||||
@ -130,6 +130,7 @@ class FileUploadGrid extends NjetComponent {
 | 
				
			|||||||
    startUpload(file, tile, progress) {
 | 
					    startUpload(file, tile, progress) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.publish('file-uploading', {file: file, tile: tile, progress: progress});
 | 
					        this.publish('file-uploading', {file: file, tile: tile, progress: progress});
 | 
				
			||||||
 | 
					        console.info("File uploading",file)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const protocol = location.protocol === "https:" ? "wss://" : "ws://";
 | 
					        const protocol = location.protocol === "https:" ? "wss://" : "ws://";
 | 
				
			||||||
        const ws = new WebSocket(`${protocol}${location.host}/channel/${this.channelUid}/attachment.sock`);
 | 
					        const ws = new WebSocket(`${protocol}${location.host}/channel/${this.channelUid}/attachment.sock`);
 | 
				
			||||||
@ -148,7 +149,7 @@ class FileUploadGrid extends NjetComponent {
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        ws.onmessage = (event) => {
 | 
					        ws.onmessage = (event) => {
 | 
				
			||||||
 | 
					            cconsole.info(event.data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const data = JSON.parse(event.data);
 | 
					            const data = JSON.parse(event.data);
 | 
				
			||||||
            if (data.type === 'progress') {
 | 
					            if (data.type === 'progress') {
 | 
				
			||||||
@ -161,7 +162,7 @@ class FileUploadGrid extends NjetComponent {
 | 
				
			|||||||
                this.publish('file-uploaded', {file: file, tile: tile, progress: progress});
 | 
					                this.publish('file-uploaded', {file: file, tile: tile, progress: progress});
 | 
				
			||||||
                progress.style.width = '100%';
 | 
					                progress.style.width = '100%';
 | 
				
			||||||
                tile.classList.add('fug-done');
 | 
					                tile.classList.add('fug-done');
 | 
				
			||||||
 | 
					                console.info("Closed")
 | 
				
			||||||
                ws.close();
 | 
					                ws.close();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                this.reset()
 | 
					                this.reset()
 | 
				
			||||||
 | 
				
			|||||||
@ -112,9 +112,9 @@ class UploadButtonElement extends HTMLElement {
 | 
				
			|||||||
    this.channelUid = this.getAttribute("channel");
 | 
					    this.channelUid = this.getAttribute("channel");
 | 
				
			||||||
    this.uploadButton = this.container.querySelector(".upload-button");
 | 
					    this.uploadButton = this.container.querySelector(".upload-button");
 | 
				
			||||||
    this.fileInput = this.container.querySelector(".hidden-input");
 | 
					    this.fileInput = this.container.querySelector(".hidden-input");
 | 
				
			||||||
    this.uploadButton.addEventListener("click", () => {
 | 
					    /*this.uploadButton.addEventListener("click", () => {
 | 
				
			||||||
      this.fileInput.click();
 | 
					      this.fileInput.click();
 | 
				
			||||||
    });
 | 
					    });*/
 | 
				
			||||||
    this.fileInput.addEventListener("change", () => {
 | 
					    this.fileInput.addEventListener("change", () => {
 | 
				
			||||||
      this.uploadFiles();
 | 
					      this.uploadFiles();
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
				
			|||||||
@ -192,13 +192,18 @@ class ChannelAttachmentUploadView(BaseView):
 | 
				
			|||||||
            channel_uid=channel_uid, name=filename, user_uid=user_uid
 | 
					            channel_uid=channel_uid, name=filename, user_uid=user_uid
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        pathlib.Path(attachment["path"]).parent.mkdir(parents=True, exist_ok=True)
 | 
					        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:
 | 
					            async for msg in ws:
 | 
				
			||||||
                if msg.type == web.WSMsgType.BINARY:
 | 
					                if msg.type == web.WSMsgType.BINARY:
 | 
				
			||||||
 | 
					                    print("Binary",filename)
 | 
				
			||||||
                    if file is not None:
 | 
					                    if file is not None:
 | 
				
			||||||
                        await file.write(msg.data)
 | 
					                        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:
 | 
					                elif msg.type == web.WSMsgType.TEXT:
 | 
				
			||||||
 | 
					                    print("TExt",filename)
 | 
				
			||||||
 | 
					                    print(msg.json())
 | 
				
			||||||
                    data = msg.json()                   
 | 
					                    data = msg.json()                   
 | 
				
			||||||
                    if data.get('type') == 'end':
 | 
					                    if data.get('type') == 'end':
 | 
				
			||||||
                        await ws.send_json({"type": "done", "filename": filename})
 | 
					                        await ws.send_json({"type": "done", "filename": filename})
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user