notherbase-fs 4.4.7 → 4.5.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.
- package/notherbase-fs.js +40 -32
- package/package.json +1 -1
- package/public/js/base.js +1 -41
- package/server/creation.js +117 -0
- package/server/spirit-world.js +147 -0
- package/server/spirit.js +83 -0
- package/{controllers → server}/user.js +36 -37
- package/test/coast/tall-beach/nono-cove/index.ejs +3 -3
- package/test/the-front/add-gold.js +4 -12
- package/test/the-front/index.ejs +12 -6
- package/test2/the-front/index.ejs +0 -99
- package/views/explorer.ejs +1 -1
- package/views/footer.ejs +1 -1
- package/controllers/creation.js +0 -181
- package/controllers/spirit-world.js +0 -247
- package/models/index.js +0 -31
- package/models/spirit.js +0 -235
- package/test2/the-front/add-gold.js +0 -14
- package/test2/the-front/check/check.css +0 -3
- package/test2/the-front/check/emailTime.js +0 -10
- package/test2/the-front/check/flip.js +0 -10
- package/test2/the-front/check/index.ejs +0 -55
- package/test2/the-front/check/save-input.js +0 -8
- package/test2/the-front/keeper/clipboards.js +0 -134
- package/test2/the-front/keeper/index.ejs +0 -81
- package/test2/the-front/keeper/keeper.css +0 -158
- package/test2/the-front/keeper/keeper.js +0 -140
- package/test2/the-front/test-page/emailTime.js +0 -9
- package/test2/the-front/test-page/index.ejs +0 -74
- /package/{models → server}/send-mail.js +0 -0
- /package/{controllers → server}/util.js +0 -0
- /package/test/{the-front/void → void}/index.ejs +0 -0
- /package/test/{the-front/void → void}/void.css +0 -0
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import express from "express";
|
|
2
|
-
import { stripHtml } from "string-strip-html";
|
|
3
|
-
import { success, fail } from "./util.js";
|
|
4
|
-
import User from "./user.js";
|
|
5
|
-
import fs from 'fs';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* The spirit world is the API of a base.
|
|
9
|
-
*/
|
|
10
|
-
export default class SpiritWorld {
|
|
11
|
-
/**
|
|
12
|
-
* Sets up the spirit world.
|
|
13
|
-
* @param {Server} io
|
|
14
|
-
*/
|
|
15
|
-
constructor(io) {
|
|
16
|
-
this.io = io;
|
|
17
|
-
this.rooms = {};
|
|
18
|
-
this.io.on('connection', this.setupChat);
|
|
19
|
-
|
|
20
|
-
this.user = new User();
|
|
21
|
-
this.router = express.Router();
|
|
22
|
-
this.router.post("/loadAll", this.loadAll);
|
|
23
|
-
this.router.post("/load", this.load);
|
|
24
|
-
this.router.post("/save", this.save);
|
|
25
|
-
this.router.post("/delete", this.delete);
|
|
26
|
-
this.router.post("/serve", this.serve);
|
|
27
|
-
this.router.use("/user", this.user.router);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Sets up socket.io for instant messaging and etc.
|
|
32
|
-
* @param {*} socket
|
|
33
|
-
*/
|
|
34
|
-
setupChat = (socket) => {
|
|
35
|
-
try {
|
|
36
|
-
let roomName = socket.handshake.query.room;
|
|
37
|
-
socket.join(roomName);
|
|
38
|
-
let room = this.rooms[roomName];
|
|
39
|
-
if (room) room.users.push(socket.handshake.query.name);
|
|
40
|
-
else {
|
|
41
|
-
this.rooms[roomName] = {
|
|
42
|
-
users: [ socket.handshake.query.name ]
|
|
43
|
-
}
|
|
44
|
-
room = this.rooms[roomName];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
this.io.to(roomName).emit("chat message", {
|
|
48
|
-
name: "Server",
|
|
49
|
-
time: Date.now(),
|
|
50
|
-
text: `${socket.handshake.query.name} has joined the room.`
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
this.io.to(roomName).emit("chat info", {
|
|
54
|
-
name: socket.handshake.query.room,
|
|
55
|
-
time: Date.now(),
|
|
56
|
-
data: {
|
|
57
|
-
users: room.users
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
socket.on("chat message", (msg) => {
|
|
62
|
-
this.io.to(roomName).emit("chat message", {
|
|
63
|
-
name: msg.name,
|
|
64
|
-
time: msg.time,
|
|
65
|
-
text: stripHtml(msg.text).result
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
socket.on('disconnect', () => {
|
|
70
|
-
room.users.splice(room.users.indexOf(socket.handshake.query.name));
|
|
71
|
-
|
|
72
|
-
this.io.to(roomName).emit("chat message", {
|
|
73
|
-
name: "Server",
|
|
74
|
-
time: Date.now(),
|
|
75
|
-
text: `${socket.handshake.query.name} has left the room.`
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
this.io.to(roomName).emit("chat info", {
|
|
79
|
-
name: socket.handshake.query.room,
|
|
80
|
-
time: Date.now(),
|
|
81
|
-
data: {
|
|
82
|
-
users: room.users
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
if (room.users.length < 1) delete this.rooms[roomName];
|
|
87
|
-
});
|
|
88
|
-
} catch (error) {
|
|
89
|
-
console.log(error);
|
|
90
|
-
fail(res, "Server error: Sockets");
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* This API route requests all spirits of a kind from the database.
|
|
96
|
-
* @param {Object} req
|
|
97
|
-
* @param {Object} res
|
|
98
|
-
* @returns {Object} The requested spirits.
|
|
99
|
-
*/
|
|
100
|
-
loadAll = async (req, res) => {
|
|
101
|
-
try {
|
|
102
|
-
let parent = null;
|
|
103
|
-
let data = req.body.data ? req.body.data : {};
|
|
104
|
-
let id = req.body.id ? req.body.id : null;
|
|
105
|
-
|
|
106
|
-
// if the scope is local, the parent is the user's id
|
|
107
|
-
if (req.body.scope === "local") {
|
|
108
|
-
let user = await req.db.Spirit.recallOne("user", null, { username: req.session?.currentUser });
|
|
109
|
-
if (user?.memory?._id) parent = user.memory._id;
|
|
110
|
-
else {
|
|
111
|
-
fail(res, "User had no id on load()");
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// recall all spirits with the given service name and parent
|
|
117
|
-
let spirits = await req.db.Spirit.recallAll(req.body.service, parent, data, id);
|
|
118
|
-
|
|
119
|
-
res.send(spirits);
|
|
120
|
-
} catch (error) {
|
|
121
|
-
console.log(error);
|
|
122
|
-
fail(res, "Server error");
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* This API route requests a spirit of a kind from the database.
|
|
128
|
-
* @param {Object} req
|
|
129
|
-
* @param {Object} res
|
|
130
|
-
*/
|
|
131
|
-
load = async (req, res) => {
|
|
132
|
-
try {
|
|
133
|
-
let parent = null;
|
|
134
|
-
let data = req.body.data ? req.body.data : {};
|
|
135
|
-
let id = req.body.id ? req.body.id : null;
|
|
136
|
-
|
|
137
|
-
// if the scope is local, the parent is the user's id
|
|
138
|
-
if (req.body.scope === "local") {
|
|
139
|
-
let user = await req.db.Spirit.recallOne("user", null, { username: req.session?.currentUser });
|
|
140
|
-
if (user?.memory?._id) parent = user.memory._id;
|
|
141
|
-
else {
|
|
142
|
-
fail(res, "User had no id on load()");
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// recall all spirits with the given service name and parent
|
|
148
|
-
let spirit = await req.db.Spirit.recallOne(req.body.service, parent, data, id);
|
|
149
|
-
|
|
150
|
-
res.send(spirit);
|
|
151
|
-
} catch (error) {
|
|
152
|
-
console.log(error);
|
|
153
|
-
fail(res, "Server error");
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* This API route saves a spirit to the database.
|
|
159
|
-
* @param {Object} req
|
|
160
|
-
* @param {Object} res
|
|
161
|
-
*/
|
|
162
|
-
save = async (req, res) => {
|
|
163
|
-
try {
|
|
164
|
-
let parent = null;
|
|
165
|
-
let spiritData = req.body.data ? req.body.data : {};
|
|
166
|
-
let id = req.body.id ? req.body.id : null;
|
|
167
|
-
|
|
168
|
-
// if the scope is local, the parent is the user's id
|
|
169
|
-
if (req.body.scope === "local") {
|
|
170
|
-
let user = await req.db.Spirit.recallOne("user", null, { username: req.session?.currentUser });
|
|
171
|
-
if (user?.memory?._id) parent = user.memory._id;
|
|
172
|
-
else {
|
|
173
|
-
fail(res, "User had no id on load()");
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// save the spirit with the given service name and parent
|
|
179
|
-
let spirit = null;
|
|
180
|
-
if (id !== "new") spirit = await req.db.Spirit.recallOne(req.body.service, parent, {}, id);
|
|
181
|
-
|
|
182
|
-
if (spirit) {
|
|
183
|
-
// update existing spirit
|
|
184
|
-
await spirit.commit({ ...spirit.memory.data, ...spiritData });
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
// create new spirit
|
|
188
|
-
spirit = await req.db.Spirit.create(req.body.service, spiritData, parent);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
res.send(spirit.memory._id);
|
|
192
|
-
} catch (error) {
|
|
193
|
-
console.log(error);
|
|
194
|
-
fail(res, "Server error");
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
delete = async (req, res) => {
|
|
199
|
-
try {
|
|
200
|
-
let parent = null;
|
|
201
|
-
let data = req.body.data ? req.body.data : {};
|
|
202
|
-
let id = req.body.id ? req.body.id : null;
|
|
203
|
-
|
|
204
|
-
// if the scope is local, the parent is the user's id
|
|
205
|
-
if (req.body.scope === "local") {
|
|
206
|
-
let user = await req.db.Spirit.recallOne("user", null, { username: req.session?.currentUser });
|
|
207
|
-
if (user?.memory?._id) parent = user.memory._id;
|
|
208
|
-
else {
|
|
209
|
-
fail(res, "User had no id on load()");
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// delete the spirits
|
|
215
|
-
let deleted = await req.db.Spirit.delete(req.body.service, parent, data, id);
|
|
216
|
-
res.send(`${deleted}`);
|
|
217
|
-
} catch (error) {
|
|
218
|
-
console.log(error);
|
|
219
|
-
fail(res, "Server error");
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* This API route runs a script on the server. Responds with the result.
|
|
225
|
-
* @param {Object} req
|
|
226
|
-
* @param {Object} res
|
|
227
|
-
*/
|
|
228
|
-
serve = async (req, res) => {
|
|
229
|
-
try {
|
|
230
|
-
let scriptPath = `${req.contentPath}${req.body.route}/${req.body.script}.js`;
|
|
231
|
-
|
|
232
|
-
let script, result = null;
|
|
233
|
-
|
|
234
|
-
if (fs.existsSync(scriptPath)) {
|
|
235
|
-
let user = await req.db.Spirit.recallOne("user", null, { username: req.session?.currentUser });
|
|
236
|
-
|
|
237
|
-
script = await import(process.env.WINDOWS == "true" ? `file://${scriptPath}` : scriptPath);
|
|
238
|
-
result = await script.default(req, user, this.io);
|
|
239
|
-
success(res, "Served.", result);
|
|
240
|
-
}
|
|
241
|
-
else fail(res, `Script not found: ${req.body.script} at ${scriptPath}`);
|
|
242
|
-
} catch (error) {
|
|
243
|
-
console.log(error);
|
|
244
|
-
fail(res, "Server error");
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
package/models/index.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import mongoose from "mongoose";
|
|
2
|
-
import dotenv from "dotenv";
|
|
3
|
-
dotenv.config();
|
|
4
|
-
import Spirit from "./spirit.js";
|
|
5
|
-
import SendMail from "./send-mail.js";
|
|
6
|
-
|
|
7
|
-
mongoose.set('strictQuery', true);
|
|
8
|
-
|
|
9
|
-
mongoose.connection.on('connected', (err) => {
|
|
10
|
-
console.log(`Mongoose connected to db`);
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
mongoose.connection.on('error', (err) => {
|
|
14
|
-
console.log(`Mongoose ${err}`);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
mongoose.connection.on('disconnected', () => {
|
|
18
|
-
console.log('Mongoose disconnected');
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
mongoose.connect(process.env.MONGODB_URI);
|
|
23
|
-
}
|
|
24
|
-
catch (err) {
|
|
25
|
-
console.log(`Mongoose on connect: ${err}`);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default {
|
|
29
|
-
SendMail: SendMail,
|
|
30
|
-
Spirit: Spirit
|
|
31
|
-
}
|
package/models/spirit.js
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import mongoose from "mongoose";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Curated Mongoose.js documents for use in bases.
|
|
5
|
-
*/
|
|
6
|
-
export default class Spirit {
|
|
7
|
-
// The actual Mongoose.js model for accessing the database.
|
|
8
|
-
static db = mongoose.model('spirits', new mongoose.Schema({
|
|
9
|
-
_lastUpdate: Number,
|
|
10
|
-
service: String,
|
|
11
|
-
parent: {
|
|
12
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
13
|
-
ref: "spirits",
|
|
14
|
-
required: false
|
|
15
|
-
},
|
|
16
|
-
data: {},
|
|
17
|
-
backups: []
|
|
18
|
-
}));
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Builds query objects for Mongoose.js searches.
|
|
22
|
-
* @param {String} service The name of the spirit.
|
|
23
|
-
* @param {Object} data An object with data to query the spirit by.
|
|
24
|
-
* @param {ObjectID} parent The MongoDB id of the parent spirit to search by.
|
|
25
|
-
* @param {ObjectID} id The exact id of the MongoDB document.
|
|
26
|
-
* @returns A query object.
|
|
27
|
-
*/
|
|
28
|
-
static buildQuery = (service, data = null, parent = null, id = null) => {
|
|
29
|
-
let query = {
|
|
30
|
-
parent: parent
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
if (service) query.service = service;
|
|
34
|
-
if (id) query._id = id;
|
|
35
|
-
else if (data){
|
|
36
|
-
let keys = Object.keys(data);
|
|
37
|
-
for (let i = 0; i < keys.length; i++) {
|
|
38
|
-
query[`data.${keys[i]}`] = data[keys[i]];
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return query;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// static buildBackupQuery = (service, data = null, parent = null, id = null) => {
|
|
46
|
-
// let query = {
|
|
47
|
-
// service: service,
|
|
48
|
-
// parent: parent
|
|
49
|
-
// };
|
|
50
|
-
|
|
51
|
-
// if (id) query._id = id;
|
|
52
|
-
// else if (data){
|
|
53
|
-
// let keys = Object.keys(data);
|
|
54
|
-
// for (let i = 0; i < keys.length; i++) {
|
|
55
|
-
|
|
56
|
-
// query[`data.backups.0.data.${keys[i]}`] = data[keys[i]];
|
|
57
|
-
// }
|
|
58
|
-
// }
|
|
59
|
-
|
|
60
|
-
// return query;
|
|
61
|
-
// }
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Creates a spirit in the database.
|
|
65
|
-
* @param {String} service The name of the spirit.
|
|
66
|
-
* @param {Object} data An object with data to create the spirit with.
|
|
67
|
-
* @param {ObjectID} parent The MongoDB id of the parent of the spirit to be created.
|
|
68
|
-
* @returns A new spirit.
|
|
69
|
-
*/
|
|
70
|
-
static create = async (service, data = {}, parent = null) => {
|
|
71
|
-
let spirit = new Spirit();
|
|
72
|
-
|
|
73
|
-
spirit.memory = await Spirit.db.create({
|
|
74
|
-
service,
|
|
75
|
-
parent,
|
|
76
|
-
_lastUpdate: Date.now(),
|
|
77
|
-
data: data,
|
|
78
|
-
backups: []
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
return spirit;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Recalls all spirits in the database with a given name.
|
|
86
|
-
* @param {String} service The name of the spirit.
|
|
87
|
-
* @param {ObjectID} parent The MongoDB id of the parent spirit to search by.
|
|
88
|
-
* @param {Object} data An object with data to query the spirit by.
|
|
89
|
-
* @param {ObjectID} id The exact id of the MongoDB document.
|
|
90
|
-
* @returns All spirits found.
|
|
91
|
-
*/
|
|
92
|
-
static recallAll = async (service, parent = null, data = {}, id = null) => {
|
|
93
|
-
let spirits = [];
|
|
94
|
-
|
|
95
|
-
let query = Spirit.buildQuery(service, data, parent, id);
|
|
96
|
-
|
|
97
|
-
let found = await Spirit.db.find(query);
|
|
98
|
-
|
|
99
|
-
if (found) {
|
|
100
|
-
for (let i = 0; i < found.length; i++) {
|
|
101
|
-
let spirit = new Spirit(found[i]);
|
|
102
|
-
spirits.push(spirit);
|
|
103
|
-
// convert old backups to new format
|
|
104
|
-
if (spirit.memory.data?._backupsEnabled) {
|
|
105
|
-
spirit.memory.backups = spirit.memory.data.backups;
|
|
106
|
-
spirit.memory.data = spirit.memory.backups[0].data;
|
|
107
|
-
spirit.memory.markModified("backups");
|
|
108
|
-
await spirit.commit();
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return spirits;
|
|
113
|
-
}
|
|
114
|
-
else return null;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Recalls one spirit from the database or creates a new one.
|
|
119
|
-
* @param {String} service The name of the spirit.
|
|
120
|
-
* @param {ObjectID} parent The MongoDB id of the parent spirit to search by.
|
|
121
|
-
* @param {Object} data An object with data to query the spirit by.
|
|
122
|
-
* @param {ObjectID} id The exact id of the MongoDB document.
|
|
123
|
-
* @returns The spirit found or a new one created in the database.
|
|
124
|
-
*/
|
|
125
|
-
static recallOne = async (service, parent = null, data = {}, id = null) => {
|
|
126
|
-
let spirit = null;
|
|
127
|
-
|
|
128
|
-
let query = Spirit.buildQuery(service, data, parent, id);
|
|
129
|
-
|
|
130
|
-
let found = await Spirit.db.findOne(query);
|
|
131
|
-
|
|
132
|
-
if (found) {
|
|
133
|
-
spirit = new Spirit(found);
|
|
134
|
-
|
|
135
|
-
// convert old backups to new format
|
|
136
|
-
if (spirit.memory.data?._backupsEnabled) {
|
|
137
|
-
spirit.memory.backups = spirit.memory.data.backups;
|
|
138
|
-
spirit.memory.data = spirit.memory.backups[0].data;
|
|
139
|
-
spirit.memory.markModified("backups");
|
|
140
|
-
await spirit.commit();
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return spirit;
|
|
144
|
-
}
|
|
145
|
-
else return null;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Recalls or creates a spirit in the database.
|
|
150
|
-
* @param {String} service The name of the spirit.
|
|
151
|
-
* @param {ObjectID} parent The MongoDB id of the parent spirit to search by.
|
|
152
|
-
* @param {Object} data An object with data to query the spirit by.
|
|
153
|
-
* @param {ObjectID} id The exact id of the MongoDB document.
|
|
154
|
-
* @returns The spirit found or a new one created in the database.
|
|
155
|
-
*/
|
|
156
|
-
static recallOrCreateOne = async (service, parent = null, data = {}, id = null) => {
|
|
157
|
-
let spirit = null;
|
|
158
|
-
|
|
159
|
-
let query = Spirit.buildQuery(service, data, parent, id);
|
|
160
|
-
|
|
161
|
-
let found = await Spirit.db.findOne(query);
|
|
162
|
-
|
|
163
|
-
if (found) spirit = new Spirit(found);
|
|
164
|
-
else spirit = await Spirit.create(service, data, parent);
|
|
165
|
-
|
|
166
|
-
// convert old backups to new format
|
|
167
|
-
if (spirit.memory.data?._backupsEnabled) {
|
|
168
|
-
spirit.memory.backups = spirit.memory.data.backups;
|
|
169
|
-
spirit.memory.data = spirit.memory.backups[0].data;
|
|
170
|
-
spirit.memory.markModified("backups");
|
|
171
|
-
await spirit.commit();
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return spirit;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Deletes all of the specified spirit.
|
|
179
|
-
* @param {String} service The name of the spirit.
|
|
180
|
-
* @param {ObjectID} parent The MongoDB id of the parent spirit to search with.
|
|
181
|
-
* @param {Object} data An object with data to query the spirit by.
|
|
182
|
-
* @param {ObjectID} id The exact id of the MongoDB document.
|
|
183
|
-
* @returns The number of documents deleted.
|
|
184
|
-
*/
|
|
185
|
-
static delete = async (service, parent = null, data = {}, id = null) => {
|
|
186
|
-
let found = await Spirit.db.deleteMany(Spirit.buildQuery(service, data, parent, id));
|
|
187
|
-
|
|
188
|
-
return found.deletedCount;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
constructor(memory = {}) {
|
|
192
|
-
this.memory = memory;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Commits new data to a spirit.
|
|
197
|
-
* @param {Object} data Data to save.
|
|
198
|
-
* @returns Updated
|
|
199
|
-
*/
|
|
200
|
-
commit = async (data = this.memory.data) => {
|
|
201
|
-
this.memory._lastUpdate = Date.now();
|
|
202
|
-
|
|
203
|
-
this.memory.data = data;
|
|
204
|
-
this.memory.markModified("data");
|
|
205
|
-
await this.memory.save();
|
|
206
|
-
|
|
207
|
-
return "Updated";
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* Normalizes the data property to an array.
|
|
212
|
-
*/
|
|
213
|
-
normalizeDataToArray = () => {
|
|
214
|
-
if (!Array.isArray(this.memory.data)) this.memory.data = [];
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Adds a new backup to the spirit's data.
|
|
219
|
-
* @param {Object} data Data to add to the backup.
|
|
220
|
-
*/
|
|
221
|
-
addBackup = (data, max = 5) => {
|
|
222
|
-
this.memory.backups.unshift({
|
|
223
|
-
_lastUpdate: Date.now(),
|
|
224
|
-
data: this.memory.data
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
this.memory.data = data;
|
|
228
|
-
|
|
229
|
-
if (max > 1) {
|
|
230
|
-
while (this.memory.backups.length > max) this.memory.backups.pop();
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
this.memory.markModified("backups");
|
|
234
|
-
}
|
|
235
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export default async (req, user, io) => {
|
|
2
|
-
// let deleted = await req.db.Spirit.delete("gold");
|
|
3
|
-
let spirit = await req.db.Spirit.recallOrCreateOne("gold");
|
|
4
|
-
spirit.addBackup({
|
|
5
|
-
amount: spirit.memory?.data?.amount != null ? spirit.memory.data.amount + 1 : 1
|
|
6
|
-
});
|
|
7
|
-
await spirit.commit();
|
|
8
|
-
|
|
9
|
-
spirit = await req.db.Spirit.recallOrCreateOne("gold", user.memory._id);
|
|
10
|
-
spirit.addBackup({
|
|
11
|
-
amount: spirit.memory?.data?.amount != null ? spirit.memory.data.amount + 1 : 1
|
|
12
|
-
});
|
|
13
|
-
await spirit.commit();
|
|
14
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export default async (req, user, io) => {
|
|
2
|
-
let bigSwitch = await req.db.Spirit.recallOne("big-switch");
|
|
3
|
-
|
|
4
|
-
if (!bigSwitch.memory.data.flipped) await bigSwitch.commit({ flipped: true });
|
|
5
|
-
else await bigSwitch.commit({ flipped: false });
|
|
6
|
-
console.log(bigSwitch.memory.data);
|
|
7
|
-
|
|
8
|
-
io.to("big-switch").emit("big-switch", { flipped: bigSwitch.memory.data.flipped });
|
|
9
|
-
return "success";
|
|
10
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
<style>
|
|
2
|
-
<%- include("./check.css"); %>
|
|
3
|
-
</style>
|
|
4
|
-
|
|
5
|
-
<h1>The Big Check</h1>
|
|
6
|
-
|
|
7
|
-
<hr>
|
|
8
|
-
|
|
9
|
-
<button onclick="base.do('add-more-gold')">+3</button>
|
|
10
|
-
<button onclick="base.do('subtract-gold')">-30</button>
|
|
11
|
-
<button onclick="base.do('emailTime', { route: '/the-front/check'})">email</button>
|
|
12
|
-
<button class="switch" onclick="base.do('flip')">Flip Me</button>
|
|
13
|
-
<input type="text" id="test" placeholder="Loading...">
|
|
14
|
-
<button onclick="saveInput()">Save</button>
|
|
15
|
-
|
|
16
|
-
<hr>
|
|
17
|
-
|
|
18
|
-
<a href="/the-front">
|
|
19
|
-
Go to The Front
|
|
20
|
-
</a>
|
|
21
|
-
|
|
22
|
-
<script>
|
|
23
|
-
const $inp = $("input#test");
|
|
24
|
-
|
|
25
|
-
base.loadAll("test-save3").then((res) => {
|
|
26
|
-
console.log(res);
|
|
27
|
-
if (res[0]?.memory.data.text) $inp.attr("placeholder", res[0].memory.data.text);
|
|
28
|
-
else $inp.attr("placeholder", "No Input Saved");
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const saveInput = function saveInput() {
|
|
32
|
-
let inp = $inp.val();
|
|
33
|
-
|
|
34
|
-
base.do("save-input", {
|
|
35
|
-
text: inp,
|
|
36
|
-
route: "/the-front/check"
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
let switchSocket = io({
|
|
41
|
-
query: {
|
|
42
|
-
room: "big-switch",
|
|
43
|
-
name: "player"
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
switchSocket.on('big-switch', (update) => {
|
|
48
|
-
flipSwitch(update.flipped);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
let flipSwitch = function flipSwitch(flipped) {
|
|
52
|
-
if (flipped) $(".switch").addClass("flipped");
|
|
53
|
-
else $(".switch").removeClass("flipped");
|
|
54
|
-
}
|
|
55
|
-
</script>
|