@cocreate/file 1.15.0 → 1.15.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [1.15.2](https://github.com/CoCreate-app/CoCreate-file/compare/v1.15.1...v1.15.2) (2024-02-14)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * realtime defaults to false ([c6fb16c](https://github.com/CoCreate-app/CoCreate-file/commit/c6fb16c6f634c9a0eac244884913941963e5807b))
7
+
8
+ ## [1.15.1](https://github.com/CoCreate-app/CoCreate-file/compare/v1.15.0...v1.15.1) (2024-02-13)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * add file.size and add missing object param ([32f8508](https://github.com/CoCreate-app/CoCreate-file/commit/32f85080079dcb91fee2bb294b72d16d769b3440))
14
+
1
15
  # [1.15.0](https://github.com/CoCreate-app/CoCreate-file/compare/v1.14.2...v1.15.0) (2024-02-05)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/file",
3
- "version": "1.15.0",
3
+ "version": "1.15.2",
4
4
  "description": "A headless file uploader that uses HTML5 attributes for customization. Allows easy upload of files to server.",
5
5
  "keywords": [
6
6
  "file",
package/src/client.js CHANGED
@@ -151,6 +151,9 @@ async function fileEvent(event) {
151
151
  if (!files[i].src)
152
152
  await readFile(files[i])
153
153
 
154
+ if (!files[i].size)
155
+ files[i].size = handle.size
156
+
154
157
  files[i].directory = handle.directory || '/'
155
158
  files[i].path = handle.path || '/'
156
159
  files[i].pathname = handle.pathname || '/' + handle.name
@@ -174,8 +177,10 @@ async function fileEvent(event) {
174
177
 
175
178
  const isImport = input.getAttribute('import')
176
179
  const isRealtime = input.getAttribute('realtime')
177
- if (isRealtime !== 'false' && (isImport || isImport == "")) {
178
- Import(input)
180
+ if (isRealtime && isRealtime !== 'false') {
181
+ if (isImport || isImport == "") {
182
+ Import(input)
183
+ }
179
184
  }
180
185
  }
181
186
  } catch (error) {
@@ -232,9 +237,11 @@ async function getFiles(fileInputs) {
232
237
  for (let file of Array.from(selected.values())) {
233
238
  if (!file.src)
234
239
  await readFile(file)
240
+ let fileObject = { ...file }
241
+ fileObject.size = file.size
242
+ await getCustomData(fileObject)
235
243
 
236
- file = await getCustomData({ ...file })
237
- files.push(file)
244
+ files.push(fileObject)
238
245
  }
239
246
  }
240
247
  }
@@ -267,14 +274,11 @@ function readFile(file) {
267
274
 
268
275
  if (fileType[1] === 'directory') {
269
276
  return resolve(file)
270
- } else if (['jpg', 'jpeg', 'png', 'gif', 'bmp'].includes(fileType[1])
271
- || fileType[0] === 'image') {
277
+ } else if (fileType[0] === 'image') {
272
278
  readAs = 'readAsDataURL';
273
- } else if (['mp4', 'avi', 'mov', 'mpeg', 'flv'].includes(fileType[1])
274
- || fileType[0] === 'video') {
279
+ } else if (fileType[0] === 'video') {
275
280
  readAs = 'readAsDataURL';
276
- } else if (['mp3', 'wav', 'wma', 'aac', 'ogg'].includes(fileType[1])
277
- || fileType[0] === 'audio') { // updated condition
281
+ } else if (fileType[0] === 'audio') {
278
282
  readAs = 'readAsDataURL';
279
283
  } else if (fileType[1] === 'pdf') {
280
284
  readAs = 'readAsDataURL';
@@ -429,13 +433,11 @@ async function upload(element, data) {
429
433
  if (Data.type === 'key')
430
434
  Data.type = 'object'
431
435
 
432
- if (Data.type === 'object') {
433
- let object = input.getAttribute('object')
434
- if (key) {
435
- Data[Data.type] = { _id: object, [key]: files }
436
- } else {
437
- Data[Data.type] = files
438
- }
436
+ let object = input.getAttribute('object')
437
+ if (key) {
438
+ Data[Data.type] = { _id: object, [key]: files }
439
+ } else {
440
+ Data[Data.type] = files
439
441
  }
440
442
 
441
443
  Data.method = Data.type + '.update'