@cocreate/file 1.9.6 → 1.9.8
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 +1 -1
- package/src/client.js +7 -30
- package/src/server.js +19 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
## [1.9.8](https://github.com/CoCreate-app/CoCreate-file/compare/v1.9.7...v1.9.8) (2023-10-22)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* base64 conditions ([55ef6e3](https://github.com/CoCreate-app/CoCreate-file/commit/55ef6e3b29ccc2b5b40669ffa16eb92802b6eb2c))
|
|
7
|
+
* support watch upload of deeply nested files ([db8b460](https://github.com/CoCreate-app/CoCreate-file/commit/db8b4601aa92ed76ff10095d2505cffbda54a8ac))
|
|
8
|
+
|
|
9
|
+
## [1.9.7](https://github.com/CoCreate-app/CoCreate-file/compare/v1.9.6...v1.9.7) (2023-10-19)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* declartion of render functions using object spread ([acb3fc5](https://github.com/CoCreate-app/CoCreate-file/commit/acb3fc5a549ff0a4d17bb5c8c7850f2aad4c58c8))
|
|
15
|
+
|
|
1
16
|
## [1.9.6](https://github.com/CoCreate-app/CoCreate-file/compare/v1.9.5...v1.9.6) (2023-10-17)
|
|
2
17
|
|
|
3
18
|
|
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -136,10 +136,6 @@ async function fileEvent(event) {
|
|
|
136
136
|
|
|
137
137
|
if (!input.renderValue)
|
|
138
138
|
input.renderValue(selected.values())
|
|
139
|
-
// render.render({
|
|
140
|
-
// source: input,
|
|
141
|
-
// data
|
|
142
|
-
// });
|
|
143
139
|
|
|
144
140
|
const isImport = input.getAttribute('import')
|
|
145
141
|
const isRealtime = input.getAttribute('realtime')
|
|
@@ -230,57 +226,38 @@ async function getCustomData(file) {
|
|
|
230
226
|
|
|
231
227
|
// This function reads the file and returns its src
|
|
232
228
|
function readFile(file) {
|
|
233
|
-
// Return a new promise that resolves the file object
|
|
234
229
|
return new Promise((resolve) => {
|
|
235
|
-
// Split the file type into an array
|
|
236
230
|
const fileType = file.type.split('/');
|
|
237
231
|
let readAs;
|
|
238
232
|
|
|
239
|
-
// Check if the file type is a directory
|
|
240
233
|
if (fileType[1] === 'directory') {
|
|
241
234
|
return resolve(file)
|
|
242
|
-
}
|
|
243
|
-
// Check if the file type is a image
|
|
244
|
-
else if (['jpg', 'jpeg', 'png', 'gif', 'bmp'].includes(fileType[1])
|
|
235
|
+
} else if (['jpg', 'jpeg', 'png', 'gif', 'bmp'].includes(fileType[1])
|
|
245
236
|
|| fileType[0] === 'image') {
|
|
246
237
|
readAs = 'readAsDataURL';
|
|
247
|
-
}
|
|
248
|
-
// Check if the file type is a video
|
|
249
|
-
else if (['mp4', 'avi', 'mov', 'mpeg', 'flv'].includes(fileType[1])
|
|
238
|
+
} else if (['mp4', 'avi', 'mov', 'mpeg', 'flv'].includes(fileType[1])
|
|
250
239
|
|| fileType[0] === 'video') {
|
|
251
240
|
readAs = 'readAsDataURL';
|
|
252
|
-
}
|
|
253
|
-
// Check if the file type is an audio
|
|
254
|
-
else if (['mp3', 'wav', 'wma', 'aac', 'ogg'].includes(fileType[1])
|
|
241
|
+
} if (['mp3', 'wav', 'wma', 'aac', 'ogg'].includes(fileType[1])
|
|
255
242
|
|| fileType[0] === 'audio') { // updated condition
|
|
256
243
|
readAs = 'readAsDataURL';
|
|
257
|
-
}
|
|
258
|
-
// Check if the file type is a pdf
|
|
259
|
-
else if (fileType[1] === 'pdf') {
|
|
244
|
+
} else if (fileType[1] === 'pdf') {
|
|
260
245
|
readAs = 'readAsDataURL';
|
|
261
|
-
}
|
|
262
|
-
// Check if the file type is a document
|
|
263
|
-
else if (['doc', 'msword', 'docx', 'xlsx', 'pptx'].includes(fileType[1])) {
|
|
246
|
+
} else if (['doc', 'msword', 'docx', 'xlsx', 'pptx'].includes(fileType[1])) {
|
|
264
247
|
readAs = 'readAsBinaryString';
|
|
265
|
-
}
|
|
266
|
-
// Otherwise, assume the file type is text
|
|
267
|
-
else {
|
|
248
|
+
} else {
|
|
268
249
|
readAs = 'readAsText';
|
|
269
250
|
}
|
|
270
251
|
|
|
271
|
-
// Create a FileReader instance to read the file
|
|
272
252
|
const reader = new FileReader();
|
|
273
|
-
// Read the file based on the file type
|
|
274
253
|
reader[readAs](file);
|
|
275
|
-
|
|
254
|
+
|
|
276
255
|
reader.onload = () => {
|
|
277
256
|
file.src = reader.result;
|
|
278
|
-
// If the file type is a document, convert it to base64 encoding
|
|
279
257
|
if (['doc', 'msword', 'docx', 'xlsx', 'pptx'].includes(fileType)) {
|
|
280
258
|
file.src = btoa(file.src);
|
|
281
259
|
}
|
|
282
260
|
|
|
283
|
-
// Resolve the file object
|
|
284
261
|
resolve(file);
|
|
285
262
|
};
|
|
286
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
|