notherbase-fs 1.5.3 → 2.0.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/controllers/creation.js +90 -0
- package/controllers/spirit-world.js +110 -0
- package/controllers/spirits/attribute.js +47 -0
- package/controllers/spirits/contact.js +16 -0
- package/controllers/spirits/inventory.js +71 -0
- package/controllers/spirits/item.js +41 -0
- package/controllers/spirits/serve.js +33 -0
- package/controllers/spirits/user.js +130 -0
- package/controllers/spirits/util.js +39 -0
- package/models/index.js +130 -14
- package/models/spirit.js +159 -0
- package/notherbase-fs.js +23 -73
- package/package.json +2 -2
- package/public/js/commune.js +22 -0
- package/public/js/establishment.js +44 -0
- package/public/js/memories.js +29 -30
- package/public/styles/main.css +9 -99
- package/test/explorer/coast/tall-beach/nono-cove/server-scripts/emailTime.js +7 -3
- package/test/explorer/coast/tall-beach/nono-cove/views/index.ejs +38 -60
- package/test/pages/server-scripts/emailTime.js +15 -0
- package/test/pages/test.ejs +30 -3
- package/test/the-front/server-scripts/emailTime.js +7 -3
- package/test/the-front/server-scripts/migrateBig.js +3 -0
- package/test/the-front/views/check.ejs +88 -2
- package/test/the-front/views/index.ejs +43 -101
- package/test-index.js +5 -0
- package/views/account.ejs +25 -36
- package/views/explorer.ejs +48 -1
- package/views/inventory.ejs +41 -99
- package/views/menu.ejs +8 -2
- package/views/more.ejs +8 -14
- package/views/player.ejs +37 -24
- package/controllers/authCheck.js +0 -18
- package/controllers/contact.js +0 -22
- package/controllers/explorer.js +0 -150
- package/controllers/game.js +0 -59
- package/controllers/index.js +0 -10
- package/controllers/inventory.js +0 -116
- package/controllers/item.js +0 -70
- package/controllers/pages.js +0 -33
- package/controllers/the-front.js +0 -70
- package/controllers/user.js +0 -413
- package/controllers/void.js +0 -16
- package/models/chat.js +0 -9
- package/models/contact.js +0 -14
- package/models/detail.js +0 -16
- package/models/game.js +0 -8
- package/models/inventory.js +0 -19
- package/models/item.js +0 -12
- package/models/page.js +0 -14
- package/models/user.js +0 -25
- package/test/test-index.js +0 -5
package/models/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import mongoose from "mongoose";
|
|
2
2
|
import dotenv from "dotenv";
|
|
3
3
|
dotenv.config();
|
|
4
|
+
import Spirit from "./spirit.js";
|
|
5
|
+
import SendMail from "./send-mail.js";
|
|
4
6
|
|
|
5
7
|
mongoose.connection.on('connected', (err) => {
|
|
6
8
|
console.log(`Mongoose connected to db`);
|
|
@@ -14,28 +16,142 @@ mongoose.connection.on('disconnected', () => {
|
|
|
14
16
|
console.log('Mongoose disconnected');
|
|
15
17
|
});
|
|
16
18
|
|
|
17
|
-
let connectionSuccess = false;
|
|
18
|
-
|
|
19
19
|
try {
|
|
20
20
|
mongoose.connect(process.env.MONGODB_URI, {
|
|
21
21
|
useNewUrlParser: true,
|
|
22
22
|
useUnifiedTopology: true
|
|
23
23
|
});
|
|
24
|
-
|
|
25
|
-
connectionSuccess = true;
|
|
26
24
|
}
|
|
27
25
|
catch (err) {
|
|
28
26
|
console.log(`Mongoose on connect: ${err}`);
|
|
29
27
|
}
|
|
30
28
|
|
|
29
|
+
class User extends Spirit {
|
|
30
|
+
constructor(service, email = null) {
|
|
31
|
+
super();
|
|
32
|
+
this.body.route = "/";
|
|
33
|
+
this.body.service = service;
|
|
34
|
+
this.email = email;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
recall = async () => {
|
|
38
|
+
let result = await this.recallFromData("email", this.email);
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
class Item extends Spirit {
|
|
44
|
+
constructor(name = "") {
|
|
45
|
+
super();
|
|
46
|
+
this.body.route = "/";
|
|
47
|
+
this.body.service = "item";
|
|
48
|
+
|
|
49
|
+
this.memory = {
|
|
50
|
+
data: {
|
|
51
|
+
name: name
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
recall = async () => {
|
|
57
|
+
let result = await this.recallFromData("name", this.memory.data.name);
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
commit = async (data = this.memory.data) => {
|
|
62
|
+
let result = await this.commitByData("name", this.memory.data.name, data);
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
delete = async () => {
|
|
67
|
+
let result = await this.deleteByData("name", this.memory.data.name);
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
// migrate
|
|
74
|
+
// const user = mongoose.model('users', new mongoose.Schema({
|
|
75
|
+
// username: String,
|
|
76
|
+
// password: String,
|
|
77
|
+
// email: String,
|
|
78
|
+
// coin: Number,
|
|
79
|
+
// home: String,
|
|
80
|
+
// authLevels: [ String ],
|
|
81
|
+
// location: String,
|
|
82
|
+
// attributes: {
|
|
83
|
+
// translation: Number,
|
|
84
|
+
// strength: Number,
|
|
85
|
+
// agility: Number,
|
|
86
|
+
// defense: Number
|
|
87
|
+
// },
|
|
88
|
+
// reset: {
|
|
89
|
+
// token: Number,
|
|
90
|
+
// exp: Number
|
|
91
|
+
// }
|
|
92
|
+
// }));
|
|
93
|
+
// const page = mongoose.model('pages', new mongoose.Schema({
|
|
94
|
+
// name: String,
|
|
95
|
+
// type: String,
|
|
96
|
+
// user: {
|
|
97
|
+
// type: mongoose.Schema.Types.ObjectId,
|
|
98
|
+
// ref: "users",
|
|
99
|
+
// required: false
|
|
100
|
+
// },
|
|
101
|
+
// data: {}
|
|
102
|
+
// }));
|
|
103
|
+
|
|
104
|
+
// user.find({}, async (err, users) => {
|
|
105
|
+
// for (let i = 0; i < users.length; i++) {
|
|
106
|
+
// let userSpirit = new User("user", users[i].email);
|
|
107
|
+
|
|
108
|
+
// await userSpirit.create({
|
|
109
|
+
// username: users[i].username,
|
|
110
|
+
// password: users[i].password,
|
|
111
|
+
// email: users[i].email,
|
|
112
|
+
// coin: users[i].coin,
|
|
113
|
+
// home: users[i].home,
|
|
114
|
+
// authLevels: users[i].authLevels,
|
|
115
|
+
// location: users[i].location,
|
|
116
|
+
// attributes: users[i].attributes,
|
|
117
|
+
// inventory: []
|
|
118
|
+
// });
|
|
119
|
+
|
|
120
|
+
// let foundPages = await page.find({ user: users[i]._id });
|
|
121
|
+
|
|
122
|
+
// for (let i = 0; i < foundPages.length; i++) {
|
|
123
|
+
// let spirit = new Spirit({
|
|
124
|
+
// route: `/${foundPages[i].name}`,
|
|
125
|
+
// service: foundPages[i].name,
|
|
126
|
+
// scope: foundPages[i].type,
|
|
127
|
+
// parent: userSpirit.memory._id,
|
|
128
|
+
// _lastUpdate: 0,
|
|
129
|
+
// data: foundPages[i].data.tickets
|
|
130
|
+
// });
|
|
131
|
+
|
|
132
|
+
// let found = await spirit.recall();
|
|
133
|
+
|
|
134
|
+
// if (found) {
|
|
135
|
+
// spirit.memory.data.tickets.concat(foundPages[i].data.tickets);
|
|
136
|
+
// await spirit.commit();
|
|
137
|
+
// }
|
|
138
|
+
// else await spirit.create({
|
|
139
|
+
// tickets: foundPages[i].data.tickets
|
|
140
|
+
// });
|
|
141
|
+
// }
|
|
142
|
+
// }
|
|
143
|
+
// });
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
31
151
|
|
|
32
|
-
export
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
export {default as sendMail} from "./send-mail.js";
|
|
39
|
-
export {default as detail} from "./detail.js";
|
|
40
|
-
export {default as page} from "./page.js";
|
|
41
|
-
export { connectionSuccess };
|
|
152
|
+
export default {
|
|
153
|
+
SendMail: SendMail,
|
|
154
|
+
Spirit: Spirit,
|
|
155
|
+
User: User,
|
|
156
|
+
Item: Item
|
|
157
|
+
}
|
package/models/spirit.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import mongoose from "mongoose";
|
|
2
|
+
|
|
3
|
+
export default class Spirit {
|
|
4
|
+
constructor(body = {}) {
|
|
5
|
+
this.body = body;
|
|
6
|
+
if (!this.body.route) this.body.route = "/";
|
|
7
|
+
if (!this.body.service) this.body.service = "default";
|
|
8
|
+
if (!this.body.scope) this.body.scope = "global";
|
|
9
|
+
if (!this.body.parent) this.body.parent = null;
|
|
10
|
+
if (!this.body._lastUpdate) this.body._lastUpdate = 0;
|
|
11
|
+
if (!this.body.data) this.body.data = {};
|
|
12
|
+
this.memory = {
|
|
13
|
+
data: {}
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static db = mongoose.model('spirits', new mongoose.Schema({
|
|
18
|
+
_lastUpdate: Number,
|
|
19
|
+
route: String,
|
|
20
|
+
service: String,
|
|
21
|
+
scope: String,
|
|
22
|
+
parent: {
|
|
23
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
24
|
+
ref: "spirits",
|
|
25
|
+
required: false
|
|
26
|
+
},
|
|
27
|
+
data: {}
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
create = async (data = this.memory.data) => {
|
|
31
|
+
this.time = Date.now();
|
|
32
|
+
|
|
33
|
+
this.memory = await Spirit.db.create({
|
|
34
|
+
route: this.body.route,
|
|
35
|
+
service: this.body.service,
|
|
36
|
+
scope: this.body.scope,
|
|
37
|
+
parent: this.body.parent,
|
|
38
|
+
_lastUpdate: this.time,
|
|
39
|
+
data: data
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
commit = async (data = this.memory.data) => {
|
|
46
|
+
this.time = Date.now();
|
|
47
|
+
|
|
48
|
+
this.memory = await Spirit.db.updateOne({
|
|
49
|
+
route: this.body.route,
|
|
50
|
+
service: this.body.service,
|
|
51
|
+
scope: this.body.scope,
|
|
52
|
+
parent: this.body.parent
|
|
53
|
+
}, {
|
|
54
|
+
route: this.body.route,
|
|
55
|
+
service: this.body.service,
|
|
56
|
+
scope: this.body.scope,
|
|
57
|
+
parent: this.body.parent,
|
|
58
|
+
_lastUpdate: this.time,
|
|
59
|
+
data: data
|
|
60
|
+
}, {
|
|
61
|
+
upsert: true
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
commitByData = async (which, query, data = this.memory.data) => {
|
|
68
|
+
this.time = Date.now();
|
|
69
|
+
|
|
70
|
+
this.memory = await Spirit.db.updateOne({
|
|
71
|
+
route: this.body.route,
|
|
72
|
+
service: this.body.service,
|
|
73
|
+
scope: this.body.scope,
|
|
74
|
+
parent: this.body.parent
|
|
75
|
+
}, {
|
|
76
|
+
route: this.body.route,
|
|
77
|
+
service: this.body.service,
|
|
78
|
+
scope: this.body.scope,
|
|
79
|
+
parent: this.body.parent,
|
|
80
|
+
_lastUpdate: this.time,
|
|
81
|
+
data: data
|
|
82
|
+
}, {
|
|
83
|
+
upsert: true
|
|
84
|
+
}).where(`data.${which}`).equals(query);
|
|
85
|
+
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
recall = async () => {
|
|
90
|
+
let found = await Spirit.db.findOne({
|
|
91
|
+
route: this.body.route,
|
|
92
|
+
service: this.body.service,
|
|
93
|
+
scope: this.body.scope,
|
|
94
|
+
parent: this.body.parent
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
if (found && new Date(found._lastUpdate) > new Date(this.body._lastUpdate)) {
|
|
98
|
+
this.memory = found;
|
|
99
|
+
this.time = found._lastUpdate;
|
|
100
|
+
|
|
101
|
+
return found.data;
|
|
102
|
+
}
|
|
103
|
+
else return false;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
getAll = async () => {
|
|
107
|
+
let found = await Spirit.db.find({
|
|
108
|
+
route: this.body.route,
|
|
109
|
+
service: this.body.service,
|
|
110
|
+
scope: this.body.scope
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
if (found) {
|
|
114
|
+
this.memory = found;
|
|
115
|
+
this.time = found._lastUpdate;
|
|
116
|
+
|
|
117
|
+
let takeout = [];
|
|
118
|
+
for (let i = 0; i < found.length; i++) {
|
|
119
|
+
takeout.push(found[i].data)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return takeout;
|
|
123
|
+
}
|
|
124
|
+
else return false;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
recallFromData = async (which, query) => {
|
|
128
|
+
let found = await Spirit.db.findOne({
|
|
129
|
+
route: this.body.route,
|
|
130
|
+
service: this.body.service
|
|
131
|
+
}).where(`data.${which}`).equals(query);
|
|
132
|
+
|
|
133
|
+
if (found && new Date(found._lastUpdate) > new Date(this.body._lastUpdate)) {
|
|
134
|
+
this.memory = found;
|
|
135
|
+
this.time = found._lastUpdate;
|
|
136
|
+
|
|
137
|
+
return found.data;
|
|
138
|
+
}
|
|
139
|
+
else return false;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
delete = async () => {
|
|
143
|
+
await Spirit.db.findOneAndDelete({
|
|
144
|
+
route: this.body.route,
|
|
145
|
+
service: this.body.service,
|
|
146
|
+
scope: this.body.scope,
|
|
147
|
+
parent: this.body.parent
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
deleteByData = async (which, query) => {
|
|
152
|
+
await Spirit.db.findOneAndDelete({
|
|
153
|
+
route: this.body.route,
|
|
154
|
+
service: this.body.service,
|
|
155
|
+
scope: this.body.scope,
|
|
156
|
+
parent: this.body.parent
|
|
157
|
+
}).where(`data.${which}`).equals(query);
|
|
158
|
+
}
|
|
159
|
+
};
|
package/notherbase-fs.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import dotenv from "dotenv";
|
|
2
2
|
dotenv.config();
|
|
3
|
-
import
|
|
3
|
+
import Models from "./models/index.js";
|
|
4
4
|
import { Server } from "socket.io";
|
|
5
5
|
import express from "express";
|
|
6
6
|
import session from 'express-session';
|
|
@@ -10,17 +10,16 @@ import favicon from 'serve-favicon';
|
|
|
10
10
|
import http from 'http';
|
|
11
11
|
import { fileURLToPath } from 'node:url';
|
|
12
12
|
const __dirname = fileURLToPath(new URL('./', import.meta.url));
|
|
13
|
-
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
import * as controllers from "./controllers/index.js";
|
|
13
|
+
import Creation from "./controllers/creation.js";
|
|
14
|
+
import SpiritWorld from "./controllers/spirit-world.js";
|
|
17
15
|
|
|
18
16
|
class NotherBaseFS {
|
|
19
|
-
constructor(
|
|
17
|
+
constructor(contentPath) {
|
|
20
18
|
this.app = express();
|
|
21
19
|
this.server = http.createServer(this.app);
|
|
22
20
|
this.io = new Server(this.server);
|
|
23
|
-
this.
|
|
21
|
+
this.creation = new Creation();
|
|
22
|
+
this.spiritWorld = new SpiritWorld(this.io);
|
|
24
23
|
|
|
25
24
|
//set views path
|
|
26
25
|
this.app.set("view engine", "ejs");
|
|
@@ -30,7 +29,12 @@ class NotherBaseFS {
|
|
|
30
29
|
this.app.use(methodOverride('_method'));
|
|
31
30
|
|
|
32
31
|
// allows us to use post body data
|
|
33
|
-
this.app.use(express.
|
|
32
|
+
this.app.use(express.json({
|
|
33
|
+
extended: true,
|
|
34
|
+
inflate: true,
|
|
35
|
+
type: 'application/x-www-form-urlencoded'
|
|
36
|
+
}));
|
|
37
|
+
//this.app.use(express.urlencoded({ extended: true }));
|
|
34
38
|
|
|
35
39
|
// allows us to get static files like css
|
|
36
40
|
this.app.use(express.static('public'));
|
|
@@ -40,76 +44,22 @@ class NotherBaseFS {
|
|
|
40
44
|
this.app.use(favicon(__dirname + '/public/img/logo.png'));
|
|
41
45
|
|
|
42
46
|
//enable cookies
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}));
|
|
50
|
-
|
|
51
|
-
console.log("sessions enabled");
|
|
52
|
-
}
|
|
53
|
-
else console.log("sessions disabled");
|
|
54
|
-
|
|
55
|
-
this.io.on('connection', (socket) => {
|
|
56
|
-
socket.join(socket.handshake.query.room);
|
|
57
|
-
|
|
58
|
-
this.io.to(socket.handshake.query.room).emit("chat message", {
|
|
59
|
-
name: "Server",
|
|
60
|
-
time: Date.now(),
|
|
61
|
-
text: `${socket.handshake.query.name} has joined the room.`
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
socket.on("chat message", (msg) => {
|
|
65
|
-
this.io.to(socket.handshake.query.room).emit("chat message", {
|
|
66
|
-
name: msg.name,
|
|
67
|
-
time: msg.time,
|
|
68
|
-
text: stripHtml(msg.text).result
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
socket.on('disconnect', () => {
|
|
73
|
-
this.io.to(socket.handshake.query.room).emit("chat message", {
|
|
74
|
-
name: "Server",
|
|
75
|
-
time: Date.now(),
|
|
76
|
-
text: `${socket.handshake.query.name} has left the room.`
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
});
|
|
47
|
+
this.app.use(session({
|
|
48
|
+
store: MongoStore.create({ mongoUrl: process.env.MONGODB_URI }),
|
|
49
|
+
secret: process.env.SECRET,
|
|
50
|
+
resave: false,
|
|
51
|
+
saveUninitialized: false
|
|
52
|
+
}));
|
|
80
53
|
|
|
81
54
|
this.app.use((req, res, next) => {
|
|
82
|
-
req.db =
|
|
83
|
-
req.
|
|
84
|
-
req.frontDir = frontPath;
|
|
85
|
-
req.pagesDir = pagesPath;
|
|
86
|
-
req.voidDir = voidPath;
|
|
87
|
-
|
|
55
|
+
req.db = Models;
|
|
56
|
+
req.contentPath = contentPath;
|
|
88
57
|
next();
|
|
89
58
|
});
|
|
90
|
-
|
|
91
|
-
this.app.use("/user", controllers.user);
|
|
92
|
-
|
|
93
|
-
this.app.use("/contact", controllers.contact);
|
|
94
|
-
|
|
95
|
-
this.app.use("/game", controllers.game);
|
|
96
|
-
|
|
97
|
-
this.app.use("/inventory", controllers.authCheck, controllers.inventory);
|
|
98
|
-
|
|
99
|
-
this.app.use("/item", controllers.item);
|
|
100
|
-
|
|
101
|
-
this.app.use("/the-front", controllers.front);
|
|
102
|
-
|
|
103
|
-
this.app.use("/", controllers.pages);
|
|
104
|
-
|
|
105
|
-
this.app.use("/", controllers.authCheck, controllers.explorer);
|
|
106
|
-
|
|
107
|
-
// start location
|
|
108
|
-
this.app.get("/", function(req, res) {
|
|
109
|
-
res.redirect("/the-front");
|
|
110
|
-
});
|
|
111
59
|
|
|
112
|
-
this.app.use(
|
|
60
|
+
this.app.use("/s", this.spiritWorld.router);
|
|
61
|
+
|
|
62
|
+
this.app.use("/", this.creation.router);
|
|
113
63
|
|
|
114
64
|
this.server.listen(process.env.PORT, function () {
|
|
115
65
|
console.log(`Server started at ${process.env.PORT}`);
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "notherbase-fs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Functions to help make developing for NotherBase easier.",
|
|
5
5
|
"exports": "./notherbase-fs.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "nodemon test
|
|
7
|
+
"test": "nodemon test-index.js",
|
|
8
8
|
"gmail-auth": "node gmail-auth.js",
|
|
9
9
|
"gmail-token": "node gmail-token.js"
|
|
10
10
|
},
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const commune = async (action, data = null, options) => {
|
|
2
|
+
try {
|
|
3
|
+
let body = {
|
|
4
|
+
action,
|
|
5
|
+
data,
|
|
6
|
+
...options
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
let response = null;
|
|
10
|
+
|
|
11
|
+
let onResponse = (res) => {
|
|
12
|
+
response = res;
|
|
13
|
+
if (res.status != "success") console.log(`${res.status}: ${res.message}`, res.data);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
await $.post("/s", JSON.stringify(body), onResponse);
|
|
17
|
+
|
|
18
|
+
return response;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
return error;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
class Establishment {
|
|
2
|
+
constructor() {
|
|
3
|
+
this._lastUpdate = 0;
|
|
4
|
+
this.data = {};
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
load = async (service, route = currentRoute) => {
|
|
8
|
+
if (!this.data[service]) this.data[service] = { _lastUpdate: 0 };
|
|
9
|
+
|
|
10
|
+
let response = await commune("recall", {}, {
|
|
11
|
+
service: service,
|
|
12
|
+
_lastUpdate: this.data[service]._lastUpdate,
|
|
13
|
+
route: route,
|
|
14
|
+
scope: "global",
|
|
15
|
+
parent: null
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
if (!response.isUpToDate) {
|
|
19
|
+
this.data[service] = response.data;
|
|
20
|
+
this._lastUpdate = this.data[service]._lastUpdate;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return this.data[service];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
save = async (service, dataToSave, route = currentRoute) => {
|
|
27
|
+
this._lastUpdate = Date.now();
|
|
28
|
+
dataToSave._lastUpdate = this._lastUpdate;
|
|
29
|
+
|
|
30
|
+
let response = await commune("commit", dataToSave, {
|
|
31
|
+
service: service,
|
|
32
|
+
_lastUpdate: this._lastUpdate,
|
|
33
|
+
route: route,
|
|
34
|
+
scope: "global",
|
|
35
|
+
parent: null
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
this.data[service] = dataToSave;
|
|
39
|
+
|
|
40
|
+
return response;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const establishment = new Establishment();
|
package/public/js/memories.js
CHANGED
|
@@ -4,41 +4,40 @@ class Memories {
|
|
|
4
4
|
this.data = {};
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
load = async (service, route = currentRoute) => {
|
|
8
|
-
|
|
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
|
-
});
|
|
7
|
+
load = async (service, route = currentRoute, parent = null) => {
|
|
8
|
+
if (!this.data[service]) this.data[service] = { _lastUpdate: 0 };
|
|
19
9
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
let response = await commune("recall", {}, {
|
|
11
|
+
service: service,
|
|
12
|
+
_lastUpdate: this.data[service]._lastUpdate,
|
|
13
|
+
route: route,
|
|
14
|
+
scope: "local",
|
|
15
|
+
parent: parent
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
if (!response.isUpToDate) {
|
|
19
|
+
this.data[service] = response.data;
|
|
20
|
+
this._lastUpdate = this.data[service]._lastUpdate;
|
|
23
21
|
}
|
|
22
|
+
|
|
23
|
+
return this.data[service];
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
save = async (service, dataToSave, route = currentRoute) => {
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
save = async (service, dataToSave, route = currentRoute, parent = null) => {
|
|
27
|
+
this._lastUpdate = Date.now();
|
|
28
|
+
dataToSave._lastUpdate = this._lastUpdate;
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
30
|
+
let response = await commune("commit", dataToSave, {
|
|
31
|
+
service: service,
|
|
32
|
+
_lastUpdate: this._lastUpdate,
|
|
33
|
+
route: route,
|
|
34
|
+
scope: "local",
|
|
35
|
+
parent: parent
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
this.data[service] = dataToSave;
|
|
39
|
+
|
|
40
|
+
return response;
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
43
|
|