notherbase-fs 3.0.7 → 3.0.9
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/controllers/creation.js +1 -1
- package/controllers/spirit-world.js +6 -16
- package/models/item.js +3 -21
- package/models/spirit.js +18 -39
- package/models/user.js +6 -21
- package/package.json +1 -1
- package/test/the-front/check/index.ejs +18 -1
- package/test/the-front/check/save-input.js +7 -0
- package/views/scripts/base.js +7 -8
- /package/test/{test-page → pages/test-page}/emailTime.js +0 -0
- /package/test/{test-page → pages/test-page}/index.ejs +0 -0
package/controllers/creation.js
CHANGED
|
@@ -47,24 +47,14 @@ export default class SpiritWorld {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
load = async (req, res) => {
|
|
50
|
-
let user = await req.db.User.recallOne(req.session.currentUser);
|
|
51
|
-
|
|
52
50
|
let parent = null;
|
|
53
|
-
if (req.query.scope === "local" && user) parent = user.id;
|
|
54
51
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
parent: parent
|
|
60
|
-
});
|
|
52
|
+
if (req.query.scope === "local") {
|
|
53
|
+
let user = await req.db.User.recallOne(req.session.currentUser);
|
|
54
|
+
parent = user.id;
|
|
55
|
+
}
|
|
61
56
|
|
|
62
|
-
|
|
63
|
-
route: req.query.route,
|
|
64
|
-
service: req.query.service,
|
|
65
|
-
scope: req.query.scope,
|
|
66
|
-
parent: parent
|
|
67
|
-
}, {});
|
|
57
|
+
let spirit = await req.db.Spirit.recallOne(req.query.service, parent);
|
|
68
58
|
|
|
69
59
|
if (!spirit.memory.data) spirit.memory.data = {};
|
|
70
60
|
|
|
@@ -73,7 +63,7 @@ export default class SpiritWorld {
|
|
|
73
63
|
|
|
74
64
|
serve = async (req, res) => {
|
|
75
65
|
try {
|
|
76
|
-
let scriptPath = `${req.contentPath}${req.body.route}/${req.body.data.script}.js`;
|
|
66
|
+
let scriptPath = `${req.contentPath}${req.body.data.route}/${req.body.data.script}.js`;
|
|
77
67
|
|
|
78
68
|
let script, result = null;
|
|
79
69
|
|
package/models/item.js
CHANGED
|
@@ -5,10 +5,8 @@ export default class Item extends Spirit {
|
|
|
5
5
|
let spirit = new Item(name);
|
|
6
6
|
|
|
7
7
|
spirit.memory = await Spirit.db.create({
|
|
8
|
-
route: "/",
|
|
9
8
|
service: "items",
|
|
10
9
|
parent: null,
|
|
11
|
-
scope: "global",
|
|
12
10
|
_lastUpdate: Date.now(),
|
|
13
11
|
data: {
|
|
14
12
|
name,
|
|
@@ -24,10 +22,8 @@ export default class Item extends Spirit {
|
|
|
24
22
|
let spirit = new Item();
|
|
25
23
|
|
|
26
24
|
let found = await Spirit.db.find({
|
|
27
|
-
route: "/",
|
|
28
25
|
service: "items",
|
|
29
|
-
parent: null
|
|
30
|
-
scope: "global"
|
|
26
|
+
parent: null
|
|
31
27
|
});
|
|
32
28
|
|
|
33
29
|
if (found) {
|
|
@@ -41,14 +37,7 @@ export default class Item extends Spirit {
|
|
|
41
37
|
static recallOne = async (name) => {
|
|
42
38
|
let spirit = new Item(name);
|
|
43
39
|
|
|
44
|
-
let query = Spirit.buildQuery({
|
|
45
|
-
route: "/",
|
|
46
|
-
service: "items",
|
|
47
|
-
parent: null,
|
|
48
|
-
scope: "global"
|
|
49
|
-
}, {
|
|
50
|
-
name: name
|
|
51
|
-
});
|
|
40
|
+
let query = Spirit.buildQuery("items", { name });
|
|
52
41
|
|
|
53
42
|
let found = await Spirit.db.findOne(query);
|
|
54
43
|
|
|
@@ -61,14 +50,7 @@ export default class Item extends Spirit {
|
|
|
61
50
|
}
|
|
62
51
|
|
|
63
52
|
static delete = async (name) => {
|
|
64
|
-
let found = await Spirit.db.findAndDelete(Spirit.buildQuery({
|
|
65
|
-
route: "/",
|
|
66
|
-
service: "items",
|
|
67
|
-
parent: null,
|
|
68
|
-
scope: "global"
|
|
69
|
-
}, {
|
|
70
|
-
name: name
|
|
71
|
-
}));
|
|
53
|
+
let found = await Spirit.db.findAndDelete(Spirit.buildQuery("items", { name }));
|
|
72
54
|
|
|
73
55
|
return found.deletedCount;
|
|
74
56
|
}
|
package/models/spirit.js
CHANGED
|
@@ -3,9 +3,7 @@ import mongoose from "mongoose";
|
|
|
3
3
|
export default class Spirit {
|
|
4
4
|
static db = mongoose.model('spirits', new mongoose.Schema({
|
|
5
5
|
_lastUpdate: Number,
|
|
6
|
-
route: String,
|
|
7
6
|
service: String,
|
|
8
|
-
scope: String,
|
|
9
7
|
parent: {
|
|
10
8
|
type: mongoose.Schema.Types.ObjectId,
|
|
11
9
|
ref: "spirits",
|
|
@@ -14,16 +12,14 @@ export default class Spirit {
|
|
|
14
12
|
data: {}
|
|
15
13
|
}));
|
|
16
14
|
|
|
17
|
-
static buildQuery = (
|
|
18
|
-
let query = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
_id: id
|
|
22
|
-
};
|
|
23
|
-
if (options) query = {
|
|
24
|
-
...query,
|
|
25
|
-
...options
|
|
15
|
+
static buildQuery = (service, data = null, parent = null, id = null) => {
|
|
16
|
+
let query = {
|
|
17
|
+
service: service,
|
|
18
|
+
parent: parent
|
|
26
19
|
};
|
|
20
|
+
|
|
21
|
+
if (id) query._id = id;
|
|
22
|
+
|
|
27
23
|
if (data){
|
|
28
24
|
let keys = Object.keys(data);
|
|
29
25
|
for (let i = 0; i < keys.length; i++) {
|
|
@@ -34,11 +30,12 @@ export default class Spirit {
|
|
|
34
30
|
return query;
|
|
35
31
|
}
|
|
36
32
|
|
|
37
|
-
static create = async (
|
|
33
|
+
static create = async (service, data = {}, parent = null) => {
|
|
38
34
|
let spirit = new Spirit();
|
|
39
35
|
|
|
40
36
|
spirit.memory = await Spirit.db.create({
|
|
41
|
-
|
|
37
|
+
service,
|
|
38
|
+
parent,
|
|
42
39
|
_lastUpdate: Date.now(),
|
|
43
40
|
data: data
|
|
44
41
|
});
|
|
@@ -46,54 +43,36 @@ export default class Spirit {
|
|
|
46
43
|
return spirit;
|
|
47
44
|
}
|
|
48
45
|
|
|
49
|
-
static
|
|
46
|
+
static recallAll = async (service) => {
|
|
50
47
|
let spirit = new Spirit();
|
|
51
48
|
|
|
52
|
-
let query = Spirit.buildQuery(
|
|
53
|
-
|
|
54
|
-
let found = await Spirit.db.find(query);
|
|
49
|
+
let query = Spirit.buildQuery(service);
|
|
55
50
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return spirit;
|
|
61
|
-
}
|
|
62
|
-
else return null;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
static recallOne = async (options = {}, data = {}, id = null) => {
|
|
66
|
-
let spirit = new Spirit();
|
|
67
|
-
|
|
68
|
-
let query = Spirit.buildQuery(options, data, id);
|
|
69
|
-
|
|
70
|
-
let found = await Spirit.db.findOne(query);
|
|
51
|
+
let found = await Spirit.db.find({
|
|
52
|
+
service: service
|
|
53
|
+
});
|
|
71
54
|
|
|
72
55
|
if (found) {
|
|
73
56
|
spirit.memory = found;
|
|
74
|
-
if (!spirit.memory.data) spirit.memory.data = {};
|
|
75
57
|
|
|
76
58
|
return spirit;
|
|
77
59
|
}
|
|
78
60
|
else return null;
|
|
79
61
|
}
|
|
80
62
|
|
|
81
|
-
static
|
|
63
|
+
static recallOne = async (service, parent = null, data = {}, id = null) => {
|
|
82
64
|
let spirit = new Spirit();
|
|
83
65
|
|
|
84
|
-
let query = Spirit.buildQuery(
|
|
66
|
+
let query = Spirit.buildQuery(service, data, parent, id);
|
|
85
67
|
|
|
86
68
|
let found = await Spirit.db.findOne(query);
|
|
87
69
|
|
|
88
70
|
if (found) {
|
|
89
71
|
spirit.memory = found;
|
|
90
|
-
if (!spirit.memory.data) spirit.memory.data = {};
|
|
91
|
-
|
|
92
72
|
return spirit;
|
|
93
73
|
}
|
|
94
74
|
else {
|
|
95
|
-
|
|
96
|
-
let newSpirit = await Spirit.create(options, initdata);
|
|
75
|
+
let newSpirit = await Spirit.create(service, {}, parent);
|
|
97
76
|
return newSpirit;
|
|
98
77
|
}
|
|
99
78
|
}
|
package/models/user.js
CHANGED
|
@@ -3,34 +3,19 @@ import Item from "./item.js";
|
|
|
3
3
|
import bcrypt from "bcrypt";
|
|
4
4
|
|
|
5
5
|
export default class User extends Spirit {
|
|
6
|
-
static recallOne = async (
|
|
7
|
-
let spirit = new User(
|
|
6
|
+
static recallOne = async (email = null, username = null, id = null) => {
|
|
7
|
+
let spirit = new User(email, id);
|
|
8
8
|
|
|
9
9
|
let query = null;
|
|
10
10
|
|
|
11
|
-
if (
|
|
12
|
-
query = Spirit.buildQuery({
|
|
13
|
-
route: "/",
|
|
14
|
-
service: "user",
|
|
15
|
-
scope: "global",
|
|
16
|
-
parent: null
|
|
17
|
-
}, { email: target });
|
|
11
|
+
if (email) {
|
|
12
|
+
query = Spirit.buildQuery("user", { email: email });
|
|
18
13
|
}
|
|
19
14
|
else if (username) {
|
|
20
|
-
query = Spirit.buildQuery({
|
|
21
|
-
route: "/",
|
|
22
|
-
service: "user",
|
|
23
|
-
scope: "global",
|
|
24
|
-
parent: null
|
|
25
|
-
}, { username: username });
|
|
15
|
+
query = Spirit.buildQuery("user", { username: username });
|
|
26
16
|
}
|
|
27
17
|
else if (id) {
|
|
28
|
-
query = Spirit.buildQuery(
|
|
29
|
-
route: "/",
|
|
30
|
-
service: "user",
|
|
31
|
-
scope: "global",
|
|
32
|
-
parent: null
|
|
33
|
-
}, null, id);
|
|
18
|
+
query = Spirit.buildQuery("user", null, null, id);
|
|
34
19
|
}
|
|
35
20
|
|
|
36
21
|
let found = null;
|
package/package.json
CHANGED
|
@@ -5,9 +5,26 @@
|
|
|
5
5
|
<button onclick="base.do('add-more-gold')">+3</button>
|
|
6
6
|
<button onclick="base.do('subtract-gold')">-30</button>
|
|
7
7
|
<button onclick="base.do('emailTime')">email</button>
|
|
8
|
+
<input type="text" id="test" placeholder="Loading...">
|
|
9
|
+
<button onclick="saveInput()">Save</button>
|
|
8
10
|
|
|
9
11
|
<hr>
|
|
10
12
|
|
|
11
13
|
<a href="/the-front">
|
|
12
14
|
Go to The Front
|
|
13
|
-
</a>
|
|
15
|
+
</a>
|
|
16
|
+
|
|
17
|
+
<script>
|
|
18
|
+
const $inp = $("input#test");
|
|
19
|
+
|
|
20
|
+
base.load("test-save3").then((res) => {
|
|
21
|
+
if (res.text) $inp.attr("placeholder", res.text);
|
|
22
|
+
else $inp.attr("placeholder", "No Input Saved");
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const saveInput = function saveInput() {
|
|
26
|
+
let inp = $inp.val();
|
|
27
|
+
|
|
28
|
+
base.do("save-input", { text: inp });
|
|
29
|
+
}
|
|
30
|
+
</script>
|
package/views/scripts/base.js
CHANGED
|
@@ -288,23 +288,22 @@ class Base {
|
|
|
288
288
|
return response;
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
-
do = async (what, data = null
|
|
292
|
-
|
|
291
|
+
do = async (what, data = null) => {
|
|
292
|
+
console.log(window.location.pathname);
|
|
293
|
+
let response = await Base.commune("/s/serve", {
|
|
293
294
|
script: what,
|
|
294
|
-
...data
|
|
295
|
-
|
|
296
|
-
route
|
|
295
|
+
...data,
|
|
296
|
+
route: window.location.pathname
|
|
297
297
|
});
|
|
298
298
|
|
|
299
299
|
this.playerInventory.refresh();
|
|
300
300
|
this.playerAttributes.refresh();
|
|
301
|
-
|
|
302
|
-
await response;
|
|
301
|
+
|
|
303
302
|
return response;
|
|
304
303
|
}
|
|
305
304
|
|
|
306
305
|
load = async (service, scope = "local") => {
|
|
307
|
-
let response = await $.get("/s/load", { service, scope
|
|
306
|
+
let response = await $.get("/s/load", { service, scope });
|
|
308
307
|
|
|
309
308
|
return response;
|
|
310
309
|
}
|
|
File without changes
|
|
File without changes
|