notherbase-fs 1.3.1 → 1.3.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.
@@ -1,9 +1,10 @@
1
+ const db = require("../models");
2
+ const path = require('path');
3
+ const fs = require("fs");
4
+
5
+ let router = require("express").Router();
6
+
1
7
  const explorer = async function explorer(worldPath, voidPath) {
2
- const db = require("../models");
3
- const path = require('path');
4
-
5
- let router = require("express").Router();
6
-
7
8
  router.post(`/:region/:area/:poi/:detail/serve/:script`, async function(req, res) {
8
9
  try {
9
10
  let currentAreaRoute = `${req.params.region}/${req.params.area}/${req.params.poi}`;
@@ -43,19 +44,30 @@ const explorer = async function explorer(worldPath, voidPath) {
43
44
  const foundInventory = await db.inventory.findOne({ user: req.session.currentUser }).populate("items.item");
44
45
 
45
46
  let main = `${worldPath}/${req.params.region}/${req.params.area}/${req.params.poi}/views/${req.params.detail}`;
46
-
47
- let context = {
48
- siteTitle: `NotherBase - ${req.params.detail}`,
49
- user: foundUser,
50
- main: main,
51
- pov: req.query.pov,
52
- inventory: foundInventory,
53
- query: req.query,
54
- dir: worldPath,
55
- path: path
47
+
48
+ if (fs.existsSync(main + ".js")) {
49
+ let context = {
50
+ siteTitle: `NotherBase - ${req.params.detail}`,
51
+ user: foundUser,
52
+ main: main,
53
+ pov: req.query.pov,
54
+ inventory: foundInventory,
55
+ query: req.query,
56
+ dir: worldPath,
57
+ path: path
58
+ }
59
+
60
+ await res.render(`explorer`, context);
61
+ }
62
+ else {
63
+ res.render(`explorer`,
64
+ {
65
+ siteTitle: "NotherBase | The Void",
66
+ user: null,
67
+ inventory: null,
68
+ main: `${voidPath}/index`
69
+ });
56
70
  }
57
-
58
- await res.render(`explorer`, context);
59
71
  }
60
72
  catch(err) {
61
73
  console.log(err);
@@ -70,18 +82,29 @@ const explorer = async function explorer(worldPath, voidPath) {
70
82
 
71
83
  let main = `${worldPath}/${req.params.region}/${req.params.area}/${req.params.poi}/views/index`;
72
84
 
73
- let context = {
74
- siteTitle: `NotherBase - ${req.params.poi}`,
75
- user: foundUser,
76
- main: main,
77
- pov: req.query.pov,
78
- inventory: foundInventory,
79
- query: req.query,
80
- dir: worldPath,
81
- path: path
85
+ if (fs.existsSync(main + ".js")) {
86
+ let context = {
87
+ siteTitle: `NotherBase - ${req.params.poi}`,
88
+ user: foundUser,
89
+ main: main,
90
+ pov: req.query.pov,
91
+ inventory: foundInventory,
92
+ query: req.query,
93
+ dir: worldPath,
94
+ path: path
95
+ }
96
+
97
+ await res.render(`explorer`, context);
98
+ }
99
+ else {
100
+ res.render(`explorer`,
101
+ {
102
+ siteTitle: "NotherBase | The Void",
103
+ user: null,
104
+ inventory: null,
105
+ main: `${voidPath}/index`
106
+ });
82
107
  }
83
-
84
- await res.render(`explorer`, context);
85
108
  }
86
109
  catch(err) {
87
110
  console.log(err);
@@ -101,9 +124,7 @@ const explorer = async function explorer(worldPath, voidPath) {
101
124
  siteTitle: "NotherBase | The Void",
102
125
  user: null,
103
126
  inventory: null,
104
- main: `${voidPath}/index`,
105
- dir: dir,
106
- path: path
127
+ main: `${voidPath}/index`
107
128
  });
108
129
  });
109
130
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notherbase-fs",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Functions to help make developing for NotherBase easier.",
5
5
  "main": "notherbase-fs.js",
6
6
  "scripts": {