mdkcontroller 1.0.0 → 1.0.2

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/app.js CHANGED
@@ -1,105 +1,3 @@
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
+ 'use strict';
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
+ module.exports = require('main.js');
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,13 +5,20 @@
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.2",
12
13
  "keywords": [],
13
14
  "author": "",
14
15
  "license": "ISC",
15
16
  "description": "",
16
- "type": "module"
17
+ "type": "module",
18
+ "files": [
19
+ "app.js",
20
+ "main.js",
21
+ "Cores/",
22
+ "dk_modules/"
23
+ ]
17
24
  }
package/projectDB.js DELETED
@@ -1,5 +0,0 @@
1
- export default function (db) {
2
- console.log("Module projectDB.js: (db)=> init table for project");
3
- db.data.videoAccess = db.data.videoAccess || [];
4
- return db;
5
- };
package/projectVar.js DELETED
@@ -1,3 +0,0 @@
1
- //C:\Users\KHANHNBD\Desktop\WWW\ShareFiles\Temp
2
- // export const apivideoPath = "C:\\Users\\khanh\\Desktop\\WWW\\ShareFiles\\Temp";
3
- export const demo = "";