@cocreate/file 1.9.7 → 1.9.9
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 +15 -0
- package/package.json +5 -5
- package/src/client.js +7 -26
- package/src/server.js +19 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
## [1.9.9](https://github.com/CoCreate-app/CoCreate-file/compare/v1.9.8...v1.9.9) (2023-10-25)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* bump dependencies ([e785667](https://github.com/CoCreate-app/CoCreate-file/commit/e785667854cbc76da7650ff99fc39eb18387b843))
|
|
7
|
+
|
|
8
|
+
## [1.9.8](https://github.com/CoCreate-app/CoCreate-file/compare/v1.9.7...v1.9.8) (2023-10-22)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* base64 conditions ([55ef6e3](https://github.com/CoCreate-app/CoCreate-file/commit/55ef6e3b29ccc2b5b40669ffa16eb92802b6eb2c))
|
|
14
|
+
* support watch upload of deeply nested files ([db8b460](https://github.com/CoCreate-app/CoCreate-file/commit/db8b4601aa92ed76ff10095d2505cffbda54a8ac))
|
|
15
|
+
|
|
1
16
|
## [1.9.7](https://github.com/CoCreate-app/CoCreate-file/compare/v1.9.6...v1.9.7) (2023-10-19)
|
|
2
17
|
|
|
3
18
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/file",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.9",
|
|
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",
|
|
@@ -59,9 +59,9 @@
|
|
|
59
59
|
"webpack-log": "^3.0.1"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@cocreate/actions": "^1.
|
|
63
|
-
"@cocreate/config": "^1.6.
|
|
64
|
-
"@cocreate/render": "^1.
|
|
65
|
-
"@cocreate/utils": "^1.
|
|
62
|
+
"@cocreate/actions": "^1.12.0",
|
|
63
|
+
"@cocreate/config": "^1.6.5",
|
|
64
|
+
"@cocreate/render": "^1.29.0",
|
|
65
|
+
"@cocreate/utils": "^1.26.1"
|
|
66
66
|
}
|
|
67
67
|
}
|
package/src/client.js
CHANGED
|
@@ -226,57 +226,38 @@ async function getCustomData(file) {
|
|
|
226
226
|
|
|
227
227
|
// This function reads the file and returns its src
|
|
228
228
|
function readFile(file) {
|
|
229
|
-
// Return a new promise that resolves the file object
|
|
230
229
|
return new Promise((resolve) => {
|
|
231
|
-
// Split the file type into an array
|
|
232
230
|
const fileType = file.type.split('/');
|
|
233
231
|
let readAs;
|
|
234
232
|
|
|
235
|
-
// Check if the file type is a directory
|
|
236
233
|
if (fileType[1] === 'directory') {
|
|
237
234
|
return resolve(file)
|
|
238
|
-
}
|
|
239
|
-
// Check if the file type is a image
|
|
240
|
-
else if (['jpg', 'jpeg', 'png', 'gif', 'bmp'].includes(fileType[1])
|
|
235
|
+
} else if (['jpg', 'jpeg', 'png', 'gif', 'bmp'].includes(fileType[1])
|
|
241
236
|
|| fileType[0] === 'image') {
|
|
242
237
|
readAs = 'readAsDataURL';
|
|
243
|
-
}
|
|
244
|
-
// Check if the file type is a video
|
|
245
|
-
else if (['mp4', 'avi', 'mov', 'mpeg', 'flv'].includes(fileType[1])
|
|
238
|
+
} else if (['mp4', 'avi', 'mov', 'mpeg', 'flv'].includes(fileType[1])
|
|
246
239
|
|| fileType[0] === 'video') {
|
|
247
240
|
readAs = 'readAsDataURL';
|
|
248
|
-
}
|
|
249
|
-
// Check if the file type is an audio
|
|
250
|
-
else if (['mp3', 'wav', 'wma', 'aac', 'ogg'].includes(fileType[1])
|
|
241
|
+
} if (['mp3', 'wav', 'wma', 'aac', 'ogg'].includes(fileType[1])
|
|
251
242
|
|| fileType[0] === 'audio') { // updated condition
|
|
252
243
|
readAs = 'readAsDataURL';
|
|
253
|
-
}
|
|
254
|
-
// Check if the file type is a pdf
|
|
255
|
-
else if (fileType[1] === 'pdf') {
|
|
244
|
+
} else if (fileType[1] === 'pdf') {
|
|
256
245
|
readAs = 'readAsDataURL';
|
|
257
|
-
}
|
|
258
|
-
// Check if the file type is a document
|
|
259
|
-
else if (['doc', 'msword', 'docx', 'xlsx', 'pptx'].includes(fileType[1])) {
|
|
246
|
+
} else if (['doc', 'msword', 'docx', 'xlsx', 'pptx'].includes(fileType[1])) {
|
|
260
247
|
readAs = 'readAsBinaryString';
|
|
261
|
-
}
|
|
262
|
-
// Otherwise, assume the file type is text
|
|
263
|
-
else {
|
|
248
|
+
} else {
|
|
264
249
|
readAs = 'readAsText';
|
|
265
250
|
}
|
|
266
251
|
|
|
267
|
-
// Create a FileReader instance to read the file
|
|
268
252
|
const reader = new FileReader();
|
|
269
|
-
// Read the file based on the file type
|
|
270
253
|
reader[readAs](file);
|
|
271
|
-
|
|
254
|
+
|
|
272
255
|
reader.onload = () => {
|
|
273
256
|
file.src = reader.result;
|
|
274
|
-
// If the file type is a document, convert it to base64 encoding
|
|
275
257
|
if (['doc', 'msword', 'docx', 'xlsx', 'pptx'].includes(fileType)) {
|
|
276
258
|
file.src = btoa(file.src);
|
|
277
259
|
}
|
|
278
260
|
|
|
279
|
-
// Resolve the file object
|
|
280
261
|
resolve(file);
|
|
281
262
|
};
|
|
282
263
|
});
|
package/src/server.js
CHANGED
|
@@ -176,20 +176,23 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
|
|
|
176
176
|
}
|
|
177
177
|
if (skip) continue
|
|
178
178
|
|
|
179
|
+
let isDirectory = fs.existsSync(`${entryPath}/${file}`) && fs.lstatSync(`${entryPath}/${file}`).isDirectory();
|
|
180
|
+
let name = file
|
|
181
|
+
let source = ''
|
|
182
|
+
|
|
179
183
|
for (let i = 0; i < match.length; i++) {
|
|
180
184
|
skip = true
|
|
181
185
|
const filePath = path.resolve(entryPath, file);
|
|
182
186
|
if (filePath.startsWith(match[i])) {
|
|
183
187
|
skip = false
|
|
184
188
|
break;
|
|
189
|
+
} else if (isDirectory && match[i].startsWith(filePath)) {
|
|
190
|
+
skip = 'directory'
|
|
191
|
+
break;
|
|
185
192
|
}
|
|
186
193
|
}
|
|
187
194
|
|
|
188
|
-
if (skip) continue
|
|
189
|
-
|
|
190
|
-
let isDirectory = fs.existsSync(`${entryPath}/${file}`) && fs.lstatSync(`${entryPath}/${file}`).isDirectory();
|
|
191
|
-
let name = file
|
|
192
|
-
let source = ''
|
|
195
|
+
if (skip === true) continue
|
|
193
196
|
|
|
194
197
|
const fileExtension = path.extname(file);
|
|
195
198
|
let mimeType = mimeTypes[fileExtension]
|
|
@@ -267,16 +270,19 @@ module.exports = async function file(CoCreateConfig, configPath, match) {
|
|
|
267
270
|
}
|
|
268
271
|
}
|
|
269
272
|
|
|
270
|
-
if (!newObject.object._id)
|
|
271
|
-
newObject.$filter = {
|
|
272
|
-
query: [{ key: 'pathname', value: pathname, operator: '$eq' }]
|
|
273
|
-
}
|
|
274
273
|
|
|
275
|
-
|
|
276
|
-
|
|
274
|
+
if (skip !== 'directory') {
|
|
275
|
+
if (!newObject.object._id)
|
|
276
|
+
newObject.$filter = {
|
|
277
|
+
query: [{ key: 'pathname', value: pathname, operator: '$eq' }]
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
response = await runStore(newObject);
|
|
281
|
+
console.log(`Uploaded: ${entryPath}/${file}`, `To: ${pathname}`)
|
|
277
282
|
|
|
278
|
-
|
|
279
|
-
|
|
283
|
+
if (response.error)
|
|
284
|
+
errorLog.push(response.error)
|
|
285
|
+
}
|
|
280
286
|
|
|
281
287
|
if (isDirectory && pathname) {
|
|
282
288
|
let newEntry
|