Merge pull request 'Fix file upload' (#59) from BordedDev/snek:bugfix/file-upload into main
Reviewed-on: retoor/snek#59
This commit is contained in:
commit
05192a00cd
@ -179,27 +179,25 @@ class ChatInputComponent extends NjetComponent {
|
||||
e.preventDefault();
|
||||
this.fileUploadGrid.openFileDialog();
|
||||
});
|
||||
eventBus.subscribe("file-uploading", (e) => {
|
||||
this.subscribe("file-uploading", (e) => {
|
||||
this.fileUploadGrid.style.display = "block";
|
||||
this.uploadButton.style.display = "none";
|
||||
this.textarea.style.display = "none";
|
||||
})
|
||||
document.eventBus = eventBus;
|
||||
this.appendChild(this.uploadButton);
|
||||
|
||||
this.textarea.addEventListener("blur", () => {
|
||||
this.updateFromInput("");
|
||||
});
|
||||
|
||||
eventBus.subscribe("file-uploads-done", (data)=>{
|
||||
console.info("JEEJ", data)
|
||||
this.textarea.style.display = "block";
|
||||
this.subscribe("file-uploads-done", (data)=>{
|
||||
this.textarea.style.display = "block";
|
||||
this.uploadButton.style.display = "block";
|
||||
this.fileUploadGrid.style.display = "none";
|
||||
let message =data.reduce((file) => {
|
||||
return `${message}[${file.filename}](/channel/attachment/${file.file})`;
|
||||
let msg =data.reduce((message, 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) => {
|
||||
console.info(event.data)
|
||||
|
||||
const data = JSON.parse(event.data);
|
||||
if (data.type === 'progress') {
|
||||
const pct = Math.min(100, Math.round(100 * data.bytes / file.size));
|
||||
progress.style.width = pct + '%';
|
||||
this.publish('file-uploading', {file: file, tile: tile, progress: progress});
|
||||
} else if (data.type === 'done') {
|
||||
console.info("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH")
|
||||
console.info("Done")
|
||||
console.info(this.uploadResponses)
|
||||
this.uploadsDone += 1;
|
||||
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.uploadResponses.push({file:file, remoteFile:data.file})
|
||||
console.info(this.uploadsDone, this.uploadsStarted)
|
||||
if(this.uploadsDone == this.uploadsStarted){
|
||||
this.publish('file-uploads-done', this.uploadResponses);
|
||||
}
|
||||
|
@ -206,7 +206,7 @@ class ChannelAttachmentUploadView(BaseView):
|
||||
print(msg.json())
|
||||
data = msg.json()
|
||||
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})
|
||||
elif msg.type == web.WSMsgType.ERROR:
|
||||
break
|
||||
|
Loading…
Reference in New Issue
Block a user