move some files into other folders and make some code neater

This commit is contained in:
hippoz 2021-03-14 20:14:32 +02:00
parent 50a3564fd4
commit 4d61db3e5b
No known key found for this signature in database
GPG key ID: 7C52899193467641
13 changed files with 1125 additions and 1189 deletions

View file

@ -2,23 +2,21 @@ const User = require("../../models/User");
const Category = require("../../models/Category");
const Post = require("../../models/Post");
const config = require("../../config");
const { authenticateEndpoint } = require("./authfunctions");
const { authenticateEndpoint } = require("./../../common/auth/authfunctions");
const mongoose = require("mongoose");
const { body, param, validationResult } = require("express-validator");
const express = require("express");
const app = express.Router();
mongoose.connect(config.mongoUrl, {useNewUrlParser: true, useUnifiedTopology: true});
const rateLimit = require("express-rate-limit");
const app = express.Router();
const createLimiter = rateLimit({
windowMs: 2 * 60 * 1000,
max: 10,
});
mongoose.connect(config.mongoUrl, {useNewUrlParser: true, useUnifiedTopology: true});
app.post("/category/create", [
createLimiter,
body("title").not().isEmpty().trim().isLength({ min: 3, max: 32 }).escape()

View file

@ -2,7 +2,7 @@ const User = require("../../../models/User");
const secret = require("../../../secret");
const config = require("../../../config");
const Category = require("../../../models/Category");
const RateLimiter = require("./ratelimiter");
const RateLimiter = require("../../../common/util/ratelimiter");
const jwt = require("jsonwebtoken");
const siolib = require("socket.io");

View file

@ -1,8 +1,7 @@
const User = require("../../models/User");
const config = require("../../config");
const secret = require("../../secret");
const { authenticateEndpoint } = require("./authfunctions");
const { authenticateEndpoint } = require("./../../common/auth/authfunctions");
// TODO: Might want to use something else (https://blog.benpri.me/blog/2019/01/13/why-you-shouldnt-be-using-bcrypt-and-scrypt/)
const bcrypt = require("bcrypt");
@ -10,18 +9,17 @@ const mongoose = require("mongoose");
const { body, param, validationResult } = require("express-validator");
const express = require("express");
const jwt = require("jsonwebtoken");
const app = express.Router();
mongoose.connect(config.mongoUrl, {useNewUrlParser: true, useUnifiedTopology: true});
const rateLimit = require("express-rate-limit");
const app = express.Router();
const createAccountLimiter = rateLimit({
windowMs: 60 * 60 * 1000, // 1 hour window
max: 10, // start blocking after 5 requests
message: "You are being rate limited"
});
mongoose.connect(config.mongoUrl, {useNewUrlParser: true, useUnifiedTopology: true});
app.get("/account/create/info", async (req, res) => {
let requiresCode = false;
if (config.restrictions) {

View file

@ -1,57 +0,0 @@
POST http://localhost:3000/api/v1/users/account/create
Content-Type: application/json
{
"username": "test",
"password": "testtesttest",
"email": "test@test.test"
}
###
POST http://localhost:3000/api/v1/users/token/create
Content-Type: application/json
{
"username": "test",
"password": "testtesttest"
}
###
GET http://localhost:3000/api/v1/users/current/info
Cookie: token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3QiLCJpYXQiOjE2MDU0ODI5NjgsImV4cCI6MTYwNTQ5Mzc2OH0.BjZEnI1v7XCYpEqyBub7uFrTtfQUZ7_PukP4sgcEzB0.eyJ1c2VybmFtZSI6InRlc3QiLCJpYXQiOjE2MDA1MTA2MTEsImV4cCI6MTYwMDUyMTQxMX0.q85p94FLPR4fxZ4O5pmalEEjU9Hyr9js63u6LgoCQCw
###
POST http://localhost:3000/api/v1/content/category/create
Cookie: token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3QiLCJpYXQiOjE2MDU0ODI5NjgsImV4cCI6MTYwNTQ5Mzc2OH0.BjZEnI1v7XCYpEqyBub7uFrTtfQUZ7_PukP4sgcEzB0
Content-Type: application/json
{
"title": "testing1"
}
###
POST http://localhost:3000/api/v1/content/post/create
Cookie: token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3QiLCJpYXQiOjE2MDU0ODI5NjgsImV4cCI6MTYwNTQ5Mzc2OH0.BjZEnI1v7XCYpEqyBub7uFrTtfQUZ7_PukP4sgcEzB0
Content-Type: application/json
{
"category": "5fb1ba3eb04f2b3356aa2e58",
"title": "Test title",
"body": "Test content!!!"
}
###
GET http://localhost:3000/api/v1/content/category/5fb1ba3eb04f2b3356aa2e58/info
Cookie: token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3QiLCJpYXQiOjE2MDU0ODI5NjgsImV4cCI6MTYwNTQ5Mzc2OH0.BjZEnI1v7XCYpEqyBub7uFrTtfQUZ7_PukP4sgcEzB0
Content-Type: application/json
###
GET http://localhost:3000/api/v1/content/category/list
Cookie: token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3QiLCJpYXQiOjE2MDA1MTA2MTEsImV4cCI6MTYwMDUyMTQxMX0.q85p94FLPR4fxZ4O5pmalEEjU9Hyr9js63u6LgoCQCw
Content-Type: application/json

View file

@ -6,7 +6,7 @@ const cookieParser = require("cookie-parser");
const cors = require("cors");
const http = require("http");
const { authenticateEndpoint } = require("./api/v1/authfunctions");
const { authenticateEndpoint } = require("./common/auth/authfunctions");
const GatewayServer = require("./api/v1/gateway/index");
const app = express();
@ -35,10 +35,6 @@ app.get("/", authenticateEndpoint((req, res) => {
res.redirect("/app.html");
}, "/auth.html"));
app.get("/admin", (req, res) => {
res.send("Keanu chungus wholesome 100 reddit moment 😀i beat up a kid that said minecraft bad 😂and my doggo bit him so i gave him snaccos😉 and we watched pewdiepie together while in elon musks cyber truck 😳talking about how superior reddit memers are : “haha emojis bad” 😲i said and keanu reeves came outta nowhere and said “this is wholesome 100, updoot this wholesome boy” 😗so i got alot of updoots and edit: thanks for the gold kind stranger😣. but the kind stranger revealed himself to be baby yoda eating chiccy nuggies😨 and drinking choccy milk😎 so we went to the cinema to see our (communism funny) favorite movies avengers endgame😆 but then thor played fortnite and fortnite bad😡, so then i said “reality is often dissappointing” and then baby yoda replied r/unexpectedthanos and i replied by r/expectedthanos😖 for balance and then danny devito came to pick us up from the cinema😩 and all the insta normies and gay mods stood watching😵 ,as we,superior redditors went home with danny devito to suck on his magnum dong😫 but i said no homo and started sucking,not like those gay mods😮,then the next morning we woke up to MrBeast telling us to plant 69420 million trees😌, me, baby yoda and danny said nice, and then on our way to plant 69420 million trees😊 (nice) we saw a kid doing a tiktok so keanu reeves appeared and said “we have a kid to burn” and i replied “youre breathtaking”😄 so i said “i need a weapon” and baby yoda gave me an RPG so i blew the kid (DESTRUCTION 100)😎 and posted it on r/memes and r/dankmemes and r/pewdiepiesubmissions and got 1000000000 updoots😘,im sure pewds will give me a big pp, then we shat on emoji users😂😂 and started dreaming about girls that will never like me😢 and posted a lie on r/teenagers about how i got a GF after my doggo died by the hands of fortnite players😳 so i exploited his death for updoots😜, but i watched the sunset with the wholesome gang😁 (keanu,danny,Mrbeast, pewds, spongebob,stefan karl , bob ross, steve irwin, baby yoda and other artists that reddit exploits them) [Everyone liked that] WHOLESOME 100 REDDIT 100🤡");
});
app.use((err, req, res, next) => {
console.error("[E] Internal server error", err);
res.status(500).json({ error: true, status: 500, message: "ERR_INTERNAL_SERVER_ERROR" });

2201
brainlet/package-lock.json generated Executable file → Normal file

File diff suppressed because it is too large Load diff

View file

@ -1,10 +1,11 @@
{
"name": "dictionar",
"name": "brainlet",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"keywords": [],
"author": "",

View file

@ -5,6 +5,6 @@ module.exports = {
// Set default values
// You shouldn't need to touch this for configuring this
if (module.exports.jwtPrivateKey === "KEY") {
console.error("[*] [config] jwtPrivateKey was not specified in secret.js. A randomly generated private key will be used instead");
console.error("[*] [config] jwtPrivateKey was not specified in secret.js. A randomly generated private key will be used instead.");
module.exports.jwtPrivateKey = require("crypto").randomBytes(129).toString("base64");
}

6
package-lock.json generated
View file

@ -1,6 +0,0 @@
{
"name": "brainlet",
"lockfileVersion": 2,
"requires": true,
"packages": {}
}

View file

@ -1 +0,0 @@
{}

View file

@ -50,7 +50,7 @@ You need to edit the config.js file in order to allow your domain to CORS, and m
## You should now be ready to go!
Just run Brainlet with the command below:
```
node index.js
npm start
```
Afterwards, try going to [http://localhost:3005/auth.html](http://localhost:3005/auth.html) to visit the site, assuming default port config.