Fix file upload
This commit is contained in:
		
							parent
							
								
									23055919cd
								
							
						
					
					
						commit
						0de95e3824
					
				@ -179,27 +179,25 @@ class ChatInputComponent extends NjetComponent {
 | 
				
			|||||||
      e.preventDefault();
 | 
					      e.preventDefault();
 | 
				
			||||||
      this.fileUploadGrid.openFileDialog();
 | 
					      this.fileUploadGrid.openFileDialog();
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    eventBus.subscribe("file-uploading", (e) => {
 | 
					    this.subscribe("file-uploading", (e) => {
 | 
				
			||||||
      this.fileUploadGrid.style.display = "block";
 | 
					      this.fileUploadGrid.style.display = "block";
 | 
				
			||||||
      this.uploadButton.style.display = "none";
 | 
					      this.uploadButton.style.display = "none";
 | 
				
			||||||
      this.textarea.style.display = "none";
 | 
					      this.textarea.style.display = "none";
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
    document.eventBus = eventBus;
 | 
					 | 
				
			||||||
    this.appendChild(this.uploadButton);
 | 
					    this.appendChild(this.uploadButton);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.textarea.addEventListener("blur", () => {
 | 
					    this.textarea.addEventListener("blur", () => {
 | 
				
			||||||
      this.updateFromInput("");
 | 
					      this.updateFromInput("");
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    eventBus.subscribe("file-uploads-done", (data)=>{
 | 
					    this.subscribe("file-uploads-done", (data)=>{
 | 
				
			||||||
        console.info("JEEJ", data)
 | 
					 | 
				
			||||||
      this.textarea.style.display = "block";
 | 
					      this.textarea.style.display = "block";
 | 
				
			||||||
      this.uploadButton.style.display = "block";
 | 
					      this.uploadButton.style.display = "block";
 | 
				
			||||||
      this.fileUploadGrid.style.display = "none";
 | 
					      this.fileUploadGrid.style.display = "none";
 | 
				
			||||||
      let message =data.reduce((file) => {
 | 
					      let msg =data.reduce((message, file) => {
 | 
				
			||||||
        return `${message}[${file.filename}](/channel/attachment/${file.file})`;
 | 
					        return `${message}[${file.filename || file.name || file.remoteFile}](/channel/attachment/${file.remoteFile})`;
 | 
				
			||||||
      }, '');
 | 
					      }, '');
 | 
				
			||||||
      app.rpc.sendMessage(this.channelUid, message, true);
 | 
					      app.rpc.sendMessage(this.channelUid, msg, true);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
				
			|||||||
@ -151,25 +151,18 @@ class FileUploadGrid extends NjetComponent {
 | 
				
			|||||||
        };
 | 
					        };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        ws.onmessage = (event) => {
 | 
					        ws.onmessage = (event) => {
 | 
				
			||||||
            console.info(event.data)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            const data = JSON.parse(event.data);
 | 
					            const data = JSON.parse(event.data);
 | 
				
			||||||
            if (data.type === 'progress') {
 | 
					            if (data.type === 'progress') {
 | 
				
			||||||
                const pct = Math.min(100, Math.round(100 * data.bytes / file.size));
 | 
					                const pct = Math.min(100, Math.round(100 * data.bytes / file.size));
 | 
				
			||||||
                progress.style.width = pct + '%';
 | 
					                progress.style.width = pct + '%';
 | 
				
			||||||
                this.publish('file-uploading', {file: file, tile: tile, progress: progress});
 | 
					                this.publish('file-uploading', {file: file, tile: tile, progress: progress});
 | 
				
			||||||
            } else if (data.type === 'done') {
 | 
					            } else if (data.type === 'done') {
 | 
				
			||||||
                console.info("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH")
 | 
					 | 
				
			||||||
                console.info("Done")
 | 
					 | 
				
			||||||
                console.info(this.uploadResponses)
 | 
					 | 
				
			||||||
                this.uploadsDone += 1;
 | 
					                this.uploadsDone += 1;
 | 
				
			||||||
                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.uploadResponses.push({file:file, remoteFile:data.file})
 | 
					                this.uploadResponses.push({file:file, remoteFile:data.file})
 | 
				
			||||||
                console.info(this.uploadsDone, this.uploadsStarted)
 | 
					 | 
				
			||||||
                if(this.uploadsDone == this.uploadsStarted){
 | 
					                if(this.uploadsDone == this.uploadsStarted){
 | 
				
			||||||
                    this.publish('file-uploads-done', this.uploadResponses);
 | 
					                    this.publish('file-uploads-done', this.uploadResponses);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 | 
				
			|||||||
@ -206,7 +206,7 @@ class ChannelAttachmentUploadView(BaseView):
 | 
				
			|||||||
                    print(msg.json())
 | 
					                    print(msg.json())
 | 
				
			||||||
                    data = msg.json()                   
 | 
					                    data = msg.json()                   
 | 
				
			||||||
                    if data.get('type') == 'end':
 | 
					                    if data.get('type') == 'end':
 | 
				
			||||||
                        relative_url = urllib.parse.quote(attachment_record["relative_url"])
 | 
					                        relative_url = urllib.parse.quote(attachment["relative_url"])
 | 
				
			||||||
                        await ws.send_json({"type": "done", "file": relative_url, "filename": filename})
 | 
					                        await ws.send_json({"type": "done", "file": relative_url, "filename": filename})
 | 
				
			||||||
                elif msg.type == web.WSMsgType.ERROR:
 | 
					                elif msg.type == web.WSMsgType.ERROR:
 | 
				
			||||||
                    break
 | 
					                    break
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user