miqro 6.2.13 → 7.0.1
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/README.md +9 -17
- package/build/editor.bundle.js +11601 -10129
- package/build/esm/src/bin/types.js +10 -5
- package/build/esm/src/cluster.js +1 -1
- package/build/esm/src/common/arguments.d.ts +2 -1
- package/build/esm/src/common/arguments.js +42 -18
- package/build/esm/src/common/assets.d.ts +1 -1
- package/build/esm/src/common/assets.js +34 -13
- package/build/esm/src/common/esbuild.d.ts +4 -1
- package/build/esm/src/common/esbuild.js +31 -26
- package/build/esm/src/common/exit.js +4 -4
- package/build/esm/src/common/help.d.ts +1 -1
- package/build/esm/src/common/help.js +2 -2
- package/build/esm/src/common/jsx.d.ts +2 -3
- package/build/esm/src/common/jsx.js +70 -75
- package/build/esm/src/common/paths.d.ts +0 -1
- package/build/esm/src/common/paths.js +3 -3
- package/build/esm/src/common/watch.d.ts +0 -1
- package/build/esm/src/common/watch.js +4 -1
- package/build/esm/src/inflate/inflate-sea.js +35 -24
- package/build/esm/src/inflate/inflate.js +4 -4
- package/build/esm/src/inflate/setup-auth.js +1 -1
- package/build/esm/src/inflate/setup-cors.js +1 -1
- package/build/esm/src/inflate/setup-db.js +2 -2
- package/build/esm/src/inflate/setup-error.js +1 -1
- package/build/esm/src/inflate/setup-http.js +16 -16
- package/build/esm/src/inflate/setup-log.js +1 -1
- package/build/esm/src/inflate/setup-middleware.js +1 -1
- package/build/esm/src/inflate/setup-server-config.js +1 -1
- package/build/esm/src/inflate/setup-ws.js +1 -1
- package/build/esm/src/inflate/setup.doc.d.ts +2 -2
- package/build/esm/src/inflate/setup.doc.js +23 -2
- package/build/esm/src/inflate/utils/sea-utils.js +2 -2
- package/build/esm/src/lib.d.ts +10 -1
- package/build/esm/src/lib.js +16 -1
- package/build/esm/src/main.js +2 -1
- package/build/esm/src/services/app.d.ts +1 -0
- package/build/esm/src/services/app.js +4 -5
- package/build/esm/src/services/migrations.js +2 -2
- package/build/esm/src/services/utils/jwt.d.ts +2 -0
- package/build/esm/src/services/utils/jwt.js +23 -0
- package/build/esm/src/services/utils/middleware.d.ts +9 -0
- package/build/esm/src/services/utils/middleware.js +9 -0
- package/build/esm/src/services/utils/server-interface.js +33 -4
- package/build/esm/src/types.d.ts +50 -83
- package/build/lib.cjs +15694 -15619
- package/package.json +6 -8
- package/sea/basic-compile.base64.sh +1 -1
- package/sea/basic-compile.sh +1 -1
- package/sea/install-nodejs.sh +1 -1
- package/sea/node.version.tag +1 -1
- package/.eslintrc +0 -15
- package/build/esm/editor/auth.d.ts +0 -6
- package/build/esm/editor/auth.js +0 -41
- package/build/esm/editor/common/admin-interface.d.ts +0 -36
- package/build/esm/editor/common/admin-interface.js +0 -44
- package/build/esm/editor/common/constants.d.ts +0 -4
- package/build/esm/editor/common/constants.js +0 -20
- package/build/esm/editor/common/constants.server.d.ts +0 -2
- package/build/esm/editor/common/constants.server.js +0 -4
- package/build/esm/editor/common/editor-index.d.ts +0 -2
- package/build/esm/editor/common/editor-index.js +0 -14
- package/build/esm/editor/common/html-encode.d.ts +0 -1
- package/build/esm/editor/common/html-encode.js +0 -14
- package/build/esm/editor/common/log-socket.d.ts +0 -15
- package/build/esm/editor/common/log-socket.js +0 -70
- package/build/esm/editor/common/templates.d.ts +0 -11
- package/build/esm/editor/common/templates.js +0 -477
- package/build/esm/editor/components/api-preview.d.ts +0 -11
- package/build/esm/editor/components/api-preview.js +0 -90
- package/build/esm/editor/components/editor.d.ts +0 -16
- package/build/esm/editor/components/editor.js +0 -365
- package/build/esm/editor/components/file-browser.d.ts +0 -37
- package/build/esm/editor/components/file-browser.js +0 -126
- package/build/esm/editor/components/file-editor-toolbar.d.ts +0 -22
- package/build/esm/editor/components/file-editor-toolbar.js +0 -93
- package/build/esm/editor/components/file-editor.d.ts +0 -32
- package/build/esm/editor/components/file-editor.js +0 -59
- package/build/esm/editor/components/filter-query.d.ts +0 -1
- package/build/esm/editor/components/filter-query.js +0 -22
- package/build/esm/editor/components/highlight-text-area.d.ts +0 -11
- package/build/esm/editor/components/highlight-text-area.js +0 -125
- package/build/esm/editor/components/log-viewer.d.ts +0 -6
- package/build/esm/editor/components/log-viewer.js +0 -69
- package/build/esm/editor/components/new-file.d.ts +0 -10
- package/build/esm/editor/components/new-file.js +0 -117
- package/build/esm/editor/components/scroll-query.d.ts +0 -7
- package/build/esm/editor/components/scroll-query.js +0 -21
- package/build/esm/editor/components/start-page.d.ts +0 -13
- package/build/esm/editor/components/start-page.js +0 -30
- package/build/esm/editor/http/admin/editor/api/fs/delete.api.d.ts +0 -3
- package/build/esm/editor/http/admin/editor/api/fs/delete.api.js +0 -29
- package/build/esm/editor/http/admin/editor/api/fs/read.api.d.ts +0 -5
- package/build/esm/editor/http/admin/editor/api/fs/read.api.js +0 -49
- package/build/esm/editor/http/admin/editor/api/fs/rename.api.d.ts +0 -4
- package/build/esm/editor/http/admin/editor/api/fs/rename.api.js +0 -39
- package/build/esm/editor/http/admin/editor/api/fs/scan.api.d.ts +0 -26
- package/build/esm/editor/http/admin/editor/api/fs/scan.api.js +0 -149
- package/build/esm/editor/http/admin/editor/api/fs/write.api.d.ts +0 -3
- package/build/esm/editor/http/admin/editor/api/fs/write.api.js +0 -38
- package/build/esm/editor/http/admin/editor/api/server/reload.api.d.ts +0 -10
- package/build/esm/editor/http/admin/editor/api/server/reload.api.js +0 -46
- package/build/esm/editor/http/admin/editor/api/server/restart.api.d.ts +0 -10
- package/build/esm/editor/http/admin/editor/api/server/restart.api.js +0 -45
- package/build/esm/editor/http/admin/editor/editor.d.ts +0 -1
- package/build/esm/editor/http/admin/editor/editor.js +0 -7
- package/build/esm/editor/http/admin/editor/index.api.d.ts +0 -3
- package/build/esm/editor/http/admin/editor/index.api.js +0 -21
- package/build/esm/editor/server.d.ts +0 -3
- package/build/esm/editor/server.js +0 -49
- package/build/esm/editor/ws.d.ts +0 -3
- package/build/esm/editor/ws.js +0 -11
- package/build/esm/src/services/globals.d.ts +0 -3
- package/build/esm/src/services/globals.js +0 -182
- package/build/jsx.dom.js +0 -1587
- package/build/postject.base64.cjs +0 -1
- package/editor/auth.ts +0 -51
- package/editor/common/admin-interface.ts +0 -84
- package/editor/common/constants.server.ts +0 -5
- package/editor/common/constants.ts +0 -21
- package/editor/common/editor-index.tsx +0 -17
- package/editor/common/html-encode.ts +0 -14
- package/editor/common/log-socket.tsx +0 -85
- package/editor/common/templates.ts +0 -481
- package/editor/components/api-preview.tsx +0 -116
- package/editor/components/editor.tsx +0 -494
- package/editor/components/file-browser.tsx +0 -308
- package/editor/components/file-editor-toolbar.tsx +0 -191
- package/editor/components/file-editor.tsx +0 -122
- package/editor/components/filter-query.tsx +0 -22
- package/editor/components/highlight-text-area.tsx +0 -145
- package/editor/components/log-viewer.tsx +0 -110
- package/editor/components/new-file.tsx +0 -169
- package/editor/components/scroll-query.tsx +0 -22
- package/editor/components/start-page.tsx +0 -49
- package/editor/http/admin/editor/api/fs/delete.api.tsx +0 -32
- package/editor/http/admin/editor/api/fs/read.api.tsx +0 -55
- package/editor/http/admin/editor/api/fs/rename.api.tsx +0 -41
- package/editor/http/admin/editor/api/fs/scan.api.tsx +0 -181
- package/editor/http/admin/editor/api/fs/write.api.tsx +0 -41
- package/editor/http/admin/editor/api/server/reload.api.ts +0 -53
- package/editor/http/admin/editor/api/server/restart.api.tsx +0 -52
- package/editor/http/admin/editor/editor.tsx +0 -8
- package/editor/http/admin/editor/index.api.tsx +0 -39
- package/editor/server.ts +0 -57
- package/editor/ws.ts +0 -15
- package/sea/types.json +0 -1
- package/src/bin/compile.ts +0 -35
- package/src/bin/doc-md.ts +0 -210
- package/src/bin/generate-doc.ts +0 -64
- package/src/bin/test.ts +0 -92
- package/src/bin/types.ts +0 -29
- package/src/cluster.ts +0 -27
- package/src/common/arguments.ts +0 -733
- package/src/common/assets.ts +0 -128
- package/src/common/checksum.ts +0 -58
- package/src/common/constants.ts +0 -18
- package/src/common/content-type.ts +0 -84
- package/src/common/esbuild.ts +0 -94
- package/src/common/exit.ts +0 -91
- package/src/common/fs.ts +0 -82
- package/src/common/help.ts +0 -60
- package/src/common/jsx.ts +0 -547
- package/src/common/jwt.ts +0 -85
- package/src/common/paths.ts +0 -107
- package/src/common/watch.ts +0 -85
- package/src/inflate/inflate-sea.ts +0 -226
- package/src/inflate/inflate.ts +0 -101
- package/src/inflate/md.ts +0 -25
- package/src/inflate/setup-auth.ts +0 -41
- package/src/inflate/setup-cors.ts +0 -41
- package/src/inflate/setup-db.ts +0 -117
- package/src/inflate/setup-error.ts +0 -44
- package/src/inflate/setup-http.ts +0 -704
- package/src/inflate/setup-log.ts +0 -45
- package/src/inflate/setup-middleware.ts +0 -47
- package/src/inflate/setup-server-config.ts +0 -48
- package/src/inflate/setup-test.ts +0 -23
- package/src/inflate/setup-ws.ts +0 -50
- package/src/inflate/setup.doc.ts +0 -68
- package/src/inflate/utils/sea-utils.ts +0 -14
- package/src/lib.ts +0 -19
- package/src/main.ts +0 -100
- package/src/services/app.ts +0 -698
- package/src/services/editor.tsx +0 -101
- package/src/services/globals.ts +0 -186
- package/src/services/hot-reload.ts +0 -51
- package/src/services/migrations.ts +0 -68
- package/src/services/utils/admin-interface.ts +0 -37
- package/src/services/utils/cache.ts +0 -88
- package/src/services/utils/cluster-cache.ts +0 -230
- package/src/services/utils/cluster-ws.ts +0 -202
- package/src/services/utils/db-manager.ts +0 -92
- package/src/services/utils/get-route.ts +0 -70
- package/src/services/utils/log-transport.ts +0 -81
- package/src/services/utils/log.ts +0 -92
- package/src/services/utils/server-interface.ts +0 -92
- package/src/services/utils/websocketmanager.ts +0 -157
- package/src/types/@esbuild.d.ts +0 -1
- package/src/types/@miqro/core.d.ts +0 -2
- package/src/types/@miqro/jsx.d.ts +0 -2
- package/src/types/@miqro/parser.d.ts +0 -2
- package/src/types/@miqro/query.d.ts +0 -2
- package/src/types/@miqro/request.d.ts +0 -2
- package/src/types/@miqro/test.d.ts +0 -2
- package/src/types/@miqro.d.ts +0 -1
- package/src/types/@types.d.ts +0 -1
- package/src/types/browser.globals.d.ts +0 -1
- package/src/types/cookie.d.ts +0 -2
- package/src/types/globals.d.ts +0 -2
- package/src/types/jose.d.ts +0 -2
- package/src/types/jsx.globals.d.ts +0 -38
- package/src/types/miqro.d.ts +0 -228
- package/src/types/postject.d.ts +0 -1
- package/src/types/server.globals.d.ts +0 -47
- package/src/types.ts +0 -304
- package/tsconfig.json +0 -35
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
interface FileEditorProps {
|
|
2
|
-
current: boolean;
|
|
3
|
-
error: string;
|
|
4
|
-
path: string;
|
|
5
|
-
previewPath: string | undefined;
|
|
6
|
-
apiPreview: undefined | {
|
|
7
|
-
path: string;
|
|
8
|
-
method: string;
|
|
9
|
-
}[];
|
|
10
|
-
content: string | null;
|
|
11
|
-
contentchange: (content: string) => void;
|
|
12
|
-
closeFile: () => void;
|
|
13
|
-
saveFile: (reload?: boolean) => void;
|
|
14
|
-
revertFile: () => void;
|
|
15
|
-
deleteFile: () => void;
|
|
16
|
-
renameFile: (newName: any) => void;
|
|
17
|
-
setlanguage: (newLanguage: any) => void;
|
|
18
|
-
language: string;
|
|
19
|
-
changed: boolean;
|
|
20
|
-
reloadString: string;
|
|
21
|
-
togglePanel: (panel: string) => void;
|
|
22
|
-
isPanelVisible: (panel: string) => boolean;
|
|
23
|
-
disableLog?: boolean;
|
|
24
|
-
disablePreview?: boolean;
|
|
25
|
-
disableReload?: boolean;
|
|
26
|
-
}
|
|
27
|
-
export declare function FileEditor({ disableLog, disablePreview, disableReload, togglePanel, isPanelVisible, apiPreview, reloadString, error, revertFile, changed, setlanguage, saveFile, deleteFile, renameFile, current, path, previewPath, content, contentchange, closeFile, language }: FileEditorProps): JSX.Element;
|
|
28
|
-
export declare namespace FileEditor {
|
|
29
|
-
var asFragment: boolean;
|
|
30
|
-
var shadowInit: boolean;
|
|
31
|
-
}
|
|
32
|
-
export {};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { APIPReview } from "./api-preview.js";
|
|
2
|
-
import { FileEditorToolbar } from "./file-editor-toolbar.js";
|
|
3
|
-
import { HighlightTextArea } from "./highlight-text-area.js";
|
|
4
|
-
import { useScroll } from "./scroll-query.js";
|
|
5
|
-
export function FileEditor({ disableLog, disablePreview, disableReload, togglePanel, isPanelVisible, apiPreview, reloadString, error, revertFile, changed, setlanguage, saveFile, deleteFile, renameFile, current, path, previewPath, content, contentchange, closeFile, language }) {
|
|
6
|
-
//console.log("FileEditor [%s]", path);
|
|
7
|
-
const iFrameRef = jsx.useRef();
|
|
8
|
-
const scrollRef = jsx.useRef();
|
|
9
|
-
const [scroll, setScroll] = useScroll();
|
|
10
|
-
jsx.useEffect(() => {
|
|
11
|
-
if (scrollRef.current) {
|
|
12
|
-
scrollRef.current.scrollLeft = scroll.scrollLeft;
|
|
13
|
-
scrollRef.current.scrollTop = scroll.scrollTop;
|
|
14
|
-
}
|
|
15
|
-
}, [scrollRef.current]);
|
|
16
|
-
jsx.useEffect(() => {
|
|
17
|
-
if (current && scrollRef.current) {
|
|
18
|
-
setScroll({
|
|
19
|
-
scrollLeft: scrollRef.current.scrollLeft,
|
|
20
|
-
scrollTop: scrollRef.current.scrollTop
|
|
21
|
-
}, true);
|
|
22
|
-
}
|
|
23
|
-
}, [current]);
|
|
24
|
-
jsx.useEffect(() => {
|
|
25
|
-
if (iFrameRef.current) {
|
|
26
|
-
iFrameRef.current.src = "";
|
|
27
|
-
iFrameRef.current.src = previewPath;
|
|
28
|
-
}
|
|
29
|
-
}, [iFrameRef.current, previewPath, reloadString]);
|
|
30
|
-
return JSX.createElement("div", { class: "file-editor" }, content === null ? JSX.createElement("p", null, "loading") : JSX.createElement(JSX.Fragment, null,
|
|
31
|
-
JSX.createElement(FileEditorToolbar, { disableLog: disableLog, disablePreview: disablePreview, disableReload: disableReload, isPanelVisible: isPanelVisible, togglePanel: togglePanel, revertFile: revertFile, closeFile: closeFile, language: language, path: path, changed: changed, saveFile: saveFile, setlanguage: setlanguage, deleteFile: deleteFile, renameFile: renameFile }),
|
|
32
|
-
JSX.createElement("div", {
|
|
33
|
-
//class={`file-editor-content${previewPath || apiPreview ? " split" : ""}`}
|
|
34
|
-
class: "file-editor-content" },
|
|
35
|
-
JSX.createElement("div", { ref: scrollRef, class: `file-editor-text-editor${previewPath || (apiPreview && apiPreview.length > 0) && isPanelVisible("right") ? " split" : ""}`,
|
|
36
|
-
//class={`file-editor-text-editor`}
|
|
37
|
-
onscroll: ev => {
|
|
38
|
-
setScroll({
|
|
39
|
-
scrollLeft: ev.target.scrollLeft,
|
|
40
|
-
scrollTop: ev.target.scrollTop
|
|
41
|
-
});
|
|
42
|
-
} },
|
|
43
|
-
error ?
|
|
44
|
-
JSX.createElement("p", { class: "file-editor-content-error" }, error)
|
|
45
|
-
: JSX.createElement(JSX.Fragment, null),
|
|
46
|
-
language !== "binary" ?
|
|
47
|
-
JSX.createElement(HighlightTextArea, { tabChar: " ", oncontentchange: (args) => {
|
|
48
|
-
if (contentchange) {
|
|
49
|
-
contentchange(args.detail);
|
|
50
|
-
}
|
|
51
|
-
}, content: content, language: language }) : JSX.createElement("p", null, "binary data not supported")),
|
|
52
|
-
apiPreview && apiPreview.length > 0 ? JSX.createElement(APIPReview, { isPanelVisible: isPanelVisible, apiPreview: apiPreview }) : JSX.createElement(JSX.Fragment, null),
|
|
53
|
-
previewPath && isPanelVisible("right") ? JSX.createElement("div", { class: `file-editor-preview`, style: `${!isPanelVisible("right") ? "display: none;" : ""}` },
|
|
54
|
-
JSX.createElement("div", { class: "file-editor-preview-path" },
|
|
55
|
-
JSX.createElement("a", { href: previewPath, target: "_blank" }, "open in new window")),
|
|
56
|
-
JSX.createElement("iframe", { ref: iFrameRef, src: previewPath, sandbox: "allow-scripts allow-same-origin" })) : JSX.createElement(JSX.Fragment, null))));
|
|
57
|
-
}
|
|
58
|
-
FileEditor.asFragment = true;
|
|
59
|
-
FileEditor.shadowInit = false;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function useFilterQuery(): [string, (newFilter: string, inmediate?: boolean) => void];
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
let queryTimeout2 = null;
|
|
2
|
-
export function useFilterQuery() {
|
|
3
|
-
const [filterQuery, setfilterQuery] = jsx.useQuery("filter", "");
|
|
4
|
-
const [filter, setfilter] = jsx.useState(typeof filterQuery === "string" ? filterQuery : "");
|
|
5
|
-
return [
|
|
6
|
-
filter,
|
|
7
|
-
(newFilter, inmediate) => {
|
|
8
|
-
clearTimeout(queryTimeout2);
|
|
9
|
-
if (inmediate) {
|
|
10
|
-
setfilter(newFilter);
|
|
11
|
-
setfilterQuery(newFilter);
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
setfilter(newFilter);
|
|
15
|
-
queryTimeout2 = setTimeout(() => {
|
|
16
|
-
setfilter(newFilter);
|
|
17
|
-
setfilterQuery(newFilter);
|
|
18
|
-
}, 1000);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
];
|
|
22
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export declare function HighlightTextArea({ content, language, oncontentchange, tabChar, disabled }: {
|
|
2
|
-
language: string;
|
|
3
|
-
content: string;
|
|
4
|
-
disabled?: string;
|
|
5
|
-
tabChar?: string;
|
|
6
|
-
oncontentchange?: (ev: CustomEvent) => void;
|
|
7
|
-
}): JSX.Element;
|
|
8
|
-
export declare namespace HighlightTextArea {
|
|
9
|
-
var asFragment: boolean;
|
|
10
|
-
var shadowInit: boolean;
|
|
11
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
//import hljs from "../lib/highlight/core.min.js"
|
|
2
|
-
import hljs from 'highlight.js/lib/core';
|
|
3
|
-
import javascript from 'highlight.js/lib/languages/javascript';
|
|
4
|
-
import xml from "highlight.js/lib/languages/xml";
|
|
5
|
-
import css from "highlight.js/lib/languages/css";
|
|
6
|
-
import scss from "highlight.js/lib/languages/scss";
|
|
7
|
-
import markdown from "highlight.js/lib/languages/markdown";
|
|
8
|
-
import dockerfile from "highlight.js/lib/languages/dockerfile";
|
|
9
|
-
import yaml from "highlight.js/lib/languages/yaml";
|
|
10
|
-
import typescript from "highlight.js/lib/languages/typescript";
|
|
11
|
-
import c from "highlight.js/lib/languages/c";
|
|
12
|
-
import cpp from "highlight.js/lib/languages/cpp";
|
|
13
|
-
import bash from "highlight.js/lib/languages/bash";
|
|
14
|
-
import python from "highlight.js/lib/languages/python";
|
|
15
|
-
import text from "highlight.js/lib/languages/plaintext";
|
|
16
|
-
import json from "highlight.js/lib/languages/json";
|
|
17
|
-
// Then register the languages you need
|
|
18
|
-
hljs.registerLanguage('text', text);
|
|
19
|
-
hljs.registerLanguage('dockerfile', dockerfile);
|
|
20
|
-
hljs.registerLanguage('yaml', yaml);
|
|
21
|
-
hljs.registerLanguage('javascript', javascript);
|
|
22
|
-
hljs.registerLanguage('xml', xml);
|
|
23
|
-
hljs.registerLanguage('html', xml);
|
|
24
|
-
hljs.registerLanguage('css', css);
|
|
25
|
-
hljs.registerLanguage('scss', scss);
|
|
26
|
-
hljs.registerLanguage('markdown', markdown);
|
|
27
|
-
hljs.registerLanguage('typescript', typescript);
|
|
28
|
-
hljs.registerLanguage('c', c);
|
|
29
|
-
hljs.registerLanguage('cpp', cpp);
|
|
30
|
-
hljs.registerLanguage('bash', bash);
|
|
31
|
-
hljs.registerLanguage('python', python);
|
|
32
|
-
hljs.registerLanguage('json', json);
|
|
33
|
-
/*!
|
|
34
|
-
Theme: GitHub Dark
|
|
35
|
-
Description: Dark theme as seen on github.com
|
|
36
|
-
Author: github.com
|
|
37
|
-
Maintainer: @Hirse
|
|
38
|
-
Updated: 2021-05-15
|
|
39
|
-
|
|
40
|
-
Outdated base version: https://github.com/primer/github-syntax-dark
|
|
41
|
-
Current colors taken from GitHub's CSS
|
|
42
|
-
*/
|
|
43
|
-
const STYLE = `pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{color:#c9d1d9;background:#0d1117}.hljs-doctag,.hljs-keyword,.hljs-meta .hljs-keyword,.hljs-template-tag,.hljs-template-variable,.hljs-type,.hljs-variable.language_{color:#ff7b72}.hljs-title,.hljs-title.class_,.hljs-title.class_.inherited__,.hljs-title.function_{color:#d2a8ff}.hljs-attr,.hljs-attribute,.hljs-literal,.hljs-meta,.hljs-number,.hljs-operator,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-id,.hljs-variable{color:#79c0ff}.hljs-meta .hljs-string,.hljs-regexp,.hljs-string{color:#a5d6ff}.hljs-built_in,.hljs-symbol{color:#ffa657}.hljs-code,.hljs-comment,.hljs-formula{color:#8b949e}.hljs-name,.hljs-quote,.hljs-selector-pseudo,.hljs-selector-tag{color:#7ee787}.hljs-subst{color:#c9d1d9}.hljs-section{color:#1f6feb;font-weight:700}.hljs-bullet{color:#f2cc60}.hljs-emphasis{color:#c9d1d9;font-style:italic}.hljs-strong{color:#c9d1d9;font-weight:700}.hljs-addition{color:#aff5b4;background-color:#033a16}.hljs-deletion{color:#ffdcd7;background-color:#67060c}code{outline: 0px solid rgba(0, 0, 0, 0.263);caret-color: red;}.hljs-name{color: #e8910d;}.hljs-tag .hljs-attr, .hljs-tag .hljs-name{color: #e8910d;}`;
|
|
44
|
-
const POSTTYLE = "pre{padding:0; margin:0;} code { background-color: #000000; color: #ffffff; }";
|
|
45
|
-
const TAG_NAME = "HIGHLIGHT-TEXT-AREA";
|
|
46
|
-
function runHighlight(content, language) {
|
|
47
|
-
const now = Date.now();
|
|
48
|
-
console.log("runHighlight [%s]", language);
|
|
49
|
-
const value = hljs.highlight(String(content), {
|
|
50
|
-
language,
|
|
51
|
-
ignoreIllegals: true
|
|
52
|
-
}).value;
|
|
53
|
-
console.log("runHighlight [%s] took [%s]ms", language, Date.now() - now);
|
|
54
|
-
return value;
|
|
55
|
-
}
|
|
56
|
-
function emitEvents(elementRef, topMost, content, oncontentchange) {
|
|
57
|
-
if (elementRef.current && topMost.current) {
|
|
58
|
-
const currentContent = elementRef.current.textContent;
|
|
59
|
-
const webComponentElement = topMost.current.parentNode;
|
|
60
|
-
const event = new CustomEvent("contentchange", { detail: currentContent });
|
|
61
|
-
if (webComponentElement && webComponentElement instanceof HTMLElement && webComponentElement.tagName === TAG_NAME) {
|
|
62
|
-
try {
|
|
63
|
-
webComponentElement.dispatchEvent(event);
|
|
64
|
-
}
|
|
65
|
-
catch (e) {
|
|
66
|
-
console.error(e);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (typeof oncontentchange === "function") {
|
|
70
|
-
try {
|
|
71
|
-
oncontentchange(event);
|
|
72
|
-
}
|
|
73
|
-
catch (e) {
|
|
74
|
-
console.error(e);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
export function HighlightTextArea({ content, language, oncontentchange, tabChar, disabled }) {
|
|
80
|
-
const elementRef = jsx.useRef();
|
|
81
|
-
const topMost = jsx.useRef();
|
|
82
|
-
const [lastLanguage, setlastLanguage] = jsx.useState(language);
|
|
83
|
-
// effect to watch changes to language
|
|
84
|
-
jsx.useEffect(() => {
|
|
85
|
-
if (elementRef.current && (lastLanguage !== language || elementRef.current.textContent !== content)) {
|
|
86
|
-
setlastLanguage(language);
|
|
87
|
-
elementRef.current.innerHTML = runHighlight(content, language);
|
|
88
|
-
}
|
|
89
|
-
}, [lastLanguage, language, elementRef.current, content]);
|
|
90
|
-
return JSX.createElement("pre", { ref: topMost },
|
|
91
|
-
JSX.createElement("style", { innerHTML: STYLE + POSTTYLE }),
|
|
92
|
-
JSX.createElement("code", { autocomplete: "off", autocorrect: "off", autocapitalize: "off", spellcheck: "false", contenteditable: disabled ? "false" : "true", ref: elementRef, tabindex: "0", innerHTML: !elementRef.current ? runHighlight(content, language) : null, onfocusout: async (ev) => {
|
|
93
|
-
ev.preventDefault();
|
|
94
|
-
if (elementRef.current) {
|
|
95
|
-
if (content !== elementRef.current.textContent) {
|
|
96
|
-
//setlastContent(String(elementRef.current.textContent));
|
|
97
|
-
//elementRef.current.innerHTML = runHighlight(elementRef.current.textContent, language);
|
|
98
|
-
}
|
|
99
|
-
elementRef.current.innerHTML = runHighlight(elementRef.current.textContent, language);
|
|
100
|
-
}
|
|
101
|
-
}, onkeydown: ev => {
|
|
102
|
-
if (ev.keyCode === 9) {
|
|
103
|
-
ev.preventDefault();
|
|
104
|
-
// now insert four non-breaking spaces for the tab key
|
|
105
|
-
const sel = document.getSelection();
|
|
106
|
-
if (sel && topMost.current) {
|
|
107
|
-
if (topMost.current.contains(sel.anchorNode)) {
|
|
108
|
-
const range = sel.getRangeAt(0);
|
|
109
|
-
const tabNode = document.createTextNode(tabChar ? tabChar : "\t");
|
|
110
|
-
range.insertNode(tabNode);
|
|
111
|
-
range.setStartAfter(tabNode);
|
|
112
|
-
range.setEndAfter(tabNode);
|
|
113
|
-
sel.removeAllRanges();
|
|
114
|
-
sel.addRange(range);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
emitEvents(elementRef, topMost, content, oncontentchange);
|
|
118
|
-
}
|
|
119
|
-
}, oninput: ev => {
|
|
120
|
-
ev.preventDefault();
|
|
121
|
-
emitEvents(elementRef, topMost, content, oncontentchange);
|
|
122
|
-
} }));
|
|
123
|
-
}
|
|
124
|
-
HighlightTextArea.asFragment = true;
|
|
125
|
-
HighlightTextArea.shadowInit = false;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
function getUniqueIdentifiers(lines) {
|
|
2
|
-
const identifiersCache = {};
|
|
3
|
-
return lines.map(l => l.identifier).filter(identifier => {
|
|
4
|
-
const filter = !identifiersCache[identifier];
|
|
5
|
-
identifiersCache[identifier] = true;
|
|
6
|
-
return filter;
|
|
7
|
-
});
|
|
8
|
-
}
|
|
9
|
-
const LOG_LEVEL_MAP = {
|
|
10
|
-
"none": 0,
|
|
11
|
-
"error": 1,
|
|
12
|
-
"warn": 2,
|
|
13
|
-
"info": 3,
|
|
14
|
-
"debug": 4,
|
|
15
|
-
"trace": 5,
|
|
16
|
-
};
|
|
17
|
-
export function LogViewer(props) {
|
|
18
|
-
const { lines, clearLog, getMaxlogsize, setMaxLogSize } = props.socket;
|
|
19
|
-
const maxLogSize = getMaxlogsize();
|
|
20
|
-
const refresh = jsx.useRefresh();
|
|
21
|
-
jsx.useEffect(() => {
|
|
22
|
-
refresh();
|
|
23
|
-
}, [maxLogSize]);
|
|
24
|
-
const [identifier, setidentifier] = jsx.useState("");
|
|
25
|
-
const [level, setlevel] = jsx.useState("debug");
|
|
26
|
-
const [filter, setfilter] = jsx.useState("");
|
|
27
|
-
const identifiers = getUniqueIdentifiers(lines).sort();
|
|
28
|
-
//console.log(identifiers);
|
|
29
|
-
return JSX.createElement("div", { class: "log-viewer" },
|
|
30
|
-
JSX.createElement("div", { class: "log-viewer-toolbar" },
|
|
31
|
-
JSX.createElement("button", { class: "btn", onclick: e => {
|
|
32
|
-
e.preventDefault();
|
|
33
|
-
clearLog();
|
|
34
|
-
} }, "clear log"),
|
|
35
|
-
JSX.createElement("select", { value: maxLogSize, oninput: ev => {
|
|
36
|
-
ev.preventDefault();
|
|
37
|
-
if (ev.target.value === "unlimited") {
|
|
38
|
-
setMaxLogSize("unlimited");
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
setMaxLogSize(parseInt(ev.target.value, 10));
|
|
42
|
-
}
|
|
43
|
-
}, style: "margin: 0; padding: 0; margin-left:auto; margin-right: 0;" },
|
|
44
|
-
["10", "1000", "5000", "10000", "15000", "20000", "25000", "50000", "100000", "500000", "1000000", "1500000", "5000000"].map(l => JSX.createElement("option", { value: l }, l)),
|
|
45
|
-
JSX.createElement("option", { value: "unlimited" }, "unlimited")),
|
|
46
|
-
JSX.createElement("select", { value: level, oninput: ev => {
|
|
47
|
-
ev.preventDefault();
|
|
48
|
-
setlevel(ev.target.value);
|
|
49
|
-
}, style: "margin: 0; padding: 0; margin-left:var(--file-browser-separation); margin-right: 0;" },
|
|
50
|
-
["error", "warn", "info", "debug", "trace"].map(l => JSX.createElement("option", { value: l }, l)),
|
|
51
|
-
JSX.createElement("option", { value: "" }, "all")),
|
|
52
|
-
JSX.createElement("select", { value: identifier, oninput: ev => {
|
|
53
|
-
ev.preventDefault();
|
|
54
|
-
setidentifier(ev.target.value);
|
|
55
|
-
}, style: "margin: 0; padding: 0; margin-left:var(--file-browser-separation); margin-right: 0;" },
|
|
56
|
-
identifiers.map(identifier => JSX.createElement("option", { value: identifier }, identifier)),
|
|
57
|
-
JSX.createElement("option", { value: "" })),
|
|
58
|
-
JSX.createElement("input", { style: "margin: 0; padding: 0; margin-left:var(--file-browser-separation); margin-right: 0;", value: filter, oninput: ev => {
|
|
59
|
-
ev.preventDefault();
|
|
60
|
-
setfilter(ev.target.value);
|
|
61
|
-
}, type: "text", placeholder: "..filter.." })),
|
|
62
|
-
JSX.createElement("div", { class: "log-viewer-log" }, lines
|
|
63
|
-
.filter(line => identifier === "" || line.identifier === identifier)
|
|
64
|
-
.filter(line => filter === "" || line.out.indexOf(filter) !== -1)
|
|
65
|
-
.filter(line => {
|
|
66
|
-
return (level === "" || LOG_LEVEL_MAP[level] >= LOG_LEVEL_MAP[line.level]);
|
|
67
|
-
})
|
|
68
|
-
.map(line => JSX.createElement("p", { style: "margin: 0; padding: 0; border-radius: 0; font-size: 12px;", class: line.level === "error" ? "info-danger" : line.level === "warn" ? "info-warn" : line.level === "trace" ? "info-success" : line.level === "debug" ? "info-info" : "" }, line.out)).reverse()));
|
|
69
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { BASEEDITOR_PATH } from "../common/constants.js";
|
|
2
|
-
import { TEMPLATES } from "../common/templates.js";
|
|
3
|
-
import { HighlightTextArea } from "./highlight-text-area.js";
|
|
4
|
-
export function NewFile(props) {
|
|
5
|
-
const [template, settemplate] = jsx.useState("EMPTY");
|
|
6
|
-
const refresh = jsx.useRefresh();
|
|
7
|
-
const [service, setservice] = jsx.useState(props.services[0]);
|
|
8
|
-
const nameInput = jsx.useRef();
|
|
9
|
-
//const open = dialog ? dialog.open : false;
|
|
10
|
-
/*jsx.useEffect(() => {
|
|
11
|
-
if (dialog) {
|
|
12
|
-
//console.log((dialogRef.current as any).open);
|
|
13
|
-
if (open !== props.open) {
|
|
14
|
-
if (nameInput.current) {
|
|
15
|
-
nameInput.current.value = "";
|
|
16
|
-
nameInput.current.focus();
|
|
17
|
-
}
|
|
18
|
-
if (props.open) {
|
|
19
|
-
console.log("showModal");
|
|
20
|
-
dialog.showModal();
|
|
21
|
-
//(dialogRef.current as any).show();
|
|
22
|
-
} else {
|
|
23
|
-
console.log("closeModal");
|
|
24
|
-
//dialog.close();
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}, [dialog, open, props.open]);*/
|
|
29
|
-
jsx.useEffect(() => {
|
|
30
|
-
if (nameInput.current) {
|
|
31
|
-
nameInput.current.value = "";
|
|
32
|
-
nameInput.current.focus();
|
|
33
|
-
}
|
|
34
|
-
}, [nameInput.current]);
|
|
35
|
-
function close(file) {
|
|
36
|
-
//console.log("closeModal");
|
|
37
|
-
if (props.ondone) {
|
|
38
|
-
props.ondone(file);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
let nextMigrationNumber = 1;
|
|
42
|
-
if (props.migrations.length > 0) {
|
|
43
|
-
const lastMigration = props.migrations[props.migrations.length - 1];
|
|
44
|
-
const indexOfDash = lastMigration.indexOf("-");
|
|
45
|
-
if (indexOfDash !== -1) {
|
|
46
|
-
nextMigrationNumber = parseInt(lastMigration.substring(0, indexOfDash), 10) + 1;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
const httpPath = (TEMPLATES[template].filename ? TEMPLATES[template].filename : nameInput.current?.value) + (TEMPLATES[template].httpSufix ? TEMPLATES[template].httpSufix : "");
|
|
50
|
-
const filename = (service ? service + "/" : "") + (service && TEMPLATES[template].prefix ? TEMPLATES[template].prefix + "/" : "") + (template === "MIGRATION" ? nextMigrationNumber + "-" : "") + (TEMPLATES[template].filename ? TEMPLATES[template].filename : nameInput.current?.value) + (TEMPLATES[template].sufix ? TEMPLATES[template].sufix : "");
|
|
51
|
-
async function createNewFile() {
|
|
52
|
-
if ((nameInput.current && nameInput.current.value) || TEMPLATES[template].filename) {
|
|
53
|
-
const t = TEMPLATES[template];
|
|
54
|
-
await fetch(BASEEDITOR_PATH + "/api/fs/write", {
|
|
55
|
-
method: "POST",
|
|
56
|
-
headers: {
|
|
57
|
-
["content-type"]: "application/json"
|
|
58
|
-
},
|
|
59
|
-
body: JSON.stringify({
|
|
60
|
-
path: filename,
|
|
61
|
-
contents: t.template ? t.template(filename, httpPath) : ""
|
|
62
|
-
})
|
|
63
|
-
});
|
|
64
|
-
return filename;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return JSX.createElement(JSX.Fragment, null, props.open ? JSX.createElement("dialog", { class: "new-dialog", open: "" },
|
|
68
|
-
JSX.createElement("div", { class: "dialog-header" },
|
|
69
|
-
JSX.createElement("h1", null, "Create new File")),
|
|
70
|
-
JSX.createElement("div", { class: "dialog-body" },
|
|
71
|
-
JSX.createElement("select", { value: service, oninput: ev => {
|
|
72
|
-
ev.preventDefault();
|
|
73
|
-
ev.stopPropagation();
|
|
74
|
-
console.log(ev.target.value);
|
|
75
|
-
setservice(ev.target.value);
|
|
76
|
-
}, style: "margin: 0; padding: 0; margin-left:auto; margin-right: var(--file-browser-separation); width: 100%; margin-top: var(--file-browser-separation); margin-bottom: var(--file-browser-separation);" },
|
|
77
|
-
JSX.createElement("option", { value: "" }),
|
|
78
|
-
props.services.map(service => JSX.createElement("option", { value: service }, service))),
|
|
79
|
-
JSX.createElement("p", { style: "margin: 0; margin-bottom: var(--file-browser-separation);" }, filename),
|
|
80
|
-
!TEMPLATES[template].filename ? JSX.createElement("form", { style: "width: 100%;", onsubmit: async (ev) => {
|
|
81
|
-
ev.preventDefault();
|
|
82
|
-
ev.stopPropagation();
|
|
83
|
-
const path = await createNewFile();
|
|
84
|
-
close(path);
|
|
85
|
-
} },
|
|
86
|
-
JSX.createElement("input", { style: "width: 100%;", onkeydown: ev => {
|
|
87
|
-
if (ev.keyCode === 27) {
|
|
88
|
-
// catch esc
|
|
89
|
-
ev.stopPropagation();
|
|
90
|
-
ev.preventDefault();
|
|
91
|
-
close();
|
|
92
|
-
}
|
|
93
|
-
refresh();
|
|
94
|
-
}, ref: nameInput, type: "text", placeholder: "...filename..." })) : JSX.createElement(JSX.Fragment, null),
|
|
95
|
-
JSX.createElement("select", { value: template, oninput: ev => {
|
|
96
|
-
ev.preventDefault();
|
|
97
|
-
ev.stopPropagation();
|
|
98
|
-
console.log(ev.target.value);
|
|
99
|
-
settemplate(ev.target.value);
|
|
100
|
-
}, style: "margin: 0; padding: 0; margin-left:auto; margin-right: var(--file-browser-separation); width: 100%; margin-top: var(--file-browser-separation);" }, Object.keys(TEMPLATES).map(templateName => JSX.createElement("option", { value: templateName }, TEMPLATES[templateName].displayName))),
|
|
101
|
-
TEMPLATES[template].template ? JSX.createElement("div", { class: "new-dialog-preview" },
|
|
102
|
-
JSX.createElement(HighlightTextArea, { content: TEMPLATES[template].template(filename, httpPath), language: TEMPLATES[template].language, disabled: "true" })) : JSX.createElement(JSX.Fragment, null)),
|
|
103
|
-
JSX.createElement("div", { class: "dialog-footer" },
|
|
104
|
-
JSX.createElement("button", { class: "btn danger", onclick: ev => {
|
|
105
|
-
ev.preventDefault();
|
|
106
|
-
ev.stopPropagation();
|
|
107
|
-
close();
|
|
108
|
-
} }, "cancel"),
|
|
109
|
-
JSX.createElement("button", { style: "margin-left: auto;", class: "btn active", onclick: async (ev) => {
|
|
110
|
-
ev.preventDefault();
|
|
111
|
-
ev.stopPropagation();
|
|
112
|
-
const path = await createNewFile();
|
|
113
|
-
close(path);
|
|
114
|
-
} }, "create"))) : JSX.createElement(JSX.Fragment, null));
|
|
115
|
-
}
|
|
116
|
-
NewFile.asFragment = true;
|
|
117
|
-
NewFile.shadowInit = false;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
let scrollTimeout2 = null;
|
|
2
|
-
export function useScroll() {
|
|
3
|
-
const [scrollTop, setscrollTop] = jsx.useQuery("scrollTop", "0");
|
|
4
|
-
const [scrollLeft, setscrollLeft] = jsx.useQuery("scrollLeft", "0");
|
|
5
|
-
return [{
|
|
6
|
-
scrollTop: scrollTop,
|
|
7
|
-
scrollLeft: scrollLeft
|
|
8
|
-
}, (newScroll, inmediate) => {
|
|
9
|
-
clearTimeout(scrollTimeout2);
|
|
10
|
-
if (inmediate) {
|
|
11
|
-
setscrollTop(String(newScroll.scrollTop));
|
|
12
|
-
setscrollLeft(String(newScroll.scrollLeft));
|
|
13
|
-
}
|
|
14
|
-
else {
|
|
15
|
-
scrollTimeout2 = setTimeout(() => {
|
|
16
|
-
setscrollTop(String(newScroll.scrollTop));
|
|
17
|
-
setscrollLeft(String(newScroll.scrollLeft));
|
|
18
|
-
}, 1000);
|
|
19
|
-
}
|
|
20
|
-
}];
|
|
21
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
interface StartPageProps {
|
|
2
|
-
togglePanel: (panel: string) => void;
|
|
3
|
-
isPanelVisible: (panel: string) => boolean;
|
|
4
|
-
disableLog?: boolean;
|
|
5
|
-
disablePreview?: boolean;
|
|
6
|
-
disableReload?: boolean;
|
|
7
|
-
}
|
|
8
|
-
export declare function StartPage(props: StartPageProps): JSX.Element;
|
|
9
|
-
export declare namespace StartPage {
|
|
10
|
-
var asFragment: boolean;
|
|
11
|
-
var shadowInit: boolean;
|
|
12
|
-
}
|
|
13
|
-
export {};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export function StartPage(props) {
|
|
2
|
-
jsx.useEffect(() => {
|
|
3
|
-
if (!props.isPanelVisible("left")) {
|
|
4
|
-
props.togglePanel("left");
|
|
5
|
-
}
|
|
6
|
-
}, []);
|
|
7
|
-
return JSX.createElement("div", { class: `start-page` },
|
|
8
|
-
JSX.createElement("div", { class: "row center" },
|
|
9
|
-
JSX.createElement("h1", null, "Start Page")),
|
|
10
|
-
JSX.createElement("br", null),
|
|
11
|
-
JSX.createElement("div", { class: "row center" },
|
|
12
|
-
JSX.createElement("div", { class: "row" },
|
|
13
|
-
JSX.createElement("div", { class: `toggle-panel-button left-side-panel-button ${props.isPanelVisible("left") ? "active" : ""}`, onclick: ev => {
|
|
14
|
-
ev.preventDefault();
|
|
15
|
-
props.togglePanel("left");
|
|
16
|
-
} }),
|
|
17
|
-
JSX.createElement("br", null),
|
|
18
|
-
props.disableLog ? JSX.createElement(JSX.Fragment, null) : JSX.createElement("div", { class: `toggle-panel-button bottom-side-panel-button ${props.isPanelVisible("bottom") ? "active" : ""}`, onclick: ev => {
|
|
19
|
-
ev.preventDefault();
|
|
20
|
-
props.togglePanel("bottom");
|
|
21
|
-
} }),
|
|
22
|
-
JSX.createElement("br", null),
|
|
23
|
-
props.disablePreview ? JSX.createElement(JSX.Fragment, null) : JSX.createElement("div", { class: `toggle-panel-button right-side-panel-button ${props.isPanelVisible("right") ? "active" : ""}`, onclick: ev => {
|
|
24
|
-
ev.preventDefault();
|
|
25
|
-
props.togglePanel("right");
|
|
26
|
-
} }))),
|
|
27
|
-
JSX.createElement("br", null));
|
|
28
|
-
}
|
|
29
|
-
StartPage.asFragment = true;
|
|
30
|
-
StartPage.shadowInit = false;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { unlinkSync } from "node:fs";
|
|
2
|
-
import { getPath } from "./read.api.js";
|
|
3
|
-
export default {
|
|
4
|
-
description: "admin editor file deletion endpoint",
|
|
5
|
-
method: "POST",
|
|
6
|
-
path: "/delete",
|
|
7
|
-
middleware: [server.middleware.json()],
|
|
8
|
-
request: {
|
|
9
|
-
body: {
|
|
10
|
-
path: "string"
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
response: {
|
|
14
|
-
status: [200, 400],
|
|
15
|
-
body: {
|
|
16
|
-
message: "string"
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
handler: async (req, res) => {
|
|
20
|
-
const { path } = req.body;
|
|
21
|
-
await deleteFile(path);
|
|
22
|
-
return res?.json({
|
|
23
|
-
message: "OK"
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
function deleteFile(path) {
|
|
28
|
-
unlinkSync(getPath(path));
|
|
29
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { SUPPORTED_LANGUAGES } from "../../../../../common/constants.js";
|
|
3
|
-
import { relative, resolve } from "node:path";
|
|
4
|
-
import { getLanguage } from "./scan.api.js";
|
|
5
|
-
import { BASE_PATH } from "../../../../../common/constants.server.js";
|
|
6
|
-
export default {
|
|
7
|
-
method: "POST",
|
|
8
|
-
path: "/read",
|
|
9
|
-
description: "admin editor file read endpoint",
|
|
10
|
-
middleware: [server.middleware.json()],
|
|
11
|
-
request: {
|
|
12
|
-
body: {
|
|
13
|
-
path: "string"
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
response: {
|
|
17
|
-
status: [200, 400],
|
|
18
|
-
body: {
|
|
19
|
-
contents: "string",
|
|
20
|
-
path: "string"
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
handler: async (req, res) => {
|
|
24
|
-
const { path } = req.body;
|
|
25
|
-
const contents = readFile(path);
|
|
26
|
-
return res?.json({
|
|
27
|
-
contents,
|
|
28
|
-
path
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
export function readFile(path) {
|
|
33
|
-
const filePath = getPath(path);
|
|
34
|
-
const language = getLanguage(filePath);
|
|
35
|
-
if (SUPPORTED_LANGUAGES.includes(language)) {
|
|
36
|
-
const contents = readFileSync(filePath).toString();
|
|
37
|
-
return contents;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
throw new Error("unsupported file format");
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
export function getPath(path) {
|
|
44
|
-
const realPath = resolve(BASE_PATH, path);
|
|
45
|
-
if (relative(BASE_PATH, realPath).startsWith("..")) {
|
|
46
|
-
throw new Error("invalid path! [" + path + "]");
|
|
47
|
-
}
|
|
48
|
-
return realPath;
|
|
49
|
-
}
|