notherbase-fs 4.0.22 → 4.1.0

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.
Files changed (55) hide show
  1. package/README.md +6 -6
  2. package/controllers/creation.js +171 -147
  3. package/controllers/spirit-world.js +174 -174
  4. package/controllers/user.js +240 -240
  5. package/controllers/util.js +64 -64
  6. package/models/index.js +33 -33
  7. package/models/send-mail.js +58 -58
  8. package/models/spirit.js +234 -234
  9. package/notherbase-fs.js +114 -112
  10. package/package.json +40 -40
  11. package/public/js/base.js +222 -227
  12. package/public/js/chat-box.js +120 -120
  13. package/test/coast/tall-beach/nono-cove/index.css +17 -17
  14. package/test/coast/tall-beach/nono-cove/index.ejs +29 -29
  15. package/test/coast/tall-beach/nono-cove/nono-og/add-gold.js +15 -15
  16. package/test/coast/tall-beach/nono-cove/nono-og/index.ejs +46 -46
  17. package/test/coast/tall-beach/nono-cove/nono-og/nono.css +88 -88
  18. package/test/coast/tall-beach/nono-cove/nono-og/nono.js +207 -207
  19. package/test/pages/test-page/emailTime.js +8 -8
  20. package/test/pages/test-page/index.ejs +104 -104
  21. package/test/pages/void/index.ejs +35 -35
  22. package/test/pages/void/void.css +2 -2
  23. package/test/public/styles/main.css +792 -792
  24. package/test/the-front/add-gold.js +13 -13
  25. package/test/the-front/check/_preprocess/saved.js +9 -0
  26. package/test/the-front/check/check.css +2 -2
  27. package/test/the-front/check/emailTime.js +9 -9
  28. package/test/the-front/check/flip.js +9 -9
  29. package/test/the-front/check/index.ejs +55 -54
  30. package/test/the-front/check/save-input.js +7 -7
  31. package/test/the-front/index.ejs +116 -99
  32. package/test/the-front/keeper/clipboards.js +133 -133
  33. package/test/the-front/keeper/index.ejs +80 -80
  34. package/test/the-front/keeper/keeper.css +157 -157
  35. package/test/the-front/keeper/keeper.js +140 -140
  36. package/test-index.js +19 -19
  37. package/test2/pages/test-page/emailTime.js +8 -8
  38. package/test2/pages/test-page/index.ejs +104 -104
  39. package/test2/pages/void/index.ejs +35 -35
  40. package/test2/pages/void/void.css +2 -2
  41. package/test2/public/styles/main.css +792 -792
  42. package/test2/the-front/add-gold.js +13 -13
  43. package/test2/the-front/check/check.css +2 -2
  44. package/test2/the-front/check/emailTime.js +9 -9
  45. package/test2/the-front/check/flip.js +9 -9
  46. package/test2/the-front/check/index.ejs +54 -54
  47. package/test2/the-front/check/save-input.js +7 -7
  48. package/test2/the-front/index.ejs +99 -99
  49. package/test2/the-front/keeper/clipboards.js +133 -133
  50. package/test2/the-front/keeper/index.ejs +80 -80
  51. package/test2/the-front/keeper/keeper.css +157 -157
  52. package/test2/the-front/keeper/keeper.js +140 -140
  53. package/views/explorer.ejs +82 -82
  54. package/views/footer.ejs +9 -9
  55. package/views/head.ejs +17 -17
@@ -1,175 +1,175 @@
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("/serve", this.serve);
25
- this.router.use("/user", this.user.router);
26
- }
27
-
28
- /**
29
- * Sets up socket.io for instant messaging and etc.
30
- * @param {*} socket
31
- */
32
- setupChat = (socket) => {
33
- let roomName = socket.handshake.query.room;
34
- socket.join(roomName);
35
- let room = this.rooms[roomName];
36
- if (room) room.users.push(socket.handshake.query.name);
37
- else {
38
- this.rooms[roomName] = {
39
- users: [ socket.handshake.query.name ]
40
- }
41
- room = this.rooms[roomName];
42
- }
43
-
44
- this.io.to(roomName).emit("chat message", {
45
- name: "Server",
46
- time: Date.now(),
47
- text: `${socket.handshake.query.name} has joined the room.`
48
- });
49
-
50
- this.io.to(roomName).emit("chat info", {
51
- name: socket.handshake.query.room,
52
- time: Date.now(),
53
- data: {
54
- users: room.users
55
- }
56
- });
57
-
58
- socket.on("chat message", (msg) => {
59
- this.io.to(roomName).emit("chat message", {
60
- name: msg.name,
61
- time: msg.time,
62
- text: stripHtml(msg.text).result
63
- });
64
- });
65
-
66
- socket.on('disconnect', () => {
67
- room.users.splice(room.users.indexOf(socket.handshake.query.name));
68
-
69
- this.io.to(roomName).emit("chat message", {
70
- name: "Server",
71
- time: Date.now(),
72
- text: `${socket.handshake.query.name} has left the room.`
73
- });
74
-
75
- this.io.to(roomName).emit("chat info", {
76
- name: socket.handshake.query.room,
77
- time: Date.now(),
78
- data: {
79
- users: room.users
80
- }
81
- });
82
-
83
- if (room.users.length < 1) delete this.rooms[roomName];
84
- });
85
- }
86
-
87
- /**
88
- * This API route requests all spirits of a kind from the database.
89
- * @param {Object} req
90
- * @param {Object} res
91
- * @returns {Object} The requested spirits.
92
- */
93
- loadAll = async (req, res) => {
94
- try {
95
- let parent = null;
96
- let data = req.body.data ? req.body.data : {};
97
- let id = req.body.id ? req.body.id : null;
98
-
99
- // if the scope is local, the parent is the user's id
100
- if (req.body.scope === "local") {
101
- let user = await req.db.Spirit.recallOne("user", null, { username: req.session?.currentUser });
102
- if (user?.memory?._id) parent = user.memory._id;
103
- else {
104
- fail(res, "User had no id on load()");
105
- return;
106
- }
107
- }
108
-
109
- // recall all spirits with the given service name and parent
110
- let spirits = await req.db.Spirit.recallAll(req.body.service, parent, data, id);
111
-
112
- res.send(spirits);
113
- } catch (error) {
114
- console.log(error);
115
- fail(res, "Server error");
116
- }
117
- }
118
-
119
- /**
120
- * This API route requests a spirit of a kind from the database.
121
- * @param {Object} req
122
- * @param {Object} res
123
- * @returns {Object} The requested spirit.
124
- */
125
- load = async (req, res) => {
126
- try {
127
- let parent = null;
128
- let data = req.body.data ? req.body.data : {};
129
- let id = req.body.id ? req.body.id : null;
130
-
131
- // if the scope is local, the parent is the user's id
132
- if (req.body.scope === "local") {
133
- let user = await req.db.Spirit.recallOne("user", null, { username: req.session?.currentUser });
134
- if (user?.memory?._id) parent = user.memory._id;
135
- else {
136
- fail(res, "User had no id on load()");
137
- return;
138
- }
139
- }
140
-
141
- // recall all spirits with the given service name and parent
142
- let spirit = await req.db.Spirit.recallOne(req.body.service, parent, data, id);
143
-
144
- res.send(spirit);
145
- } catch (error) {
146
- console.log(error);
147
- fail(res, "Server error");
148
- }
149
- }
150
-
151
- /**
152
- * This API route runs a script on the server. Responds with the result.
153
- * @param {Object} req
154
- * @param {Object} res
155
- */
156
- serve = async (req, res) => {
157
- try {
158
- let scriptPath = `${req.contentPath}${req.body.route}/${req.body.script}.js`;
159
-
160
- let script, result = null;
161
-
162
- if (fs.existsSync(scriptPath)) {
163
- let user = await req.db.Spirit.recallOne("user", null, { username: req.session?.currentUser });
164
-
165
- script = await import(scriptPath);
166
- result = await script.default(req, user, this.io);
167
- success(res, "Served.", result);
168
- }
169
- else fail(res, `Script not found: ${req.body.script} at ${scriptPath}`);
170
- } catch (error) {
171
- console.log(error);
172
- fail(res, "Server error");
173
- }
174
- }
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("/serve", this.serve);
25
+ this.router.use("/user", this.user.router);
26
+ }
27
+
28
+ /**
29
+ * Sets up socket.io for instant messaging and etc.
30
+ * @param {*} socket
31
+ */
32
+ setupChat = (socket) => {
33
+ let roomName = socket.handshake.query.room;
34
+ socket.join(roomName);
35
+ let room = this.rooms[roomName];
36
+ if (room) room.users.push(socket.handshake.query.name);
37
+ else {
38
+ this.rooms[roomName] = {
39
+ users: [ socket.handshake.query.name ]
40
+ }
41
+ room = this.rooms[roomName];
42
+ }
43
+
44
+ this.io.to(roomName).emit("chat message", {
45
+ name: "Server",
46
+ time: Date.now(),
47
+ text: `${socket.handshake.query.name} has joined the room.`
48
+ });
49
+
50
+ this.io.to(roomName).emit("chat info", {
51
+ name: socket.handshake.query.room,
52
+ time: Date.now(),
53
+ data: {
54
+ users: room.users
55
+ }
56
+ });
57
+
58
+ socket.on("chat message", (msg) => {
59
+ this.io.to(roomName).emit("chat message", {
60
+ name: msg.name,
61
+ time: msg.time,
62
+ text: stripHtml(msg.text).result
63
+ });
64
+ });
65
+
66
+ socket.on('disconnect', () => {
67
+ room.users.splice(room.users.indexOf(socket.handshake.query.name));
68
+
69
+ this.io.to(roomName).emit("chat message", {
70
+ name: "Server",
71
+ time: Date.now(),
72
+ text: `${socket.handshake.query.name} has left the room.`
73
+ });
74
+
75
+ this.io.to(roomName).emit("chat info", {
76
+ name: socket.handshake.query.room,
77
+ time: Date.now(),
78
+ data: {
79
+ users: room.users
80
+ }
81
+ });
82
+
83
+ if (room.users.length < 1) delete this.rooms[roomName];
84
+ });
85
+ }
86
+
87
+ /**
88
+ * This API route requests all spirits of a kind from the database.
89
+ * @param {Object} req
90
+ * @param {Object} res
91
+ * @returns {Object} The requested spirits.
92
+ */
93
+ loadAll = async (req, res) => {
94
+ try {
95
+ let parent = null;
96
+ let data = req.body.data ? req.body.data : {};
97
+ let id = req.body.id ? req.body.id : null;
98
+
99
+ // if the scope is local, the parent is the user's id
100
+ if (req.body.scope === "local") {
101
+ let user = await req.db.Spirit.recallOne("user", null, { username: req.session?.currentUser });
102
+ if (user?.memory?._id) parent = user.memory._id;
103
+ else {
104
+ fail(res, "User had no id on load()");
105
+ return;
106
+ }
107
+ }
108
+
109
+ // recall all spirits with the given service name and parent
110
+ let spirits = await req.db.Spirit.recallAll(req.body.service, parent, data, id);
111
+
112
+ res.send(spirits);
113
+ } catch (error) {
114
+ console.log(error);
115
+ fail(res, "Server error");
116
+ }
117
+ }
118
+
119
+ /**
120
+ * This API route requests a spirit of a kind from the database.
121
+ * @param {Object} req
122
+ * @param {Object} res
123
+ * @returns {Object} The requested spirit.
124
+ */
125
+ load = async (req, res) => {
126
+ try {
127
+ let parent = null;
128
+ let data = req.body.data ? req.body.data : {};
129
+ let id = req.body.id ? req.body.id : null;
130
+
131
+ // if the scope is local, the parent is the user's id
132
+ if (req.body.scope === "local") {
133
+ let user = await req.db.Spirit.recallOne("user", null, { username: req.session?.currentUser });
134
+ if (user?.memory?._id) parent = user.memory._id;
135
+ else {
136
+ fail(res, "User had no id on load()");
137
+ return;
138
+ }
139
+ }
140
+
141
+ // recall all spirits with the given service name and parent
142
+ let spirit = await req.db.Spirit.recallOne(req.body.service, parent, data, id);
143
+
144
+ res.send(spirit);
145
+ } catch (error) {
146
+ console.log(error);
147
+ fail(res, "Server error");
148
+ }
149
+ }
150
+
151
+ /**
152
+ * This API route runs a script on the server. Responds with the result.
153
+ * @param {Object} req
154
+ * @param {Object} res
155
+ */
156
+ serve = async (req, res) => {
157
+ try {
158
+ let scriptPath = `${req.contentPath}${req.body.route}/${req.body.script}.js`;
159
+
160
+ let script, result = null;
161
+
162
+ if (fs.existsSync(scriptPath)) {
163
+ let user = await req.db.Spirit.recallOne("user", null, { username: req.session?.currentUser });
164
+
165
+ script = await import(process.env.WINDOWS == "true" ? `file://${scriptPath}` : scriptPath);
166
+ result = await script.default(req, user, this.io);
167
+ success(res, "Served.", result);
168
+ }
169
+ else fail(res, `Script not found: ${req.body.script} at ${scriptPath}`);
170
+ } catch (error) {
171
+ console.log(error);
172
+ fail(res, "Server error");
173
+ }
174
+ }
175
175
  }