Skip to content

Commit 99f48a7

Browse files
committed
feat: Refactor Import function to import files into the system.
The Import function has been updated to include parsing of JSON data and the createDocument function. This allows for the importing of files into the system.
1 parent c965cae commit 99f48a7

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/client.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ async function fileFormAction(btn, params, action) {
307307
// Export(inputs[i])
308308
}
309309
else if (action === 'import') {
310-
// Import(inputs[i])
310+
Import(inputs[i])
311311
} else {
312312
}
313313
}
@@ -432,6 +432,23 @@ async function upload(input) {
432432
return response
433433
}
434434

435+
async function Import(input) {
436+
let files = await getFiles(input)
437+
const data = files.reduce((result, { src }) => {
438+
try {
439+
const parsedSrc = JSON.parse(src);
440+
result.push(parsedSrc);
441+
} catch (error) {
442+
console.error(`Error parsing JSON: ${error}`);
443+
}
444+
return result;
445+
}, []);
446+
447+
let response = await crud.createDocument(data);
448+
449+
return response
450+
}
451+
435452
async function create(directory, type, name, src = "") {
436453
try {
437454
if (directory.handle && directory.input) {
@@ -530,6 +547,14 @@ action.init({
530547
}
531548
})
532549

550+
action.init({
551+
name: "import",
552+
endEvent: "imported",
553+
callback: (btn, params) => {
554+
fileFormAction(btn, params, "saveLocally")
555+
}
556+
})
557+
533558
action.init({
534559
name: "createFile",
535560
callback: (btn, params) => {

0 commit comments

Comments
 (0)