notherbase-fs 4.0.22 → 4.1.0
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 +6 -6
- package/controllers/creation.js +171 -147
- package/controllers/spirit-world.js +174 -174
- package/controllers/user.js +240 -240
- package/controllers/util.js +64 -64
- package/models/index.js +33 -33
- package/models/send-mail.js +58 -58
- package/models/spirit.js +234 -234
- package/notherbase-fs.js +114 -112
- package/package.json +40 -40
- package/public/js/base.js +222 -227
- package/public/js/chat-box.js +120 -120
- package/test/coast/tall-beach/nono-cove/index.css +17 -17
- package/test/coast/tall-beach/nono-cove/index.ejs +29 -29
- package/test/coast/tall-beach/nono-cove/nono-og/add-gold.js +15 -15
- package/test/coast/tall-beach/nono-cove/nono-og/index.ejs +46 -46
- package/test/coast/tall-beach/nono-cove/nono-og/nono.css +88 -88
- package/test/coast/tall-beach/nono-cove/nono-og/nono.js +207 -207
- package/test/pages/test-page/emailTime.js +8 -8
- package/test/pages/test-page/index.ejs +104 -104
- package/test/pages/void/index.ejs +35 -35
- package/test/pages/void/void.css +2 -2
- package/test/public/styles/main.css +792 -792
- package/test/the-front/add-gold.js +13 -13
- package/test/the-front/check/_preprocess/saved.js +9 -0
- package/test/the-front/check/check.css +2 -2
- package/test/the-front/check/emailTime.js +9 -9
- package/test/the-front/check/flip.js +9 -9
- package/test/the-front/check/index.ejs +55 -54
- package/test/the-front/check/save-input.js +7 -7
- package/test/the-front/index.ejs +116 -99
- package/test/the-front/keeper/clipboards.js +133 -133
- package/test/the-front/keeper/index.ejs +80 -80
- package/test/the-front/keeper/keeper.css +157 -157
- package/test/the-front/keeper/keeper.js +140 -140
- package/test-index.js +19 -19
- package/test2/pages/test-page/emailTime.js +8 -8
- package/test2/pages/test-page/index.ejs +104 -104
- package/test2/pages/void/index.ejs +35 -35
- package/test2/pages/void/void.css +2 -2
- package/test2/public/styles/main.css +792 -792
- package/test2/the-front/add-gold.js +13 -13
- package/test2/the-front/check/check.css +2 -2
- package/test2/the-front/check/emailTime.js +9 -9
- package/test2/the-front/check/flip.js +9 -9
- package/test2/the-front/check/index.ejs +54 -54
- package/test2/the-front/check/save-input.js +7 -7
- package/test2/the-front/index.ejs +99 -99
- package/test2/the-front/keeper/clipboards.js +133 -133
- package/test2/the-front/keeper/index.ejs +80 -80
- package/test2/the-front/keeper/keeper.css +157 -157
- package/test2/the-front/keeper/keeper.js +140 -140
- package/views/explorer.ejs +82 -82
- package/views/footer.ejs +9 -9
- package/views/head.ejs +17 -17
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# notherbase-fs
|
|
2
|
-
A package to help one develop a base.
|
|
3
|
-
|
|
4
|
-
A base is an Express.js server that will render EJS web pages with automatic route creation. It also has a spirit world, a MongoDB-connected API to provide those pages with dynamic data and multiplayer interaction. A little bit of socket.io is sprinkled for good measure.
|
|
5
|
-
|
|
6
|
-
Visit www.notherbase.com/docs for documentation on notherbase-fs.
|
|
1
|
+
# notherbase-fs
|
|
2
|
+
A package to help one develop a base.
|
|
3
|
+
|
|
4
|
+
A base is an Express.js server that will render EJS web pages with automatic route creation. It also has a spirit world, a MongoDB-connected API to provide those pages with dynamic data and multiplayer interaction. A little bit of socket.io is sprinkled for good measure.
|
|
5
|
+
|
|
6
|
+
Visit www.notherbase.com/docs for documentation on notherbase-fs.
|
package/controllers/creation.js
CHANGED
|
@@ -1,148 +1,172 @@
|
|
|
1
|
-
import express from "express";
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Creation is all the renedered pages in a base.
|
|
6
|
-
*/
|
|
7
|
-
export default class Creation {
|
|
8
|
-
constructor(bases = {}) {
|
|
9
|
-
this.bases = bases;
|
|
10
|
-
this.router = express.Router();
|
|
11
|
-
|
|
12
|
-
//home
|
|
13
|
-
this.router.get("/", this.front, this.explore);
|
|
14
|
-
|
|
15
|
-
//the-front
|
|
16
|
-
this.router.get(`/the-front`, this.front, this.explore);
|
|
17
|
-
this.router.get(`/the-front/:frontDetail`, this.frontDetail, this.explore);
|
|
18
|
-
|
|
19
|
-
//pages
|
|
20
|
-
this.router.get(`/:page`, this.page, this.explore);
|
|
21
|
-
|
|
22
|
-
//the-front optional shortcuts
|
|
23
|
-
this.router.get(`/:frontDetail`, this.frontDetail, this.explore);
|
|
24
|
-
|
|
25
|
-
//explorer
|
|
26
|
-
this.router.get(`/:region/:area/:poi`, this.lock, this.poi, this.explore);
|
|
27
|
-
this.router.get(`/:region/:area/:poi/:detail`, this.lock, this.detail, this.explore);
|
|
28
|
-
|
|
29
|
-
//void
|
|
30
|
-
this.router.use(function(req, res) {
|
|
31
|
-
res.redirect("/void");
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* This middleware requires a user to login to access affected routes.
|
|
37
|
-
* @param {Object} req An Express.js request.
|
|
38
|
-
* @param {Object} res An Express.js response.
|
|
39
|
-
* @param {Function} next next()
|
|
40
|
-
*/
|
|
41
|
-
lock = (req, res, next) => {
|
|
42
|
-
req.lock = true;
|
|
43
|
-
next();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* This route renders a page and sends it to the client.
|
|
48
|
-
* @param {Object} req An Express.js request.
|
|
49
|
-
* @param {Object} res An Express.js response.
|
|
50
|
-
* @param {Function} next next()
|
|
51
|
-
*/
|
|
52
|
-
explore = async (req, res, next) => {
|
|
53
|
-
try {
|
|
54
|
-
if (fs.existsSync(req.main + ".ejs")) {
|
|
55
|
-
let stats = await req.db.Spirit.recallOrCreateOne("stats", null, { route: req.path });
|
|
56
|
-
if (stats.memory.data.visits) stats.memory.data.visits++;
|
|
57
|
-
else stats.memory.data.visits = 1;
|
|
58
|
-
await stats.commit();
|
|
59
|
-
|
|
60
|
-
let context = {
|
|
61
|
-
userID: null,
|
|
62
|
-
user: null,
|
|
63
|
-
siteTitle: req.siteTitle,
|
|
64
|
-
main: req.main,
|
|
65
|
-
query: req.query,
|
|
66
|
-
route: req.path,
|
|
67
|
-
requireUser: req.lock
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
1
|
+
import express from "express";
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creation is all the renedered pages in a base.
|
|
6
|
+
*/
|
|
7
|
+
export default class Creation {
|
|
8
|
+
constructor(bases = {}) {
|
|
9
|
+
this.bases = bases;
|
|
10
|
+
this.router = express.Router();
|
|
11
|
+
|
|
12
|
+
//home
|
|
13
|
+
this.router.get("/", this.front, this.explore);
|
|
14
|
+
|
|
15
|
+
//the-front
|
|
16
|
+
this.router.get(`/the-front`, this.front, this.explore);
|
|
17
|
+
this.router.get(`/the-front/:frontDetail`, this.frontDetail, this.explore);
|
|
18
|
+
|
|
19
|
+
//pages
|
|
20
|
+
this.router.get(`/:page`, this.page, this.explore);
|
|
21
|
+
|
|
22
|
+
//the-front optional shortcuts
|
|
23
|
+
this.router.get(`/:frontDetail`, this.frontDetail, this.explore);
|
|
24
|
+
|
|
25
|
+
//explorer
|
|
26
|
+
this.router.get(`/:region/:area/:poi`, this.lock, this.poi, this.explore);
|
|
27
|
+
this.router.get(`/:region/:area/:poi/:detail`, this.lock, this.detail, this.explore);
|
|
28
|
+
|
|
29
|
+
//void
|
|
30
|
+
this.router.use(function(req, res) {
|
|
31
|
+
res.redirect("/void");
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* This middleware requires a user to login to access affected routes.
|
|
37
|
+
* @param {Object} req An Express.js request.
|
|
38
|
+
* @param {Object} res An Express.js response.
|
|
39
|
+
* @param {Function} next next()
|
|
40
|
+
*/
|
|
41
|
+
lock = (req, res, next) => {
|
|
42
|
+
req.lock = true;
|
|
43
|
+
next();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* This route renders a page and sends it to the client.
|
|
48
|
+
* @param {Object} req An Express.js request.
|
|
49
|
+
* @param {Object} res An Express.js response.
|
|
50
|
+
* @param {Function} next next()
|
|
51
|
+
*/
|
|
52
|
+
explore = async (req, res, next) => {
|
|
53
|
+
try {
|
|
54
|
+
if (fs.existsSync(req.main + ".ejs")) {
|
|
55
|
+
let stats = await req.db.Spirit.recallOrCreateOne("stats", null, { route: req.path });
|
|
56
|
+
if (stats.memory.data.visits) stats.memory.data.visits++;
|
|
57
|
+
else stats.memory.data.visits = 1;
|
|
58
|
+
await stats.commit();
|
|
59
|
+
|
|
60
|
+
let context = {
|
|
61
|
+
userID: null,
|
|
62
|
+
user: null,
|
|
63
|
+
siteTitle: req.siteTitle,
|
|
64
|
+
main: req.main,
|
|
65
|
+
query: req.query,
|
|
66
|
+
route: req.path,
|
|
67
|
+
requireUser: req.lock,
|
|
68
|
+
preprocessed: {}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (req.session.currentUser) {
|
|
72
|
+
context.user = await req.db.Spirit.recallOne("user", null, { username: req.session.currentUser });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
//preprocess
|
|
76
|
+
let preprocessScripts = fs.existsSync(req.preprocess) ? fs.readdirSync(req.preprocess) : [];
|
|
77
|
+
for (let preprocessScript of preprocessScripts) {
|
|
78
|
+
try {
|
|
79
|
+
let scriptPath = `${req.preprocess}/${preprocessScript}`;
|
|
80
|
+
|
|
81
|
+
if (fs.existsSync(scriptPath)) {
|
|
82
|
+
let script = await import(process.env.WINDOWS == "true" ? `file://${scriptPath}` : scriptPath);
|
|
83
|
+
let result = await script.default(req, context.user, this.io);
|
|
84
|
+
context.preprocessed[preprocessScript.split(".")[0]] = result;
|
|
85
|
+
}
|
|
86
|
+
else context.preprocessed[preprocessScript.split(".")[0]] = `Error: Script Not Found`;
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.log(error);
|
|
89
|
+
context.preprocessed[preprocessScript.split(".")[0]] = `Error: Server Error`;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
res.render(req.toRender, context);
|
|
94
|
+
}
|
|
95
|
+
else next();
|
|
96
|
+
}
|
|
97
|
+
catch(err) {
|
|
98
|
+
console.log(err);
|
|
99
|
+
res.status(500).send("Server Error");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* This middleware directs exploration to the front.
|
|
105
|
+
* @param {Object} req An Express.js request.
|
|
106
|
+
* @param {Object} res An Express.js response.
|
|
107
|
+
* @param {Function} next next()
|
|
108
|
+
*/
|
|
109
|
+
front = async (req, res, next) => {
|
|
110
|
+
req.main = req.contentPath + "/the-front/index";
|
|
111
|
+
req.preprocess = req.contentPath + "/the-front/_preprocess";
|
|
112
|
+
req.siteTitle = this.bases[req.hosting].title;
|
|
113
|
+
req.toRender = "explorer";
|
|
114
|
+
next();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* This middleware directs exploration to a detail in the front.
|
|
119
|
+
* @param {Object} req An Express.js request.
|
|
120
|
+
* @param {Object} res An Express.js response.
|
|
121
|
+
* @param {Function} next next()
|
|
122
|
+
*/
|
|
123
|
+
frontDetail = async (req, res, next) => {
|
|
124
|
+
req.main = `${req.contentPath}/the-front/${req.params.frontDetail}/index`;
|
|
125
|
+
req.preprocess = `${req.contentPath}/the-front/${req.params.frontDetail}/_preprocess`;
|
|
126
|
+
req.siteTitle = `${this.bases[req.hosting].title} - ${req.params.frontDetail}`;
|
|
127
|
+
req.toRender = "explorer";
|
|
128
|
+
next();
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* This middleware directs exploration to a point of interest.
|
|
133
|
+
* @param {Object} req An Express.js request.
|
|
134
|
+
* @param {Object} res An Express.js response.
|
|
135
|
+
* @param {Function} next next()
|
|
136
|
+
*/
|
|
137
|
+
poi = async (req, res, next) => {
|
|
138
|
+
req.main = `${req.contentPath}/${req.params.region}/${req.params.area}/${req.params.poi}/index`;
|
|
139
|
+
req.preprocess = `${req.contentPath}/${req.params.region}/${req.params.area}/${req.params.poi}/_preprocess`;
|
|
140
|
+
req.siteTitle = `${this.bases[req.hosting].title} - ${req.params.poi}`;
|
|
141
|
+
req.toRender = "explorer";
|
|
142
|
+
next();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* This middleware directs exploration to a detail.
|
|
147
|
+
* @param {Object} req An Express.js request.
|
|
148
|
+
* @param {Object} res An Express.js response.
|
|
149
|
+
* @param {Function} next next()
|
|
150
|
+
*/
|
|
151
|
+
detail = async (req, res, next) => {
|
|
152
|
+
req.main = `${req.contentPath}/${req.params.region}/${req.params.area}/${req.params.poi}/${req.params.detail}/index`;
|
|
153
|
+
req.preprocess = `${req.contentPath}/${req.params.region}/${req.params.area}/${req.params.poi}/${req.params.detail}/_preprocess`;
|
|
154
|
+
req.siteTitle = `${this.bases[req.hosting].title} - ${req.params.detail}`;
|
|
155
|
+
req.toRender = "explorer";
|
|
156
|
+
next();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* This middleware directs exploration to a one-off page.
|
|
161
|
+
* @param {Object} req An Express.js request.
|
|
162
|
+
* @param {Object} res An Express.js response.
|
|
163
|
+
* @param {Function} next next()
|
|
164
|
+
*/
|
|
165
|
+
page = async (req, res, next) => {
|
|
166
|
+
req.main = `${req.contentPath}/pages/${req.params.page}/index`;
|
|
167
|
+
req.preprocess = `${req.contentPath}/pages/${req.params.page}/_preprocess`;
|
|
168
|
+
req.siteTitle = `${req.params.page}`;
|
|
169
|
+
req.toRender = req.main;
|
|
170
|
+
next();
|
|
171
|
+
}
|
|
148
172
|
}
|