Skip to content

Commit

Permalink
stash teehee
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragon1320 committed Nov 2, 2018
1 parent fef0db7 commit 3b52bc9
Show file tree
Hide file tree
Showing 19 changed files with 483 additions and 165 deletions.
2 changes: 1 addition & 1 deletion src/bot/commands/member.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const member = new Command({
marketplace_enabled: true,

type: "js",
match_type: "contains",
match_type: "startswith",
match: "member",

featured: false,
Expand Down
64 changes: 63 additions & 1 deletion src/web/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,73 @@ const getUserData = token => {
});
}

// temp

/*
{
expire,
data
}
*/
const userCacheNS = {};

const cacheTimeNS = 21600000; // 6 hours

const getUserDataNoSession = id => {
return new Promise((resolve, reject) => {

let data = null;
for (let k in userCacheNS) {

if (userCacheNS[k].expire < Date.now()) {

delete userCacheNS[k];
continue;
}

if (k === id) {

data = userCacheNS[k].data;
}
}

if (data === null) {

axios
.get(`https://discordapp.com/api/v6/users/${id}`, {
headers: {
"Authorization": `Bot ${config.discord_token}`
}
})
.then(res => {

userCacheNS[id] = {

expire: new Date(Date.now() + cacheTimeNS),
data: res.data
};

resolve(res.data);
})
.catch(error => {

reject(error);
});
} else {

resolve(data);
}
});
}

//

module.exports = {

jwtVerify,
fetchSession,
fetchUser,

getUserData
getUserData,
getUserDataNoSession
};
1 change: 1 addition & 0 deletions src/web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ app.use(express.json());
app.use(cookieParser(config.rawrxd));

app.use(i18n({
defaultLang: "en",
translationsPath: path.join(__dirname, 'translations'),
siteLangs: ["en","ga","es","pt","zh","ro","ni", "pl"],
paramLangName: "hl",
Expand Down
86 changes: 20 additions & 66 deletions src/web/routes/api/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const mongoose = require("mongoose");
const schemas = require("../../../db");
const Logger = require("../../../logger");
const { authUser } = require("../../middlewares");
const { getUserData } = require("../../helpers");
const { getUserData, getUserDataNoSession } = require("../../helpers");

const router = express.Router();
const apiLogger = new Logger();
Expand Down Expand Up @@ -60,84 +60,38 @@ router.route("/").get(authUser, (req, res) => {
const script_objs = docs.map(doc => doc.toObject());
const search_ids = docs.map(doc => doc.author_id);

schemas.SessionSchema
for (let i = 0; i < script_objs.length; i++) {

if (script_objs[i].author_id === "feinwaru-devs") {

script_objs[i].author_username = "Feinwaru";
continue;
}

// other users

}

schemas.UserSchema
.find({
"discord.id": {
discord_id: {
$in: search_ids
}
})
.then(async docs => {
.then(users => {

for (let i = 0; i < script_objs.length; i++) {

if (script_objs[i].author_id === "feinwaru-devs") {

script_objs[i].author_username = "Feinwaru";
search_ids.push("feinwaru-devs");
continue;
}

let user = null;
let success = false;

for (let doc of docs) {

if (success === true) {

break;
}
for (let user of users) {

if (doc.discord.id !== script_objs[i].author_id) {
if (user.discord_id === script_objs[i].author_id) {

continue;
}

try {

user = await getUserData(doc.discord.access_token);
success = true;
} catch(error) {

user = null;
success = false;
script_objs[i].author_verified = user.verified;
}
}

if (success === true) {

script_objs[i].author_username = user.username;
} else {

return res.json({ status: 400 });
}
}

schemas.UserSchema
.find({
discord_id: {
$in: search_ids
}
})
.then(users => {

for (let i = 0; i < script_objs.length; i++) {

for (let user of users) {

if (user.discord_id === script_objs[i].author_id) {

script_objs[i].author_verified = user.verified;
}
}
}

return res.json({ status: 200, page, limit, total, scripts: script_objs });
})
.catch(error => {

apiLogger.error(error);
return res.json({ status: 500 });
});
return res.json({ status: 200, page, limit, total, scripts: script_objs });
})
.catch(error => {

Expand Down
40 changes: 4 additions & 36 deletions src/web/routes/api/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const express = require("express");
const schemas = require("../../../db");
const Logger = require("../../../logger");
const { authUser, authAdmin } = require("../../middlewares");
const { getUserData } = require("../../helpers");
const { getUserData, getUserDataNoSession } = require("../../helpers");

const router = express.Router();
const apiLogger = new Logger();
Expand Down Expand Up @@ -83,7 +83,7 @@ router.route("/").get(authUser, (req, res) => {
params.shits = req.body.shits;
params.trophies = req.body.trophies;

params.likes = req.body.likes;
params.likes = req.body.likes;
}

const user = new schemas.UserSchema(params);
Expand Down Expand Up @@ -154,40 +154,8 @@ router.route("/:discord_id").get(authUser, (req, res) => {

if (extended === true) {

schemas.SessionSchema
.find({
"discord.id": req.params.discord_id
})
.then(async docs => {
if (docs.length === 0) {

return res.json({ status: 404 });
}

let user = null;
let success = false;
for (let doc of docs) {

if (success === true) {

break;
}

try {

user = await getUserData(doc.discord.access_token);
success = true;
} catch(error) {

user = null;
success = false;
}
}

if (success === false) {

return res.json({ status: 400 });
}
getUserDataNoSession(req.params.discord_id)
.then(async user => {

user_obj.username = user.username;
//user_obj.locale = user.locale;
Expand Down
36 changes: 5 additions & 31 deletions src/web/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,23 +505,8 @@ router.get("/dashboard/leaderboards/legacy/v1", authUser, async (req, res) => {

apiLogger.fatalError(`Could not read config file: ${err}`);
}
let user;
try {

user = await axios({
method: "get",
url: `https://discordapp.com/api/v6/users/@me`,
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${req.session.discord.access_token}`
}
});
} catch(error) {

apiLogger.error(error);
}

res.render("dashboard/legacy-leaderboards", { user_data: { id: user.data.id, avatar: user.data.avatar, username: user.data.username }, v1:v1});
res.render("dashboard/legacy-leaderboards", {v1:v1});
});

router.get("/dashboard/leaderboards/legacy/v2", authUser, async (req, res) => {
Expand All @@ -534,23 +519,12 @@ router.get("/dashboard/leaderboards/legacy/v2", authUser, async (req, res) => {

apiLogger.fatalError(`Could not read config file: ${err}`);
}
let user;
try {

user = await axios({
method: "get",
url: `https://discordapp.com/api/v6/users/@me`,
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${req.session.discord.access_token}`
}
});
} catch(error) {
res.render("dashboard/legacy-leaderboards-2", {v2:v2});
});

apiLogger.error(error);
}
router.get("/dashboard/leaderboards", authUser, (req, res) => {

res.render("dashboard/legacy-leaderboards-2", { user_data: { id: user.data.id, avatar: user.data.avatar, username: user.data.username }, v2:v2});
res.render("dashboard/leaderboards");
});

router.get("/dashboard/scripts/editor/advanced", authUser, (req, res) => {
Expand Down
Binary file added src/web/static/img/ladder.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/web/static/img/news.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/web/static/img/shitter.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/web/static/img/trophy/trophy-shit.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3b52bc9

Please sign in to comment.