notherbase-fs 1.3.14 → 1.4.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.
@@ -38,24 +38,43 @@ const explorer = async function explorer(worldPath, voidPath) {
38
38
  }
39
39
  });
40
40
 
41
- router.get(`/:region/:area/:poi/:detail/load`, async function(req, res) {
41
+ router.get(`/recall`, async function(req, res) {
42
42
  try {
43
- let currentRoute = `${req.params.region}/${req.params.area}/${req.params.poi}/${req.params.detail}`;
43
+ let exists = await db.detail.exists({
44
+ route: req.query.route,
45
+ service: req.query.service,
46
+ scope: "local",
47
+ user: req.session.currentUser
48
+ });
44
49
 
45
- let exists = await db.poi.exists({ route: currentRoute, user: req.session.currentUser });
46
50
  if (!exists) {
47
- await db.poi.create({
48
- route: currentRoute,
49
- name: req.params.detail,
50
- type: "user",
51
+ await db.detail.create({
52
+ _lastUpdate: Date.now(),
53
+ route: req.query.route,
54
+ service: req.query.service,
55
+ scope: "local",
51
56
  user: req.session.currentUser,
52
57
  data: {}
53
58
  });
54
59
  }
55
60
 
56
- let found = await db.poi.findOne({ route: currentRoute, user: req.session.currentUser });
57
-
58
- res.send(found.data);
61
+ let found = await db.detail.findOne({
62
+ route: req.query.route,
63
+ service: req.query.service,
64
+ scope: "local",
65
+ user: req.session.currentUser
66
+ });
67
+
68
+ if (new Date(found._lastUpdate) > new Date(req.query._lastUpdate)) {
69
+ res.send({
70
+ isUpToDate: false,
71
+ data: found.data
72
+ });
73
+ }
74
+ else res.send({
75
+ isUpToDate: true,
76
+ data: null
77
+ });
59
78
  }
60
79
  catch(err) {
61
80
  console.log(err);
@@ -63,21 +82,25 @@ const explorer = async function explorer(worldPath, voidPath) {
63
82
  }
64
83
  });
65
84
 
66
- router.post(`/:region/:area/:poi/:detail/save`, async function(req, res) {
85
+ router.post(`/commit`, async function(req, res) {
67
86
  try {
68
- let currentRoute = `${req.params.region}/${req.params.area}/${req.params.poi}/${req.params.detail}`;
69
-
70
- let exists = await db.poi.exists({ route: currentRoute, user: req.session.currentUser });
71
- if (!exists) await db.poi.create({
72
- route: currentRoute,
73
- name: req.params.detail,
74
- type: "user",
87
+ console.log(req.body);
88
+ await db.detail.updateOne({
89
+ route: req.body.route,
90
+ service: req.body.service,
91
+ scope: "local",
92
+ user: req.session.currentUser
93
+ }, {
94
+ route: req.body.route,
95
+ service: req.body.service,
96
+ scope: "local",
75
97
  user: req.session.currentUser,
76
- data: {}
98
+ _lastUpdate: req.body.time,
99
+ data: req.body.data
100
+ }, {
101
+ upsert: true
77
102
  });
78
103
 
79
- await db.poi.updateOne({ route: currentRoute, user: req.session.currentUser }, { data: req.body });
80
-
81
104
  res.send("Update successful!");
82
105
  }
83
106
  catch(err) {
@@ -102,7 +125,7 @@ const explorer = async function explorer(worldPath, voidPath) {
102
125
  inventory: foundInventory,
103
126
  query: req.query,
104
127
  dir: worldPath,
105
- path: path
128
+ route: `/${req.params.region}/${req.params.area}/${req.params.poi}/${req.params.detail}`
106
129
  }
107
130
 
108
131
  await res.render(`explorer`, context);
@@ -113,7 +136,8 @@ const explorer = async function explorer(worldPath, voidPath) {
113
136
  siteTitle: "NotherBase | The Void",
114
137
  user: null,
115
138
  inventory: null,
116
- main: `${voidPath}/index`
139
+ main: `${voidPath}/index`,
140
+ route: `/void/index`
117
141
  });
118
142
  }
119
143
  }
@@ -139,7 +163,7 @@ const explorer = async function explorer(worldPath, voidPath) {
139
163
  inventory: foundInventory,
140
164
  query: req.query,
141
165
  dir: worldPath,
142
- path: path
166
+ route: `/${req.params.region}/${req.params.area}/${req.params.poi}/index`
143
167
  }
144
168
 
145
169
  await res.render(`explorer`, context);
@@ -150,7 +174,8 @@ const explorer = async function explorer(worldPath, voidPath) {
150
174
  siteTitle: "NotherBase | The Void",
151
175
  user: null,
152
176
  inventory: null,
153
- main: `${voidPath}/index`
177
+ main: `${voidPath}/index`,
178
+ route: `/void/index`
154
179
  });
155
180
  }
156
181
  }
@@ -172,7 +197,8 @@ const explorer = async function explorer(worldPath, voidPath) {
172
197
  siteTitle: "NotherBase | The Void",
173
198
  user: null,
174
199
  inventory: null,
175
- main: `${voidPath}/index`
200
+ main: `${voidPath}/index`,
201
+ route: `/void/index`
176
202
  });
177
203
  });
178
204
 
@@ -43,7 +43,7 @@ const front = async function front(dir) {
43
43
  inventory: foundInventory,
44
44
  query: req.query,
45
45
  dir: dir,
46
- path: path
46
+ route: `/the-front/${req.params.detail}`
47
47
  }
48
48
 
49
49
  await res.render(`explorer`, context);
@@ -69,7 +69,7 @@ const front = async function front(dir) {
69
69
  inventory: foundInventory,
70
70
  query: req.query,
71
71
  dir: dir,
72
- path: path
72
+ route: `/the-front/${req.params.detail}`
73
73
  }
74
74
 
75
75
  await res.render(`explorer`, context);
@@ -1,10 +1,11 @@
1
1
  // This allows us to use Mongoose to connect to MongoDB
2
2
  const mongoose = require("mongoose");
3
3
 
4
- const poi = new mongoose.Schema({
4
+ const detail = new mongoose.Schema({
5
+ _lastUpdate: Number,
5
6
  route: String,
6
- name: String,
7
- type: String,
7
+ service: String,
8
+ scope: String,
8
9
  user: {
9
10
  type: mongoose.Schema.Types.ObjectId,
10
11
  ref: "users",
@@ -15,4 +16,4 @@ const poi = new mongoose.Schema({
15
16
 
16
17
  // This tells Mongoose to use the exampleSchema to access the examples collection
17
18
  // in our db and then exports the model so we can use it.
18
- module.exports = mongoose.model('pois', poi);
19
+ module.exports = mongoose.model('details', detail);
package/models/index.js CHANGED
@@ -7,6 +7,6 @@ module.exports = {
7
7
  inventory: require("./inventory"),
8
8
  game: require("./game"),
9
9
  sendMail: require("./send-mail"),
10
- poi: require("./poi"),
10
+ detail: require("./detail"),
11
11
  page: require("./page")
12
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notherbase-fs",
3
- "version": "1.3.14",
3
+ "version": "1.4.1",
4
4
  "description": "Functions to help make developing for NotherBase easier.",
5
5
  "main": "notherbase-fs.js",
6
6
  "scripts": {
@@ -0,0 +1,45 @@
1
+ class Memories {
2
+ constructor() {
3
+ this._lastUpdate = 0;
4
+ this.data = {};
5
+ }
6
+
7
+ load = async (service, route = currentRoute) => {
8
+ try {
9
+ await $.get(`/recall`, {
10
+ route: route,
11
+ service: service,
12
+ _lastUpdate: this._lastUpdate
13
+ }, (res) => {
14
+ if (!res.isUpToDate && res.data) {
15
+ this.data[service] = JSON.parse(res.data);
16
+ this._lastUpdate = this.data[service]._lastUpdate;
17
+ }
18
+ });
19
+
20
+ return this.data[service];
21
+ } catch (error) {
22
+ return error;
23
+ }
24
+ }
25
+
26
+ save = async (service, dataToSave, route = currentRoute) => {
27
+ try {
28
+ this._lastUpdate = Date.now();
29
+
30
+ await $.post('/commit', {
31
+ route: route,
32
+ service: service,
33
+ time: this._lastUpdate,
34
+ data: JSON.stringify(dataToSave)
35
+ }, (data) => {
36
+ this.data[service] = dataToSave;
37
+ return "saved";
38
+ });
39
+ } catch (error) {
40
+ return error;
41
+ }
42
+ }
43
+ }
44
+
45
+ const memories = new Memories();
@@ -17,9 +17,9 @@
17
17
 
18
18
  <hr>
19
19
 
20
- <h3>Game Test</h3>
20
+ <h3>memories Test</h3>
21
21
 
22
- <button onclick="addToTime()">Add</button>
22
+ <button onclick="setTime()">Add</button>
23
23
  <p id="timer">0:00</p>
24
24
 
25
25
  <hr>
@@ -105,44 +105,34 @@
105
105
 
106
106
  let time = 0;
107
107
 
108
- let addToTime = async function addToTime() {
109
- try {
110
- time += 10;
108
+ (async () => {
109
+ let load = await memories.load("time", "/void/test");
110
+ console.log(load);
111
+ time = load.time;
112
+ })();
111
113
 
112
- await $.post(`/coast/tall-beach/nono-cove/index/save`, { timer: time, lastTime: Date.now() }, function () {
113
- $("#timer").text(Math.floor(time));
114
- });
115
- } catch (error) {
116
- console.log(error);
117
- }
118
- }
119
-
120
- let getTime = async function getTime() {
121
- try {
122
- await $.get(`/coast/tall-beach/nono-cove/index/load`, function (data) {
123
- console.log(data);
124
- data.timer = parseFloat(data.timer);
125
- data.lastTime = parseFloat(data.lastTime);
126
- console.log(data);
127
- console.log(Date.now());
128
- time = data.timer - ((Date.now() - data.lastTime) / 1000);
129
- if (time < 0) time = 0;
130
- $("#timer").text(Math.floor(time));
131
- });
132
- } catch (error) {
133
- console.log(error);
134
- }
114
+ let setTime = async function setTime() {
115
+ time = Date.now();
116
+
117
+ await memories.save("time", {
118
+ time: time,
119
+ a: "dabfb",
120
+ bln: false,
121
+ numba: 4236,
122
+ arrray: [32, "sg", 45],
123
+ check: {
124
+ time: time,
125
+ a: "dabfb",
126
+ bln: false,
127
+ numba: 4236,
128
+ arrray: [32, "sg", 45]
129
+ }
130
+ }, "/void/test");
135
131
  }
136
132
 
137
133
  let updateTime = function updateTime() {
138
- if (time > 0) {
139
- time--;
140
- if (time < 0) time = 0;
141
- $("#timer").text(Math.floor(time));
142
- }
143
-
134
+ $("#timer").text(Math.floor((Date.now() - time) / 1000));
144
135
  }
145
136
 
146
137
  setInterval(updateTime, 1000);
147
- getTime();
148
138
  </script>
@@ -1,5 +1,10 @@
1
1
  <%- include("./head.ejs"); %>
2
2
 
3
+ <script>
4
+ const currentRoute = "<%- route %>";
5
+ </script>
6
+ <script src="/js/memories.js"></script>
7
+
3
8
  <main class="override">
4
9
  <%- include(`${main}.ejs`); %>
5
10
  </main>
@@ -19,7 +19,7 @@
19
19
  constructor() {
20
20
  this.$div = $(".inventory");
21
21
  this.$list = $(".inventory .item-list");
22
- this.$search = $(".search");
22
+ this.$search = $(".inventory .search");
23
23
  this.$searchResults = $(".search-results");
24
24
  this.searchResults = [];
25
25
  this.$error = $("#inventory #error");