Skip to content

Commit

Permalink
Fix console drag-and-drop uploads (#1946)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshk authored Mar 6, 2025
1 parent c4d0801 commit 34a985c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 50 deletions.
54 changes: 28 additions & 26 deletions assets/js/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,40 +251,42 @@ dropzone.addEventListener(
e => {
e.preventDefault()
e.stopPropagation()
e.dataTransfer.items.forEach(item => {
const file = item.getAsFile()
const reader = file.stream().getReader()
if (e.dataTransfer.items) {
for (const item of e.dataTransfer.items) {
const file = item.getAsFile()
const reader = file.stream().getReader()

channel.push("file-data/start", { filename: file.name })
channel.push("message", { event: `starting to upload ${file.name}` })
channel.push("file-data/start", { filename: file.name })
channel.push("message", { event: `starting to upload ${file.name}` })

reader.read().then(function process({ done, value }) {
if (done) {
channel.push("file-data/stop", { filename: file.name })
channel.push("message", { event: `uploaded ${file.name}` })
return
}
reader.read().then(function process({ done, value }) {
if (done) {
channel.push("file-data/stop", { filename: file.name })
channel.push("message", { event: `uploaded ${file.name}` })
return
}

const chunkSize = 1024
let chunkNum = 0
const chunkSize = 1024
let chunkNum = 0

for (let i = 0; i < value.length; i += chunkSize) {
const chunk = value.slice(i, i + chunkSize)
for (let i = 0; i < value.length; i += chunkSize) {
const chunk = value.slice(i, i + chunkSize)

const encoded = btoa(String.fromCharCode.apply(null, chunk))
const encoded = btoa(String.fromCharCode.apply(null, chunk))

channel.push("file-data", {
filename: file.name,
chunk: chunkNum,
data: encoded
})
channel.push("file-data", {
filename: file.name,
chunk: chunkNum,
data: encoded
})

chunkNum += 1
}
chunkNum += 1
}

return reader.read().then(process)
})
})
return reader.read().then(process)
})
}
}
},
false
)
50 changes: 26 additions & 24 deletions assets/ui-rework/hooks/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,38 +194,40 @@ export default {
e => {
e.preventDefault()
e.stopPropagation()
e.dataTransfer.items.forEach(item => {
const file = item.getAsFile()
const reader = file.stream().getReader()
if (e.dataTransfer.items) {
for (const item of e.dataTransfer.items) {
const file = item.getAsFile()
const reader = file.stream().getReader()

channel.push("file-data/start", { filename: file.name })
channel.push("file-data/start", { filename: file.name })

reader.read().then(function process({ done, value }) {
if (done) {
channel.push("file-data/stop", { filename: file.name })
return
}
reader.read().then(function process({ done, value }) {
if (done) {
channel.push("file-data/stop", { filename: file.name })
return
}

const chunkSize = 1024
let chunkNum = 0
const chunkSize = 1024
let chunkNum = 0

for (let i = 0; i < value.length; i += chunkSize) {
const chunk = value.slice(i, i + chunkSize)
for (let i = 0; i < value.length; i += chunkSize) {
const chunk = value.slice(i, i + chunkSize)

const encoded = btoa(String.fromCharCode.apply(null, chunk))
const encoded = btoa(String.fromCharCode.apply(null, chunk))

channel.push("file-data", {
filename: file.name,
chunk: chunkNum,
data: encoded
})
channel.push("file-data", {
filename: file.name,
chunk: chunkNum,
data: encoded
})

chunkNum += 1
}
chunkNum += 1
}

return reader.read().then(process)
})
})
return reader.read().then(process)
})
}
}
},
false
)
Expand Down

0 comments on commit 34a985c

Please sign in to comment.