notherbase-fs 1.4.4 → 1.5.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.
@@ -1,11 +1,11 @@
1
- const express = require("express");
1
+ import express from "express";
2
2
  const router = express.Router();
3
- const bcrypt = require("bcrypt");
3
+ import bcrypt from "bcrypt";
4
4
 
5
5
  // Import my Data
6
- const { user, inventory, sendMail } = require("../models");
6
+ import { user, inventory, sendMail } from "../models/index.js";
7
7
 
8
- const authCheck = require("./authCheck");
8
+ import authCheck from "./authCheck.js";
9
9
 
10
10
  let getAttributes = async function getAttributes(userID) {
11
11
  try {
@@ -410,5 +410,4 @@ router.delete("/", authCheck, async function(req, res) {
410
410
  }
411
411
  });
412
412
 
413
- module.exports = router;
414
-
413
+ export default router;
@@ -0,0 +1,16 @@
1
+ import express from "express";
2
+ let router = express.Router();
3
+
4
+ //the void
5
+ router.use(function(req, res){
6
+ res.render(`explorer`,
7
+ {
8
+ siteTitle: "NotherBase | The Void",
9
+ user: null,
10
+ inventory: null,
11
+ main: `${req.voidDir}/index`,
12
+ route: `/void`
13
+ });
14
+ });
15
+
16
+ export default router;
package/models/chat.js CHANGED
@@ -1,9 +1,9 @@
1
- const mongoose = require("mongoose");
1
+ import mongoose from "mongoose";
2
2
 
3
- const chatSchema = new mongoose.Schema({
3
+ const chat = mongoose.model('chats', new mongoose.Schema({
4
4
  name: String,
5
5
  text: String,
6
6
  date: Number
7
- });
7
+ }));
8
8
 
9
- module.exports = mongoose.model('chat', chatSchema);
9
+ export default chat;
package/models/contact.js CHANGED
@@ -1,8 +1,7 @@
1
- // This allows us to use Mongoose to connect to MongoDB
2
- const mongoose = require("mongoose");
1
+ import mongoose from "mongoose";
3
2
 
4
3
  // This shows the kind of documents we're interacting with in the db
5
- const contact = new mongoose.Schema({
4
+ const contact = mongoose.model('contacts', new mongoose.Schema({
6
5
  user: {
7
6
  type: mongoose.Schema.Types.ObjectId,
8
7
  ref: "users",
@@ -10,8 +9,6 @@ const contact = new mongoose.Schema({
10
9
  },
11
10
  location: String,
12
11
  content: String
13
- });
12
+ }));
14
13
 
15
- // This tells Mongoose to use the exampleSchema to access the examples collection
16
- // in our db and then exports the model so we can use it.
17
- module.exports = mongoose.model('contacts', contact);
14
+ export default contact;
package/models/detail.js CHANGED
@@ -1,7 +1,6 @@
1
- // This allows us to use Mongoose to connect to MongoDB
2
- const mongoose = require("mongoose");
1
+ import mongoose from "mongoose";
3
2
 
4
- const detail = new mongoose.Schema({
3
+ const detail = mongoose.model('details', new mongoose.Schema({
5
4
  _lastUpdate: Number,
6
5
  route: String,
7
6
  service: String,
@@ -12,8 +11,6 @@ const detail = new mongoose.Schema({
12
11
  required: false
13
12
  },
14
13
  data: {}
15
- });
14
+ }));
16
15
 
17
- // This tells Mongoose to use the exampleSchema to access the examples collection
18
- // in our db and then exports the model so we can use it.
19
- module.exports = mongoose.model('details', detail);
16
+ export default detail;
package/models/game.js CHANGED
@@ -1,11 +1,8 @@
1
- // This allows us to use Mongoose to connect to MongoDB
2
- const mongoose = require("mongoose");
1
+ import mongoose from "mongoose";
3
2
 
4
- const game = new mongoose.Schema({
3
+ const game = mongoose.model('games', new mongoose.Schema({
5
4
  name: String,
6
5
  data: {}
7
- });
6
+ }));
8
7
 
9
- // This tells Mongoose to use the exampleSchema to access the examples collection
10
- // in our db and then exports the model so we can use it.
11
- module.exports = mongoose.model('games', game);
8
+ export default game;
package/models/index.js CHANGED
@@ -1,12 +1,41 @@
1
- module.exports = {
2
- connectionSuccess: require("./start-mongoose"),
3
- chat: require("./chat"),
4
- item: require("./item"),
5
- user: require("./user"),
6
- contact: require("./contact"),
7
- inventory: require("./inventory"),
8
- game: require("./game"),
9
- sendMail: require("./send-mail"),
10
- detail: require("./detail"),
11
- page: require("./page")
1
+ import mongoose from "mongoose";
2
+ import dotenv from "dotenv";
3
+ dotenv.config();
4
+
5
+ mongoose.connection.on('connected', (err) => {
6
+ console.log(`Mongoose connected to db`);
7
+ });
8
+
9
+ mongoose.connection.on('error', (err) => {
10
+ console.log(`Mongoose ${err}`);
11
+ });
12
+
13
+ mongoose.connection.on('disconnected', () => {
14
+ console.log('Mongoose disconnected');
15
+ });
16
+
17
+ let connectionSuccess = false;
18
+
19
+ try {
20
+ mongoose.connect(process.env.MONGODB_URI, {
21
+ useNewUrlParser: true,
22
+ useUnifiedTopology: true
23
+ });
24
+
25
+ connectionSuccess = true;
12
26
  }
27
+ catch (err) {
28
+ console.log(`Mongoose on connect: ${err}`);
29
+ }
30
+
31
+
32
+ export {default as chat} from "./chat.js";
33
+ export {default as item} from "./item.js";
34
+ export {default as user} from "./user.js";
35
+ export {default as contact} from "./contact.js";
36
+ export {default as inventory} from "./inventory.js";
37
+ export {default as game} from "./game.js";
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 };
@@ -1,8 +1,7 @@
1
- // This allows us to use Mongoose to connect to MongoDB
2
- const mongoose = require("mongoose");
1
+ import mongoose from "mongoose";
3
2
 
4
3
  // This shows the kind of documents we're interacting with in the db
5
- const inventory = new mongoose.Schema({
4
+ const inventory = mongoose.model('inventories', new mongoose.Schema({
6
5
  user: {
7
6
  type: mongoose.Schema.Types.ObjectId,
8
7
  ref: "users",
@@ -15,8 +14,6 @@ const inventory = new mongoose.Schema({
15
14
  },
16
15
  amount: Number
17
16
  }]
18
- });
17
+ }));
19
18
 
20
- // This tells Mongoose to use the exampleSchema to access the examples collection
21
- // in our db and then exports the model so we can use it.
22
- module.exports = mongoose.model('inventories', inventory);
19
+ export default inventory;
package/models/item.js CHANGED
@@ -1,15 +1,12 @@
1
- // This allows us to use Mongoose to connect to MongoDB
2
- const mongoose = require("mongoose");
1
+ import mongoose from "mongoose";
3
2
 
4
- const item = new mongoose.Schema({
3
+ const item = mongoose.model('items', new mongoose.Schema({
5
4
  name: String,
6
5
  shortDescription: String,
7
6
  fullDescription: String,
8
7
  icon: String,
9
8
  tags: [ String ],
10
9
  image: String
11
- });
10
+ }));
12
11
 
13
- // This tells Mongoose to use the exampleSchema to access the examples collection
14
- // in our db and then exports the model so we can use it.
15
- module.exports = mongoose.model('items', item);
12
+ export default item;
package/models/page.js CHANGED
@@ -1,6 +1,6 @@
1
- const mongoose = require("mongoose");
1
+ import mongoose from "mongoose";
2
2
 
3
- const page = new mongoose.Schema({
3
+ const page = mongoose.model('pages', new mongoose.Schema({
4
4
  name: String,
5
5
  type: String,
6
6
  user: {
@@ -9,6 +9,6 @@ const page = new mongoose.Schema({
9
9
  required: false
10
10
  },
11
11
  data: {}
12
- });
12
+ }));
13
13
 
14
- module.exports = mongoose.model('pages', page);
14
+ export default page;
@@ -1,4 +1,4 @@
1
- const nodemailer = require("nodemailer");
1
+ import nodemailer from "nodemailer";
2
2
 
3
3
  const passwordReset = async (toEmail, resetToken) => {
4
4
  var transporter = nodemailer.createTransport({
@@ -42,7 +42,5 @@ const send = async (toEmail, subject, html) => {
42
42
  });
43
43
  }
44
44
 
45
- module.exports = {
46
- passwordReset: passwordReset,
47
- send: send
48
- };
45
+
46
+ export default { passwordReset, send };
package/models/user.js CHANGED
@@ -1,8 +1,7 @@
1
- const mongoose = require("mongoose");
1
+ import mongoose from "mongoose";
2
2
 
3
3
  //convert schema to model
4
- const user = mongoose.model('users',
5
- new mongoose.Schema({
4
+ const user = mongoose.model('users', new mongoose.Schema({
6
5
  username: String,
7
6
  password: String,
8
7
  email: String,
@@ -23,4 +22,4 @@ const user = mongoose.model('users',
23
22
  })
24
23
  );
25
24
 
26
- module.exports = user;
25
+ export default user;
package/notherbase-fs.js CHANGED
@@ -1,91 +1,116 @@
1
- require("dotenv").config();
1
+ import dotenv from "dotenv";
2
+ dotenv.config();
3
+ import * as db from "./models/index.js";
4
+ import { Server } from "socket.io";
5
+ import express from "express";
6
+ import session from 'express-session';
7
+ import methodOverride from 'method-override';
8
+ import MongoStore from 'connect-mongo';
9
+ import favicon from 'serve-favicon';
10
+ import http from 'http';
11
+ import { fileURLToPath } from 'node:url';
12
+ const __dirname = fileURLToPath(new URL('./', import.meta.url));
2
13
 
3
- class NotherBaseFS {
4
- constructor() {
5
- this.express = require("express");
6
- this.session = require('express-session');
7
- this.methodOverride = require('method-override');
8
- this.MongoStore = require('connect-mongo');
9
- this.favicon = require('serve-favicon');
10
- this.http = require('http');
11
- this.app = this.express();
12
- this.server = this.http.createServer(this.app);
13
- this.io = new (require("socket.io").Server)(this.server);
14
- this.db = require("./models");
15
- this.started = false;
16
- }
14
+ import { stripHtml } from "string-strip-html";
17
15
 
18
- async start(worldPath, voidPath, frontPath, pagesPath) {
19
- if (!this.started) {
20
- //set views path
21
- this.app.set("view engine", "ejs");
22
- this.app.set("views", `${__dirname}/views`);
23
-
24
- // allows us to delete
25
- this.app.use(this.methodOverride('_method'));
16
+ import * as controllers from "./controllers/index.js";
26
17
 
27
- // allows us to use post body data
28
- this.app.use(this.express.urlencoded({ extended: true }));
29
-
30
- // allows us to get static files like css
31
- this.app.use(this.express.static('public'));
32
- this.app.use(this.express.static(`${__dirname}/public`));
33
-
34
- // sets the favicon image
35
- this.app.use(this.favicon(__dirname + '/public/img/logo.png'));
36
-
37
- // Import my Controller
38
- const controllers = require("./controllers");
39
-
40
- //enable cookies
41
- if (this.db.connectionSuccess) {
42
- this.app.use(this.session({
43
- store: this.MongoStore.create({ mongoUrl: process.env.MONGODB_URI }),
44
- secret: process.env.SECRET || "won",
45
- resave: false,
46
- saveUninitialized: false
47
- }));
48
-
49
- console.log("sessions enabled");
50
- }
51
- else console.log("sessions disabled");
18
+ class NotherBaseFS {
19
+ constructor(worldPath, voidPath, frontPath, pagesPath) {
20
+ this.app = express();
21
+ this.server = http.createServer(this.app);
22
+ this.io = new Server(this.server);
23
+ this.db = db;
52
24
 
53
- this.io.on('connection', (socket) => {
54
- socket.join(socket.handshake.query.room);
55
-
56
- console.log(socket.rooms);
57
-
58
- socket.to(socket.handshake.query.room).emit(`${socket.handshake.query.name} has joined the room`);
25
+ //set views path
26
+ this.app.set("view engine", "ejs");
27
+ this.app.set("views", `${__dirname}/views`);
28
+
29
+ // allows us to delete
30
+ this.app.use(methodOverride('_method'));
31
+
32
+ // allows us to use post body data
33
+ this.app.use(express.urlencoded({ extended: true }));
34
+
35
+ // allows us to get static files like css
36
+ this.app.use(express.static('public'));
37
+ this.app.use(express.static(`${__dirname}/public`));
38
+
39
+ // sets the favicon image
40
+ this.app.use(favicon(__dirname + '/public/img/logo.png'));
41
+
42
+ //enable cookies
43
+ if (this.db.connectionSuccess) {
44
+ this.app.use(session({
45
+ store: MongoStore.create({ mongoUrl: process.env.MONGODB_URI }),
46
+ secret: process.env.SECRET,
47
+ resave: false,
48
+ saveUninitialized: false
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);
59
57
 
60
- socket.on('disconnect', () => {});
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.`
61
62
  });
62
63
 
63
- this.app.use("/user", controllers.user);
64
-
65
- this.app.use("/chat", controllers.chat(this.io));
66
-
67
- this.app.use("/contact", controllers.contact);
68
-
69
- this.app.use("/game", controllers.game);
70
-
71
- this.app.use("/inventory", controllers.authCheck, controllers.inventory);
72
-
73
- this.app.use("/item", controllers.item);
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
+ });
74
71
 
75
- this.app.use("/the-front", await controllers.front(frontPath));
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
+ });
76
80
 
77
- this.app.use("/", controllers.pages(pagesPath));
81
+ this.app.use((req, res, next) => {
82
+ req.db = this.db;
83
+ req.worldDir = worldPath;
84
+ req.frontDir = frontPath;
85
+ req.pagesDir = pagesPath;
86
+ req.voidDir = voidPath;
78
87
 
79
- this.app.use("/", controllers.authCheck, await controllers.explorer(worldPath, voidPath));
88
+ next();
89
+ });
80
90
 
81
- this.server.listen(process.env.PORT, function () {
82
- console.log(`Server started at ${process.env.PORT}`);
83
- this.started = true;
84
- });
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.authCheck, controllers.explorer);
104
+
105
+ this.app.use("/", controllers.pages);
85
106
 
86
- }
87
- else console.log("Server already started!");
107
+ this.app.use(controllers.void);
108
+
109
+ this.server.listen(process.env.PORT, function () {
110
+ console.log(`Server started at ${process.env.PORT}`);
111
+ this.started = true;
112
+ });
88
113
  }
89
114
  }
90
115
 
91
- module.exports = new NotherBaseFS();
116
+ export default NotherBaseFS;
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "notherbase-fs",
3
- "version": "1.4.4",
3
+ "version": "1.5.0",
4
4
  "description": "Functions to help make developing for NotherBase easier.",
5
- "main": "notherbase-fs.js",
5
+ "exports": "./notherbase-fs.js",
6
6
  "scripts": {
7
7
  "test": "nodemon test/test-index.js",
8
8
  "gmail-auth": "node gmail-auth.js",
@@ -30,6 +30,11 @@
30
30
  "mongoose": "^6.1.7",
31
31
  "nodemailer": "^6.7.5",
32
32
  "serve-favicon": "^2.5.0",
33
- "socket.io": "^4.4.1"
33
+ "socket.io": "^4.4.1",
34
+ "string-strip-html": "^13.0.0"
35
+ },
36
+ "type": "module",
37
+ "engines": {
38
+ "node": ">=14.16"
34
39
  }
35
40
  }
@@ -1,25 +1,21 @@
1
1
  class ChatBox {
2
- constructor(name, box, room) {
2
+ constructor(username, room) {
3
3
  this.socket = null;
4
- import("/socket.io/socket.io.js").then(() => {
5
- this.socket = io({
6
- query: {
7
- room: room,
8
- name: name
9
- }
10
- });
4
+ this.username = username;
5
+ this.room = room;
6
+ this.$div = $(`.chat-box#${room}`);
7
+ this.$chatLog = null;
8
+ this.$entry = null;
11
9
 
12
- this.socket.on('chat message', this.newMessage);
13
- $(".chat-send").on("click", this.sendMessage);
14
- this.$entry.on("keyup", function(e) {
15
- if (e.keyCode == 13) sendMessage();
16
- });
10
+ this.socket = io({
11
+ query: {
12
+ room: this.room,
13
+ name: this.username
14
+ }
17
15
  });
18
16
 
19
- this.room = room;
20
- this.$div = $(`.chat-box #${box}`)
21
- this.$chatLog = this.$div.find(".chat-log");
22
- this.$entry = this.$div.find(".chat-entry");
17
+ this.socket.on('chat message', this.newMessage);
18
+ this.render();
23
19
  }
24
20
 
25
21
  newMessage = (msg) => {
@@ -32,19 +28,29 @@ class ChatBox {
32
28
  let val = this.$entry.val();
33
29
  this.$entry.val("");
34
30
 
35
- // $.post("/chat", {
36
- // room: "<%= room %>",
37
- // text: val
38
- // }, function () {
39
- // $chatLog.scrollTop($chatLog[0].scrollHeight);
40
- // });
41
-
42
31
  this.socket.emit('chat message', {
43
- name: name,
32
+ name: this.username,
44
33
  time: Date.now(),
45
34
  text: val
46
35
  });
47
36
  }
48
37
  }
38
+
39
+ render() {
40
+ this.$div.empty();
41
+
42
+ this.$div.append(`<h4>Chatting with the name ${this.username}:`);
43
+ this.$div.append(`<div class="chat-log"> </div>`);
44
+ this.$div.append(`<input autocomplete="off" type="text" class="chat-entry">`);
45
+ this.$div.append(`<button class="chat-send">Send</button>`);
46
+
47
+ this.$chatLog = this.$div.find(".chat-log");
48
+ this.$entry = this.$div.find(".chat-entry");
49
+
50
+ this.$div.find("button").on("click", this.sendMessage);
51
+ this.$entry.on("keyup", (e) => {
52
+ if (e.keyCode == 13) this.sendMessage();
53
+ });
54
+ }
49
55
  }
50
56
 
@@ -4,15 +4,16 @@
4
4
 
5
5
  <hr>
6
6
 
7
- <div class="chat-box" id="test-box">
8
- <div class="chat-name">Chatting using the name <%= user.username %>:</div>
7
+ <div class="chat-box" id="test-chat">
9
8
 
10
- <div class="chat-log">
11
-
12
- </div>
9
+ </div>
10
+
11
+ <div class="chat-box" id="test-chat-2">
12
+
13
+ </div>
14
+
15
+ <div class="chat-box" id="test-chat-3">
13
16
 
14
- <input autocomplete="off" type="text" name="text" class="chat-entry">
15
- <div value="Send" class="chat-send">Send</div>
16
17
  </div>
17
18
 
18
19
  <hr>
@@ -84,7 +85,9 @@
84
85
 
85
86
  <script src="/js/chat-box.js"></script>
86
87
  <script>
87
- let chatTest = new ChatBox("<%= user.username %>", "test-box", "testRoom");
88
+ let chatTest = new ChatBox("<%= user.username %>", "test-chat");
89
+ let chatTest2 = new ChatBox("<%= user.username %>", "test-chat-2");
90
+ let chatTest3 = new ChatBox("<%= user.username %>", "test-chat-3");
88
91
 
89
92
  let bought = false;
90
93
 
@@ -1,4 +1,7 @@
1
- const path = require('path');
2
- const notherBaseFS = require("../notherbase-fs");
1
+ import path from 'node:path';
2
+ import NotherBaseFS from "../notherbase-fs.js";
3
+ import { fileURLToPath } from 'node:url';
4
+ const __dirname = fileURLToPath(new URL('./', import.meta.url));
5
+ console.log(__dirname);
3
6
 
4
- notherBaseFS.start(__dirname, `${__dirname}/void`, __dirname, `${__dirname}/pages`);
7
+ const notherBaseFS = new NotherBaseFS(__dirname, `${__dirname}void`, __dirname, `${__dirname}pages`);
@@ -3,6 +3,7 @@
3
3
  <script>
4
4
  const currentRoute = "<%- route %>";
5
5
  </script>
6
+ <script src="/socket.io/socket.io.js"></script>
6
7
  <script src="/js/memories.js"></script>
7
8
 
8
9
  <main class="override">
@@ -1,28 +0,0 @@
1
- const express = require("express");
2
- const router = express.Router();
3
-
4
- const getRouterWithIO = function getRouterWithIO(io) {
5
- router.post("/", async function(req, res) {
6
- try {
7
- if (req.session.currentUser) {
8
- io.to(req.body.room).emit('chat message', {
9
- name: req.session.currentUser,
10
- time: Date.now(),
11
- text: req.body.text
12
- });
13
-
14
- res.status(200).end();
15
- }
16
- else {
17
- res.status(401).end();
18
- }
19
- }
20
- catch(err) {
21
- console.log(err);
22
- }
23
- });
24
-
25
- return router;
26
- }
27
-
28
- module.exports = getRouterWithIO;
@@ -1,16 +0,0 @@
1
- const mongoose = require("mongoose");
2
-
3
- const projects = new mongoose.Schema({
4
- name: String,
5
- url: String,
6
- repository: String,
7
- description: String,
8
- thumbnail: String,
9
- cover: String,
10
- developers: [{
11
- type: mongoose.Schema.Types.ObjectId,
12
- ref: "users"
13
- }]
14
- });
15
-
16
- module.exports = mongoose.model('projects', projects);