Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix console drag-and-drop uploads #1946

Merged
merged 1 commit into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any ideas on what caused this to break?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I could tell, its that e.dataTransfer.items.forEach is the culprit. I don't think forEach is a method on items.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, makes sense! Thanks.

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
Loading