|
| 1 | +/* |
| 2 | + FLASH-source.js - ESP3D WebUI Target file |
| 3 | +
|
| 4 | + Copyright (c) 2020 Luc Lebosse. All rights reserved. |
| 5 | +
|
| 6 | + This code is free software; you can redistribute it and/or |
| 7 | + modify it under the terms of the GNU Lesser General Public |
| 8 | + License as published by the Free Software Foundation; either |
| 9 | + version 2.1 of the License, or (at your option) any later version. |
| 10 | +
|
| 11 | + This code is distributed in the hope that it will be useful, |
| 12 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | + Lesser General Public License for more details. |
| 15 | +
|
| 16 | + You should have received a copy of the GNU Lesser General Public |
| 17 | + License along with This code; if not, write to the Free Software |
| 18 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | +*/ |
| 20 | +import { h } from "preact" |
| 21 | +import { sortedFilesList, formatStatus } from "../../../components/Helpers" |
| 22 | +import { canProcessFile } from "../../helpers" |
| 23 | +import { useSettingsContextFn, useUiContextFn } from "../../../contexts" |
| 24 | +const capabilities = { |
| 25 | + Process: (path, filename) => { |
| 26 | + return canProcessFile(filename) |
| 27 | + }, |
| 28 | + UseFilters: () => true, |
| 29 | + IsFlatFS: () => false, |
| 30 | + Upload: () => { |
| 31 | + return true |
| 32 | + }, |
| 33 | + Mount: () => { |
| 34 | + return false |
| 35 | + }, |
| 36 | + UploadMultiple: () => { |
| 37 | + return true |
| 38 | + }, |
| 39 | + Download: () => { |
| 40 | + return true |
| 41 | + }, |
| 42 | + DeleteFile: () => { |
| 43 | + return true |
| 44 | + }, |
| 45 | + DeleteDir: () => { |
| 46 | + return true |
| 47 | + }, |
| 48 | + CreateDir: () => { |
| 49 | + return true |
| 50 | + }, |
| 51 | +} |
| 52 | + |
| 53 | +const commands = { |
| 54 | + list: (path, filename) => { |
| 55 | + return { |
| 56 | + type: "url", |
| 57 | + url: "files", |
| 58 | + args: { path, action: "list" }, |
| 59 | + } |
| 60 | + }, |
| 61 | + upload: (path, filename) => { |
| 62 | + const upath = ( |
| 63 | + useSettingsContextFn.getValue("HostUploadPath") + path |
| 64 | + ).replaceAll("//", "/") |
| 65 | + return { |
| 66 | + type: "url", |
| 67 | + url: "files", |
| 68 | + args: { path: upath }, |
| 69 | + } |
| 70 | + }, |
| 71 | + formatResult: (resultTxT) => { |
| 72 | + const res = JSON.parse(resultTxT) |
| 73 | + if (useUiContextFn.getValue("sort_flashfs_files")){ |
| 74 | + res.files = sortedFilesList(res.files) |
| 75 | + } |
| 76 | + res.status = formatStatus(res.status) |
| 77 | + return res |
| 78 | + }, |
| 79 | + |
| 80 | + deletedir: (path, filename) => { |
| 81 | + return { |
| 82 | + type: "url", |
| 83 | + url: "files", |
| 84 | + args: { path, action: "deletedir", filename }, |
| 85 | + } |
| 86 | + }, |
| 87 | + delete: (path, filename) => { |
| 88 | + return { |
| 89 | + type: "url", |
| 90 | + url: "files", |
| 91 | + args: { path, action: "delete", filename }, |
| 92 | + } |
| 93 | + }, |
| 94 | + createdir: (path, filename) => { |
| 95 | + return { |
| 96 | + type: "url", |
| 97 | + url: "files", |
| 98 | + args: { path, action: "createdir", filename }, |
| 99 | + } |
| 100 | + }, |
| 101 | + download: (path, filename) => { |
| 102 | + const upath = ( |
| 103 | + useSettingsContextFn.getValue("HostUploadPath") + |
| 104 | + path + |
| 105 | + (path == "/" ? "" : "/") + |
| 106 | + filename |
| 107 | + ).replaceAll("//", "/") |
| 108 | + //console.log('Upath:', upath) |
| 109 | + return { |
| 110 | + type: "url", |
| 111 | + url: upath, |
| 112 | + args: {}, |
| 113 | + } |
| 114 | + }, |
| 115 | + play: (path, filename) => { |
| 116 | + const spath = (path + (path == "/" ? "" : "/") + filename).replaceAll( |
| 117 | + "//", |
| 118 | + "/" |
| 119 | + ) |
| 120 | + const cmd = useUiContextFn |
| 121 | + .getValue("playcmd") |
| 122 | + .replace("#", spath) |
| 123 | + .replaceAll("//", "/") |
| 124 | + return { |
| 125 | + type: "cmd", |
| 126 | + cmd, |
| 127 | + } |
| 128 | + }, |
| 129 | +} |
| 130 | + |
| 131 | +const FLASH = { capabilities, commands } |
| 132 | + |
| 133 | +export { FLASH } |
0 commit comments