mdkcontroller 1.0.0 → 1.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.
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
4
+ </project>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="UserContentModel">
4
+ <attachedFolders />
5
+ <explicitIncludes />
6
+ <explicitExcludes />
7
+ </component>
8
+ </project>
@@ -0,0 +1,7 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="SqlDialectInspection" enabled="false" level="WARNING" enabled_by_default="false" />
5
+ <inspection_tool class="SqlNoDataSourceInspection" enabled="false" level="WARNING" enabled_by_default="false" />
6
+ </profile>
7
+ </component>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="RiderProjectSettingsUpdater">
4
+ <option name="vcsConfiguration" value="2" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,68 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="AutoImportSettings">
4
+ <option name="autoReloadType" value="SELECTIVE" />
5
+ </component>
6
+ <component name="ChangeListManager">
7
+ <list default="true" id="93fcfe43-d602-4459-872f-00e0cab9f2cf" name="Changes" comment="" />
8
+ <option name="SHOW_DIALOG" value="false" />
9
+ <option name="HIGHLIGHT_CONFLICTS" value="true" />
10
+ <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
11
+ <option name="LAST_RESOLUTION" value="IGNORE" />
12
+ </component>
13
+ <component name="FileTemplateManagerImpl">
14
+ <option name="RECENT_TEMPLATES">
15
+ <list>
16
+ <option value="JavaScript File" />
17
+ </list>
18
+ </option>
19
+ </component>
20
+ <component name="ProjectColorInfo"><![CDATA[{
21
+ "associatedIndex": 1
22
+ }]]></component>
23
+ <component name="ProjectId" id="2go12MYEeCSEk12LscCLJzrOL3w" />
24
+ <component name="ProjectViewState">
25
+ <option name="hideEmptyMiddlePackages" value="true" />
26
+ <option name="showLibraryContents" value="true" />
27
+ </component>
28
+ <component name="PropertiesComponent"><![CDATA[{
29
+ "keyToString": {
30
+ "Node.js.app.js.executor": "Debug",
31
+ "RunOnceActivity.ShowReadmeOnStart": "true",
32
+ "node.js.detected.package.eslint": "true",
33
+ "node.js.detected.package.stylelint": "true",
34
+ "node.js.detected.package.tslint": "true",
35
+ "node.js.selected.package.eslint": "(autodetect)",
36
+ "node.js.selected.package.stylelint": "",
37
+ "node.js.selected.package.tslint": "(autodetect)",
38
+ "nodejs_package_manager_path": "npm",
39
+ "rider.code.cleanup.on.save": "true",
40
+ "rider.code.cleanup.on.save.profile": "Built-in: Reformat Code",
41
+ "settings.editor.selected.configurable": "actions.on.save"
42
+ },
43
+ "keyToStringList": {
44
+ "rider.external.source.directories": [
45
+ "C:\\Users\\KHANHNBD\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\DecompilerCache",
46
+ "C:\\Users\\KHANHNBD\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\SourcesCache",
47
+ "C:\\Users\\KHANHNBD\\AppData\\Local\\Symbols\\src"
48
+ ]
49
+ }
50
+ }]]></component>
51
+ <component name="RunManager">
52
+ <configuration name="app.js" type="NodeJSConfigurationType" temporary="true" nameIsGenerated="true" path-to-js-file="$PROJECT_DIR$/app.js" working-dir="$PROJECT_DIR$">
53
+ <method v="2" />
54
+ </configuration>
55
+ <recent_temporary>
56
+ <list>
57
+ <item itemvalue="Node.js.app.js" />
58
+ </list>
59
+ </recent_temporary>
60
+ </component>
61
+ <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
62
+ <component name="TypeScriptGeneratedFilesManager">
63
+ <option name="version" value="3" />
64
+ </component>
65
+ <component name="VcsManagerConfiguration">
66
+ <option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
67
+ </component>
68
+ </project>
package/app.js CHANGED
@@ -1,105 +1,4 @@
1
- import express, { Router, static as staticExpress } from "express";
2
- import { createServer } from "http";
3
- import pkg_body_parser from 'body-parser';
4
- const { json } = pkg_body_parser;
5
- import { join } from "path";
6
- import cookieParser from "cookie-parser";
7
- import path from 'path';
8
- import { fileURLToPath } from 'url';
1
+ import svInstance from "./main.js";
9
2
 
10
- import dbInstant from "./dk_modules/dkdb.js";
11
- import userInstant from "./dk_modules/users.js";
12
- import authInstant from "./dk_modules/authorization.js";
13
- import projectDBInstant from "./projectDB.js";
14
- import { privateKey, encodeMini } from "./dk_modules/dkvar.js";
15
-
16
- const __filename = fileURLToPath(import.meta.url);
17
- const __dirname = path.dirname(__filename);
18
-
19
- const app = express();
20
- const server = createServer(app);
21
- const db = await dbInstant("begindb.json");
22
- const projectDb = projectDBInstant(db);
23
- const auth = authInstant(projectDb);
24
-
25
- const userRoutes = userInstant(Router(), projectDb);
26
-
27
- app.use(json());
28
- app.use(cookieParser());
29
-
30
- app.use((req, res, next) => {
31
- res.setHeader('Cache-Control', 'no-store');
32
- if (req.url == "/") res.redirect("/pages");
33
- next();
34
- });
35
-
36
- app.use((req, res, next) => {
37
- const resultValidate = auth.validateBool(req, res, next);
38
- switch (resultValidate) {
39
- case 1:
40
- if (req.path.toLowerCase().indexOf("/cores/login/") >= 0) {
41
- res.redirect("/pages");
42
- return;
43
- }
44
- if (req.path.toLowerCase() == ("/pages/gameplay/")) {
45
- const boardid = req.query.boardid;
46
- const boardtoken = req.cookies?.boardtoken;
47
- const listBoard = apiGame.controller.listBoard;
48
- const boardItem = listBoard.find(f => f.boardId == boardid);
49
- let player = {};
50
- if (boardItem) {
51
- player = boardItem.player.find(f => f.userid == req.user.id);
52
- }
53
- if (!boardItem || !player) {
54
- res.redirect("/pages");
55
- return;
56
- }
57
- const currentKey = encodeMini(req.user.id + "_" + boardItem.privateCode, privateKey);
58
- if (boardtoken != currentKey) {
59
- res.redirect("/pages");
60
- return;
61
- }
62
- }
63
- break;
64
- default:
65
- if (req.path.toLowerCase().indexOf("/pages/") >= 0) {
66
- res.redirect("/Cores/Login");
67
- return;
68
- }
69
- break;
70
- }
71
- if (validateFile(req) == false) {
72
- res.send('<h2 style="color:red;">Can not access to this file<h2/>');
73
- return;
74
- }
75
-
76
- next();
77
- });
78
- const endToCatch = [];
79
- function validateFile(req) {
80
- let allow = true;
81
- for (let index = 0; index < endToCatch.length; index++) {
82
- const element = endToCatch[index];
83
- if (req.url.toLowerCase().endsWith(element)) {
84
- allow = false;
85
- }
86
- }
87
- return allow;
88
- }
89
-
90
- app.use("/Pages", staticExpress(join(__dirname, "Pages")));
91
- app.use("/Cores", staticExpress(join(__dirname, "Cores")));
92
- app.use("/api", userRoutes.router);
93
-
94
- // phải định nghĩa GET, POST trước use.
95
- // chatInstant(server, userRoutes.table);
96
-
97
- const kport = 2030;
98
- server.listen(kport, () => {
99
- console.log(
100
- `Server is listening on port ${kport}: http://localhost:${kport}/pages/`
101
- );
102
- console.log(
103
- `Server is listening on port ${kport}: http://localhost:${kport}/pages/demo/`
104
- );
105
- });
3
+ const _sv = await svInstance("khanhnbd");
4
+ _sv.startListen(8905);
package/begindb.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "users": [
3
+ {
4
+ "id": 1,
5
+ "userName": "khanhnbd",
6
+ "email": "khanh272421@gmail.com",
7
+ "password": "123",
8
+ "active": true,
9
+ "amount": 0
10
+ }
11
+ ],
12
+ "loginTokens": [
13
+ {
14
+ "id": 1,
15
+ "userId": 1,
16
+ "tokenString": "a2VoeWFKbnpoZG5XYklkaUZPcmlxSVc1QU4wem5jQTR0SU9pUXdjaVRiQm11Rll0bFpFU2ZJSTZ3SUxrOVJtckdhT0c3RmR1RGFvRWsxM040VE9TRElYc2hJVG01bDloMGQ3Q2RJZTZRTzlEUGtSeEhNUUR1Qk45d2dZaHNScXYxZUJwQXdUQXVTSGlyZDd3eDUwQWlQNEJrNmlYMTJKaU5qcHVKbWJl",
17
+ "expired": "2024-06-22T03:37:40.329Z"
18
+ }
19
+ ],
20
+ "autoSequenceNumber": [
21
+ {
22
+ "name": "users",
23
+ "currentNumber": 1
24
+ },
25
+ {
26
+ "name": "loginTokens",
27
+ "currentNumber": 1
28
+ }
29
+ ],
30
+ "videoAccess": []
31
+ }
@@ -0,0 +1,30 @@
1
+ {
2
+ "users": [
3
+ {
4
+ "id": 1,
5
+ "userName": "khanhnbd",
6
+ "email": "khanh272421@gmail.com",
7
+ "password": "123",
8
+ "active": true,
9
+ "amount": 0
10
+ }
11
+ ],
12
+ "loginTokens": [
13
+ {
14
+ "id": 1,
15
+ "userId": 1,
16
+ "tokenString": "a2VoeWFKbnpoZG5XYklkaUhPNmlqSXE1Qk5CekZjOTQ4SWRpZXczaVBidm1WRkR0b1puU1FJWTZjSWxrWFI3cmpheUdBRmt1UGE0RWExUE5XVDNTOUk1c3BJOG04bGloM2Q2Q3BJQzZUT1dEa2tmeDhNY0RyQkQ5Y3VuUDdScFlvTUp5a1p5aTlSRU9KdExJVnVsMkVZSUFteEY2eHZ3YlBySG96NVVM",
17
+ "expired": "2024-06-22T04:31:46.075Z"
18
+ }
19
+ ],
20
+ "autoSequenceNumber": [
21
+ {
22
+ "name": "users",
23
+ "currentNumber": 1
24
+ },
25
+ {
26
+ "name": "loginTokens",
27
+ "currentNumber": 1
28
+ }
29
+ ]
30
+ }
package/main.js ADDED
@@ -0,0 +1,70 @@
1
+ import express, {Router, static as staticExpress} from "express";
2
+ import {createServer} from "http";
3
+ import pkg_body_parser from 'body-parser';
4
+
5
+ const {json} = pkg_body_parser;
6
+ import {join} from "path";
7
+ import cookieParser from "cookie-parser";
8
+ import path from 'path';
9
+ import {fileURLToPath} from 'url';
10
+
11
+ import dbInstant from "./dk_modules/dkdb.js";
12
+ import userInstant from "./dk_modules/users.js";
13
+ import authInstant from "./dk_modules/authorization.js";
14
+ // import {privateKey, encodeMini} from "./dk_modules/dkvar.js";
15
+
16
+ export default async function (appname) {
17
+ const __filename = fileURLToPath(import.meta.url);
18
+ const __dirname = path.dirname(__filename);
19
+
20
+ const app = express();
21
+ const server = createServer(app);
22
+ const db = await dbInstant(appname + "-Database.json");
23
+ const auth = authInstant(db);
24
+
25
+ const userRoutes = userInstant(Router(), db);
26
+
27
+ app.use(json());
28
+ app.use(cookieParser());
29
+
30
+ app.use((req, res, next) => {
31
+ res.setHeader('Cache-Control', 'no-store');
32
+ if (req.url === "/") res.redirect("/pages");
33
+ next();
34
+ });
35
+
36
+ app.use((req, res, next) => {
37
+ const resultValidate = auth.validateBool(req, res, next);
38
+ switch (resultValidate) {
39
+ case 1:
40
+ if (req.path.toLowerCase().indexOf("/cores/login/") >= 0) {
41
+ res.redirect("/pages");
42
+ return;
43
+ }
44
+ break;
45
+ default:
46
+ if (req.path.toLowerCase().indexOf("/pages/") >= 0) {
47
+ res.redirect("/Cores/Login");
48
+ return;
49
+ }
50
+ break;
51
+ }
52
+ next();
53
+ });
54
+
55
+ app.use("/Pages", staticExpress(join(__dirname, "Pages")));
56
+ app.use("/Cores", staticExpress(join(__dirname, "Cores")));
57
+ app.use("/api", userRoutes.router);
58
+ return {
59
+ server: app,
60
+ database: db,
61
+ authen: auth,
62
+ startListen: function (kport = 8095) {
63
+ server.listen(kport, () => {
64
+ console.log(
65
+ `Server is listening on port ${kport}: http://localhost:${kport}/pages/`
66
+ );
67
+ });
68
+ }
69
+ }
70
+ }
package/package.json CHANGED
@@ -5,10 +5,11 @@
5
5
  "fluent-ffmpeg": "^2.1.2",
6
6
  "handlebars": "^4.7.8",
7
7
  "lowdb": "^7.0.1",
8
+ "mdkcontroller": "^1.0.0",
8
9
  "socket.io": "^4.7.2"
9
10
  },
10
11
  "name": "mdkcontroller",
11
- "version": "1.0.0",
12
+ "version": "1.0.1",
12
13
  "keywords": [],
13
14
  "author": "",
14
15
  "license": "ISC",