miqro 6.3.0 → 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 +1 -1
- package/build/esm/src/common/arguments.js +28 -14
- 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 +0 -1
- 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 +1 -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 +1 -1
- package/build/esm/src/services/app.js +3 -4
- 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 +15684 -15612
- 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 -745
- 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 -61
- 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 -88
- 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 -101
- package/src/services/app.ts +0 -699
- 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
package/editor/auth.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { AuthConfig, ServerRequest } from "../src/types.js";
|
|
2
|
-
import { AdminRequest } from "./common/admin-interface.js";
|
|
3
|
-
|
|
4
|
-
export const ADMIN_EDITOR_AUTH_KEY = "$$ADMIN_EDITOR_AUTH_KEY$$";
|
|
5
|
-
|
|
6
|
-
export const ADMIN_EDITOR_AUTH_QUERY = "key";
|
|
7
|
-
export const ADMIN_EDITOR_AUTH_COOKIE = ADMIN_EDITOR_AUTH_KEY;
|
|
8
|
-
|
|
9
|
-
export default {
|
|
10
|
-
authService: {
|
|
11
|
-
verify: async (args) => {
|
|
12
|
-
|
|
13
|
-
const adminInterface = (args.req as AdminRequest).editor;
|
|
14
|
-
const serverInterface = (args.req as any as ServerRequest).server;
|
|
15
|
-
const KEY = (adminInterface ? adminInterface.getCache() : serverInterface.cache).get<string>(ADMIN_EDITOR_AUTH_KEY);
|
|
16
|
-
|
|
17
|
-
const validSesson = {
|
|
18
|
-
username: "username",
|
|
19
|
-
account: "account",
|
|
20
|
-
groups: [],
|
|
21
|
-
token: args.token
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const queryToken = args.req.query[ADMIN_EDITOR_AUTH_QUERY];
|
|
25
|
-
const cookieToken = args.req.cookies[ADMIN_EDITOR_AUTH_COOKIE];
|
|
26
|
-
|
|
27
|
-
//console.log("\n\nqueryToken[%s] cookieToken[%s] KEY[%s]\n\n", queryToken, cookieToken, KEY);
|
|
28
|
-
|
|
29
|
-
if (queryToken) {
|
|
30
|
-
if (queryToken === KEY) {
|
|
31
|
-
args.res.setCookie(ADMIN_EDITOR_AUTH_COOKIE, KEY, {
|
|
32
|
-
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 31 * 12 * 500),
|
|
33
|
-
httpOnly: true,
|
|
34
|
-
|
|
35
|
-
//secure: true,
|
|
36
|
-
path: "/",
|
|
37
|
-
//sameSite: "strict"
|
|
38
|
-
});
|
|
39
|
-
args.req.searchParams.delete(ADMIN_EDITOR_AUTH_QUERY);
|
|
40
|
-
const queryString = args.req.searchParams.toString();
|
|
41
|
-
const redirect = args.req.path + (queryString ? "?" + queryString : "");
|
|
42
|
-
await args.res.redirect(redirect);
|
|
43
|
-
return validSesson;
|
|
44
|
-
}
|
|
45
|
-
} else if (cookieToken) {
|
|
46
|
-
return cookieToken === KEY ? validSesson : null;
|
|
47
|
-
}
|
|
48
|
-
return null;
|
|
49
|
-
},
|
|
50
|
-
}
|
|
51
|
-
} as AuthConfig;
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { RouterHandlerOptions } from "@miqro/core";
|
|
2
|
-
import { CacheInterface, ServerRequest } from "../../src/types.js";
|
|
3
|
-
import { MigrationModule } from "../../src/inflate/setup-db.js";
|
|
4
|
-
|
|
5
|
-
export interface EditorAdminInterface {
|
|
6
|
-
getCache: () => CacheInterface;
|
|
7
|
-
//inflateJSX: (path: string, minify?: boolean) => Promise<string>;
|
|
8
|
-
getMigrations(): MigrationModule[];
|
|
9
|
-
stop: () => Promise<void>;
|
|
10
|
-
reload: () => Promise<null | {
|
|
11
|
-
filePath: string;
|
|
12
|
-
error: Error;
|
|
13
|
-
}[]>;
|
|
14
|
-
restart: () => Promise<null | {
|
|
15
|
-
filePath: string;
|
|
16
|
-
error: Error;
|
|
17
|
-
}[]>;
|
|
18
|
-
getHotReloadHTML(): string;
|
|
19
|
-
getInflateErrors(): null | {
|
|
20
|
-
filePath: string;
|
|
21
|
-
error: Error;
|
|
22
|
-
}[];
|
|
23
|
-
getServices(): string[];
|
|
24
|
-
getRouteFileMap(): {
|
|
25
|
-
[filePath: string]: {
|
|
26
|
-
routes: {
|
|
27
|
-
path?: string;
|
|
28
|
-
method?: string | null;
|
|
29
|
-
options?: RouterHandlerOptions;
|
|
30
|
-
inflatePath?: string;
|
|
31
|
-
}[];
|
|
32
|
-
previewMethod: "api" | "html" | null;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface AdminRequest extends ServerRequest {
|
|
38
|
-
editor?: EditorAdminInterface;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/*let currentAdminInterface: EditorAdminInterface | null = null;
|
|
42
|
-
function createFakeAdminInterface(server: any): EditorAdminInterface {
|
|
43
|
-
return {
|
|
44
|
-
getCache: () => {
|
|
45
|
-
return server.cache;
|
|
46
|
-
},
|
|
47
|
-
stop: async () => {
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
restart: async () => {
|
|
51
|
-
return null;
|
|
52
|
-
},
|
|
53
|
-
reload: async () => {
|
|
54
|
-
return null;
|
|
55
|
-
},
|
|
56
|
-
getHotReloadHTML: () => {
|
|
57
|
-
return "";
|
|
58
|
-
},
|
|
59
|
-
getMigrations: () => {
|
|
60
|
-
return [];
|
|
61
|
-
},
|
|
62
|
-
getServices: () => {
|
|
63
|
-
return ["."];
|
|
64
|
-
},
|
|
65
|
-
getRouteFileMap: () => {
|
|
66
|
-
return {};
|
|
67
|
-
},
|
|
68
|
-
getInflateErrors: () => {
|
|
69
|
-
return [];
|
|
70
|
-
},
|
|
71
|
-
inflateJSX: async function inflateJSX(path, minify: boolean = true) {
|
|
72
|
-
return "";
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function getEditorAdmin(server): EditorAdminInterface {
|
|
78
|
-
return currentAdminInterface ? currentAdminInterface : createFakeAdminInterface(server);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function setEditorAdmin(admin: EditorAdminInterface): void {
|
|
82
|
-
currentAdminInterface = admin;
|
|
83
|
-
}*/
|
|
84
|
-
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export const BASEEDITOR_PATH = "/admin/editor";
|
|
2
|
-
export const LOG_SOCKET_PATH = "/admin/socket";
|
|
3
|
-
export const LOG_WRITE_EVENT = "LogWrite";
|
|
4
|
-
|
|
5
|
-
export const SUPPORTED_LANGUAGES = [
|
|
6
|
-
"text",
|
|
7
|
-
"json",
|
|
8
|
-
"javascript",
|
|
9
|
-
"typescript",
|
|
10
|
-
"dockerfile",
|
|
11
|
-
"yaml",
|
|
12
|
-
"xml",
|
|
13
|
-
"html",
|
|
14
|
-
"css",
|
|
15
|
-
"scss",
|
|
16
|
-
"markdown",
|
|
17
|
-
"c",
|
|
18
|
-
"cpp",
|
|
19
|
-
"bash",
|
|
20
|
-
"python"
|
|
21
|
-
];
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { scanDir } from "../http/admin/editor/api/fs/scan.api.js";
|
|
2
|
-
import { parseInflateErrors } from "../http/admin/editor/api/server/restart.api.js";
|
|
3
|
-
import { AdminRequest } from "./admin-interface.js";
|
|
4
|
-
import { HTMLEncode } from "./html-encode.js";
|
|
5
|
-
|
|
6
|
-
export function EditorIndex(editorCSS: string, editorJS: string, enableHotReload: boolean) {
|
|
7
|
-
return async function editorIndex(req: AdminRequest, res) {
|
|
8
|
-
const admin = req.editor;
|
|
9
|
-
|
|
10
|
-
const errors = parseInflateErrors(admin ? admin.getInflateErrors() : []);
|
|
11
|
-
const files = scanDir(req);
|
|
12
|
-
const migrations = admin ? admin.getMigrations().map(m => m.name) : [];
|
|
13
|
-
const services = admin ? admin.getServices() : ["."];
|
|
14
|
-
const hotReload = enableHotReload ? (admin ? admin.getHotReloadHTML() : "") : "";
|
|
15
|
-
res.html(`<!DOCTYPE html><html><body><style>${editorCSS}</style><script type="module">${editorJS}</script><editor-component class="main-container" reloadstring="${req.uuid}" migrations="${HTMLEncode(JSON.stringify(migrations))}" services="${HTMLEncode(JSON.stringify(services))}" errors="${HTMLEncode(JSON.stringify(errors))}" files="${HTMLEncode(JSON.stringify(files))}"><noscript>Enable JavaScript</noscript></editor-component>${hotReload}</body></html>`)
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export function HTMLEncode(str: string): string {
|
|
2
|
-
let i = str.length;
|
|
3
|
-
const aRet: string[] = [];
|
|
4
|
-
|
|
5
|
-
while (i--) {
|
|
6
|
-
const iC = str[i].charCodeAt(0);
|
|
7
|
-
if (iC < 65 || iC > 127 || (iC > 90 && iC < 97)) {
|
|
8
|
-
aRet[i] = '&#' + iC + ';';
|
|
9
|
-
} else {
|
|
10
|
-
aRet[i] = str[i];
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return aRet.join('');
|
|
14
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
interface LogLine { out: string; identifier: string; level: "error" | "warn" | "debug" | "trace" | "info" }
|
|
2
|
-
|
|
3
|
-
export interface LogSocket {
|
|
4
|
-
lines: LogLine[];
|
|
5
|
-
clearLog: () => void;
|
|
6
|
-
getMaxlogsize: () => number | "unlimited";
|
|
7
|
-
setMaxLogSize: (val: number | "unlimited") => void;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function useLogSocket(options: { disableLog?: boolean; }): LogSocket {
|
|
11
|
-
|
|
12
|
-
const [_, setmaxLogSize, getMaxlogsize] = jsx.useState<number | "unlimited">(1000000);
|
|
13
|
-
|
|
14
|
-
const [__, setlines, getLines] = jsx.useState<LogLine[]>([]);
|
|
15
|
-
const refresh = jsx.useRefresh();
|
|
16
|
-
|
|
17
|
-
jsx.useEffect(() => {
|
|
18
|
-
|
|
19
|
-
let timeout;
|
|
20
|
-
|
|
21
|
-
function setupSocket() {
|
|
22
|
-
try {
|
|
23
|
-
if (options.disableLog) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
console.log("setting up log socket");
|
|
27
|
-
const socket = new WebSocket("/admin/socket");
|
|
28
|
-
socket.addEventListener("error", (err) => {
|
|
29
|
-
console.error(err);
|
|
30
|
-
clearTimeout(timeout);
|
|
31
|
-
timeout = setTimeout(() => {
|
|
32
|
-
setupSocket();
|
|
33
|
-
}, 1000);
|
|
34
|
-
});
|
|
35
|
-
socket.addEventListener("open", () => {
|
|
36
|
-
console.log("log socket open");
|
|
37
|
-
clearTimeout(timeout);
|
|
38
|
-
socket.addEventListener("message", (msg) => {
|
|
39
|
-
const lines = getLines();
|
|
40
|
-
const data = JSON.parse(msg.data);
|
|
41
|
-
//console.log(data.out);
|
|
42
|
-
const maxLogSize = getMaxlogsize();
|
|
43
|
-
if (maxLogSize !== "unlimited" && lines.length >= maxLogSize) {
|
|
44
|
-
lines.splice(0, (lines.length - maxLogSize) + 1);
|
|
45
|
-
}
|
|
46
|
-
lines.push(data);
|
|
47
|
-
setlines(lines);
|
|
48
|
-
refresh();
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
socket.addEventListener("close", () => {
|
|
52
|
-
console.log("log socket close");
|
|
53
|
-
clearTimeout(timeout);
|
|
54
|
-
timeout = setTimeout(() => {
|
|
55
|
-
setupSocket();
|
|
56
|
-
}, 1000);
|
|
57
|
-
});
|
|
58
|
-
} catch (e) {
|
|
59
|
-
console.error(e);
|
|
60
|
-
clearTimeout(timeout);
|
|
61
|
-
timeout = setTimeout(() => {
|
|
62
|
-
setupSocket();
|
|
63
|
-
}, 1000);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
setupSocket();
|
|
68
|
-
}, []);
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
lines: getLines(),
|
|
72
|
-
clearLog: () => {
|
|
73
|
-
setlines([]);
|
|
74
|
-
},
|
|
75
|
-
getMaxlogsize,
|
|
76
|
-
setMaxLogSize: (newValue: number | "unlimited") => {
|
|
77
|
-
if (newValue === "unlimited") {
|
|
78
|
-
setmaxLogSize(newValue);
|
|
79
|
-
} else {
|
|
80
|
-
setmaxLogSize(newValue);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|