notherbase-fs 4.5.5 → 4.5.7

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/notherbase-fs.js CHANGED
@@ -101,7 +101,7 @@ class NotherBaseFS {
101
101
  req.Spirit = Spirit;
102
102
  req.SendMail = SendMail;
103
103
  req.globals = globals;
104
- req.user = req.session?.currentUser ? await req.Spirit.findOne({ service: "user", username: req.session.currentUser }) : null;
104
+ req.user = req.session?.currentUser ? await req.Spirit.findOne({ service: "user", "data.username": req.session.currentUser }) : null;
105
105
  req.lock = false;
106
106
  // enables sessions only if the protocol is https and we are in production, or if we are in development
107
107
  req.sessionsEnabled = (process.env.PRODUCTION == "true" && req.secure) || process.env.PRODUCTION == "false";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "notherbase-fs",
3
- "version": "4.5.5",
3
+ "version": "4.5.7",
4
4
  "description": "Functions to help make developing for NotherBase easier.",
5
5
  "exports": "./notherbase-fs.js",
6
6
  "scripts": {
@@ -58,7 +58,7 @@ export default class Creation {
58
58
  req.toRender = "explorer";
59
59
 
60
60
  if (fs.existsSync(req.main + ".ejs")) {
61
- let stats = await req.Spirit.findOne({ service: "stats", data: { route: req.path } });
61
+ let stats = await req.Spirit.findOne({ service: "stats", "data.route": req.path });
62
62
  if (stats == null) stats = new req.Spirit({ service: "stats", data: { route: req.path, visits: 0 } });
63
63
  if (stats.data.visits) stats.data.visits++;
64
64
  else stats.data.visits = 1;
@@ -75,14 +75,13 @@ export default class Creation {
75
75
  }
76
76
 
77
77
  if (req.session.currentUser) {
78
- let user = req.user;
79
78
  context.user = {
80
- data: user.data,
81
- backups: user.backups,
82
- _id: user._id,
83
- parent: user.parent,
84
- service: user.service,
85
- _lastUpdate: user._lastUpdate
79
+ data: req.user.data,
80
+ backups: req.user.backups,
81
+ _id: req.user._id,
82
+ parent: req.user.parent,
83
+ service: req.user.service,
84
+ _lastUpdate: req.user._lastUpdate
86
85
  }
87
86
  }
88
87
 
package/server/spirit.js CHANGED
@@ -44,6 +44,7 @@ let spiritSchema = new mongoose.Schema({
44
44
  spiritSchema.method("commit", async function(data = this.data, maxBackups = 5) {
45
45
  this._lastUpdate = Date.now();
46
46
 
47
+ if (!Array.isArray(this.backups)) this.backups = [];
47
48
  this.backups.unshift({
48
49
  _lastUpdate: Date.now(),
49
50
  data: this.data
@@ -65,6 +66,9 @@ spiritSchema.method("commit", async function(data = this.data, maxBackups = 5) {
65
66
  * @returns Status message.
66
67
  */
67
68
  spiritSchema.method("restoreBackup", async function(backupIndex) {
69
+ this._lastUpdate = Date.now();
70
+
71
+ if (!Array.isArray(this.backups)) this.backups = [];
68
72
  if (backupIndex < 0 || backupIndex >= this.backups.length) return "Invalid backup index";
69
73
  let backup = this.backups[backupIndex];
70
74
  this.backups.unshift({
package/server/user.js CHANGED
@@ -186,7 +186,6 @@ export default class User {
186
186
 
187
187
  spirit = new req.Spirit({
188
188
  service:"user",
189
- _lastUpdate: Date.now(),
190
189
  data: {
191
190
  username: req.body.username,
192
191
  password: hash,
@@ -198,10 +197,9 @@ export default class User {
198
197
  expires: 0
199
198
  },
200
199
  sessions: {}
201
- },
202
- backups: []
200
+ }
203
201
  });
204
- await spirit.save();
202
+ await spirit.commit();
205
203
 
206
204
  success(res, "Registration successful!");
207
205
  }
@@ -370,7 +368,7 @@ export default class User {
370
368
  parent: user._id,
371
369
  backups: data[i].backups || []
372
370
  });
373
- await spirit.save();
371
+ await spirit.commit();
374
372
  if (spirit) imported++;
375
373
  }
376
374
  }