Skip to content

Commit d593476

Browse files
committed
feat: Refactor file form actions and add new 'download' action
This change refactors the logic for file form actions in client.js to manage uploads, local saves, and downloading. It also adds a new action, download, now part of the file form actions. Additional actions such as creating/deleting directories and files remain now as part of a general file rendering action.
1 parent edeef71 commit d593476

File tree

1 file changed

+6
-47
lines changed

1 file changed

+6
-47
lines changed

src/client.js

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ async function fileFormAction(data) {
266266
for (let i = 0; i < inputs.length; i++) {
267267
if (action === 'upload')
268268
upload(inputs[i])
269-
else if (action === 'saveLocally' || action === 'saveAs') {
269+
else if (action === 'download' || action === 'saveLocally' || action === 'saveAs') {
270270
save(inputs[i])
271271
}
272272
else if (action === 'export') {
@@ -325,15 +325,15 @@ async function fileRenderAction(data) {
325325

326326
}
327327

328-
async function save(input) {
328+
async function save(input, action) {
329329
try {
330330
let files = await getFiles(input)
331331

332332
for (let i = 0; i < files.length; i++) {
333333
if (!files[i].src) continue
334334

335-
if (files[i].handle) {
336-
if ('saveAs' == 'true') {
335+
if (files[i].handle && action !== 'download') {
336+
if (action === 'saveAs') {
337337
if (files[i].kind === 'file') {
338338
const options = {
339339
suggestedName: files[i].name,
@@ -550,55 +550,14 @@ observer.init({
550550
});
551551

552552
action.init({
553-
name: "upload",
553+
name: ["upload", "download", "saveLocally", "import", "export"],
554554
callback: (data) => {
555555
fileFormAction(data)
556556
}
557557
})
558558

559559
action.init({
560-
name: "saveLocally",
561-
callback: (data) => {
562-
fileFormAction(data)
563-
}
564-
})
565-
566-
action.init({
567-
name: "import",
568-
callback: (data) => {
569-
fileFormAction(data)
570-
}
571-
})
572-
573-
action.init({
574-
name: "export",
575-
callback: (data) => {
576-
fileFormAction(data)
577-
}
578-
})
579-
580-
action.init({
581-
name: "createFile",
582-
callback: (data) => {
583-
fileRenderAction(data)
584-
}
585-
})
586-
587-
action.init({
588-
name: "deleteFile",
589-
callback: (data) => {
590-
fileRenderAction(data)
591-
}
592-
})
593-
action.init({
594-
name: "createDirectory",
595-
callback: (data) => {
596-
fileRenderAction(data)
597-
}
598-
})
599-
600-
action.init({
601-
name: "deleteDirectory",
560+
name: ["createFile", "deleteFile", "createDirectory", "deleteDirectory"],
602561
callback: (data) => {
603562
fileRenderAction(data)
604563
}

0 commit comments

Comments
 (0)