notherbase-fs 3.1.4 → 3.1.5

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.
@@ -8,13 +8,13 @@ export default class Creation {
8
8
  //home
9
9
  this.router.get("/", function(req, res) { res.redirect("/the-front"); });
10
10
  //the-front
11
- this.router.get(`/the-front`, this.explore);
12
- this.router.get(`/the-front/:frontDetail`, this.explore);
11
+ this.router.get(`/the-front`, this.front, this.explore);
12
+ this.router.get(`/the-front/:frontDetail`, this.frontDetail, this.explore);
13
13
  //pages
14
- this.router.get(`/:page`, this.page);
14
+ this.router.get(`/:page`, this.page, this.explore);
15
15
  //explorer
16
- this.router.get(`/:region/:area/:poi`, this.lock, this.explore);
17
- this.router.get(`/:region/:area/:poi/:detail`, this.lock, this.explore);
16
+ this.router.get(`/:region/:area/:poi`, this.lock, this.poi, this.explore);
17
+ this.router.get(`/:region/:area/:poi/:detail`, this.lock, this.detail, this.explore);
18
18
  //void
19
19
  this.router.use(function(req, res) {
20
20
  console.log(req.path);
@@ -28,64 +28,30 @@ export default class Creation {
28
28
  }
29
29
 
30
30
  explore = async (req, res, next) => {
31
- let main = `${req.contentPath}`;
32
- let route = "";
33
- let siteTitle = `NotherBase - `;
34
-
35
- if (req.params.frontDetail) {
36
- route = `/the-front/${req.params.frontDetail}/index`;
37
- siteTitle += req.params.frontDetail;
38
- }
39
- else if (req.params.detail) {
40
- route = `/${req.params.region}/${req.params.area}/${req.params.poi}/${req.params.detail}/index`;
41
- siteTitle += req.params.detail;
42
- }
43
- else if (req.params.poi) {
44
- route = `/${req.params.region}/${req.params.area}/${req.params.poi}/index`;
45
- siteTitle += req.params.poi;
46
- }
47
- else {
48
- route = `/the-front/index`;
49
- siteTitle += "the-front";
50
- }
51
- main += route;
52
-
53
31
  try {
54
- if (fs.existsSync(main + ".ejs")) {
55
- let user = await req.db.User.recallOne(req.session.currentUser);
56
-
32
+ if (fs.existsSync(req.main + ".ejs")) {
57
33
  let stats = await req.db.Spirit.recallOne("stats");
58
- if (stats.memory.data[route]) {
59
- stats.memory.data[route].visits++;
60
- }
61
- else {
62
- stats.memory.data[route] = {
63
- visits: 1
64
- }
65
- }
34
+ if (stats.memory.data[req.path]) stats.memory.data[req.path].visits++;
35
+ else stats.memory.data[req.path] = { visits: 1 };
66
36
  await stats.commit();
67
37
 
68
- let userStuff = {
38
+ let context = {
69
39
  userID: null,
70
40
  user: null,
71
- };
72
-
73
- if (user) userStuff = {
74
- userID: user.id,
75
- user: user.memory.data,
76
- };
77
-
78
- let context = {
79
- ...userStuff,
80
- siteTitle: siteTitle,
81
- main: main,
41
+ siteTitle: req.siteTitle,
42
+ main: req.main,
82
43
  query: req.query,
83
- // dir: req.frontDir,
84
44
  route: req.path,
85
45
  requireUser: req.lock
86
46
  }
87
47
 
88
- res.render(`explorer`, context);
48
+ let user = await req.db.User.recallOne(req.session.currentUser);
49
+ if (user) {
50
+ context.userID = user.id;
51
+ context.user = user.memory.data;
52
+ };
53
+
54
+ res.render(req.toRender, context);
89
55
  }
90
56
  else next();
91
57
  }
@@ -95,50 +61,38 @@ export default class Creation {
95
61
  }
96
62
  }
97
63
 
98
- page = async (req, res, next) => {
99
- let main = `${req.contentPath}`;
100
-
101
- main += `/pages/${req.params.page}/index.ejs`;
102
-
103
- try {
104
- if (fs.existsSync(main)) {
105
- let user = await req.db.User.recallOne(req.session.currentUser);
106
-
107
- let stats = await req.db.Spirit.recallOne("stats");
108
- if (stats.memory.data[main]) {
109
- stats.memory.data[main].visits++;
110
- }
111
- else {
112
- stats.memory.data[main] = {
113
- visits: 1
114
- }
115
- }
116
- await stats.commit();
64
+ front = async (req, res, next) => {
65
+ req.main = req.contentPath + "/the-front/index";
66
+ req.siteTitle = "NotherBase - The Front";
67
+ req.toRender = "explorer";
68
+ next();
69
+ }
117
70
 
118
- let userStuff = {
119
- userID: null,
120
- user: null
121
- };
71
+ frontDetail = async (req, res, next) => {
72
+ req.main = `${req.contentPath}/the-front/${req.params.frontDetail}/index`;
73
+ req.siteTitle = `NotherBase - ${req.params.frontDetail}`;
74
+ req.toRender = "explorer";
75
+ next();
76
+ }
122
77
 
123
- if (user) userStuff = {
124
- userID: user.id,
125
- user: user.memory.data
126
- };
78
+ poi = async (req, res, next) => {
79
+ req.main = `${req.contentPath}/${req.params.region}/${req.params.area}/${req.params.poi}/index`;
80
+ req.siteTitle = `NotherBase - ${req.params.poi}`;
81
+ req.toRender = "explorer";
82
+ next();
83
+ }
127
84
 
128
- let context = {
129
- ...userStuff,
130
- query: req.query,
131
- dir: req.frontDir,
132
- route: req.path
133
- }
85
+ detail = async (req, res, next) => {
86
+ req.main = `${req.contentPath}/${req.params.region}/${req.params.area}/${req.params.poi}/${req.params.detail}/index`;
87
+ req.siteTitle = `NotherBase - ${req.params.detail}`;
88
+ req.toRender = "explorer";
89
+ next();
90
+ }
134
91
 
135
- res.render(main, context);
136
- }
137
- else next();
138
- }
139
- catch(err) {
140
- console.log(err);
141
- res.status(500).end();
142
- }
92
+ page = async (req, res, next) => {
93
+ req.main = `${req.contentPath}/pages/${req.params.page}/index`;
94
+ req.siteTitle = `${req.params.page}`;
95
+ req.toRender = req.main;
96
+ next();
143
97
  }
144
98
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notherbase-fs",
3
- "version": "3.1.4",
3
+ "version": "3.1.5",
4
4
  "description": "Functions to help make developing for NotherBase easier.",
5
5
  "exports": "./notherbase-fs.js",
6
6
  "scripts": {
@@ -24,8 +24,6 @@
24
24
 
25
25
  <script>
26
26
  const currentRoute = "<%- route %>";
27
-
28
- <%- include("../../../views/scripts/base.js", {user: user}); %>
29
27
  </script>
30
28
 
31
29