Skip to content

Commit

Permalink
fix: add file.size and add missing object param
Browse files Browse the repository at this point in the history
  • Loading branch information
frankpagan committed Feb 11, 2024
1 parent e5c9ab6 commit 32f8508
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ async function fileEvent(event) {
if (!files[i].src)
await readFile(files[i])

if (!files[i].size)
files[i].size = handle.size

files[i].directory = handle.directory || '/'
files[i].path = handle.path || '/'
files[i].pathname = handle.pathname || '/' + handle.name
Expand Down Expand Up @@ -232,9 +235,11 @@ async function getFiles(fileInputs) {
for (let file of Array.from(selected.values())) {
if (!file.src)
await readFile(file)
let fileObject = { ...file }
fileObject.size = file.size
await getCustomData(fileObject)

file = await getCustomData({ ...file })
files.push(file)
files.push(fileObject)
}
}
}
Expand Down Expand Up @@ -267,14 +272,11 @@ function readFile(file) {

if (fileType[1] === 'directory') {
return resolve(file)
} else if (['jpg', 'jpeg', 'png', 'gif', 'bmp'].includes(fileType[1])
|| fileType[0] === 'image') {
} else if (fileType[0] === 'image') {
readAs = 'readAsDataURL';
} else if (['mp4', 'avi', 'mov', 'mpeg', 'flv'].includes(fileType[1])
|| fileType[0] === 'video') {
} else if (fileType[0] === 'video') {
readAs = 'readAsDataURL';
} else if (['mp3', 'wav', 'wma', 'aac', 'ogg'].includes(fileType[1])
|| fileType[0] === 'audio') { // updated condition
} else if (fileType[0] === 'audio') {
readAs = 'readAsDataURL';
} else if (fileType[1] === 'pdf') {
readAs = 'readAsDataURL';
Expand Down Expand Up @@ -429,13 +431,11 @@ async function upload(element, data) {
if (Data.type === 'key')
Data.type = 'object'

if (Data.type === 'object') {
let object = input.getAttribute('object')
if (key) {
Data[Data.type] = { _id: object, [key]: files }
} else {
Data[Data.type] = files
}
let object = input.getAttribute('object')
if (key) {
Data[Data.type] = { _id: object, [key]: files }
} else {
Data[Data.type] = files
}

Data.method = Data.type + '.update'
Expand Down

0 comments on commit 32f8508

Please sign in to comment.