Skip to content

Commit

Permalink
polish and shit pre 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragon1320 committed Nov 4, 2018
1 parent 567bd37 commit 0df15ad
Show file tree
Hide file tree
Showing 32 changed files with 1,683 additions and 1,574 deletions.
2 changes: 1 addition & 1 deletion src/web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ app.use(cookieParser(config.rawrxd));
app.use(i18n({
defaultLang: "en",
translationsPath: path.join(__dirname, 'translations'),
siteLangs: ["en","ga","es","pt","zh","ro","ni", "pl"],
siteLangs: ["en","ga","es","pt-pt","zh-tw","ro","ni", "pl"],
paramLangName: "hl",
textsVarName: 'trans'
}));
Expand Down
9 changes: 6 additions & 3 deletions src/web/middlewares/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ const authUser = (req, res, next) => {
}

if (token === undefined) {
return res.json({ status: 401, message: "Unauthorized", error: "There was an issue fetching your session" });
//return res.json({ status: 401, message: "Unauthorized", error: "There was an issue fetching your session" });
return res.redirect("/auth/discord");
}

fetchSession(token)
Expand All @@ -67,12 +68,14 @@ const authUser = (req, res, next) => {
})
.catch(error => {

return res.json({ status: 401, message: "Unauthorized", error });
//return res.json({ status: 401, message: "Unauthorized", error });
return res.redirect("/auth/discord");
});
})
.catch(error => {

res.json({ status: 401, message: "Unauthorized", error });
//res.json({ status: 401, message: "Unauthorized", error });
return res.redirect("/auth/discord");
});
}

Expand Down
148 changes: 78 additions & 70 deletions src/web/routes/api/guilds.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ router.route("/").post(authUser, (req, res) => {

router.route("/@me").get(authUser, (req, res) => {

// + cond discord data
const noawesomo = req.query.noawesomo === "true" ? true : req.query.noawesomo === "false" ? false : undefined;

// + cond discord data
const extended = req.query.extended === "true" ? true : req.query.extended === "false" ? false : undefined;

Expand All @@ -245,10 +248,12 @@ router.route("/@me").get(authUser, (req, res) => {
.then(guilds => {

const search_ids = [];
const search_guilds = [];
for (let guild of guilds) {
if ((guild.name.includes(name === undefined ? "" : name) === true) && (owner === undefined ? true : guild.owner === owner)) {

search_ids.push(guild.id);
search_guilds.push(guild);
}
}

Expand Down Expand Up @@ -303,6 +308,11 @@ router.route("/@me").get(authUser, (req, res) => {

return doc_obj;
});

if (noawesomo === true) {

docs = [...docs, ...search_guilds.filter(e => !docs.map(e => e.discord_id).includes(e.id)).map(e => { e.discord_id = e.id; delete e.id; return e; })];
}
}

return res.json({ status: 200, page, limit, total, guilds: docs });
Expand Down Expand Up @@ -487,91 +497,89 @@ router.route("/:discord_id/scripts").get(authUser, (req, res) => {
};

schemas.GuildSchema
.findOne({
discord_id: req.params.discord_id
})
.then(doc => {
if (doc === null) {
.findOne({
discord_id: req.params.discord_id
})
.then(doc => {
if (doc === null) {

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

if (extended === true) {
if (extended === true) {

const search_ids = doc.scripts.map(script => script.object_id);
const search_ids = doc.scripts.map(script => script.object_id);

schemas.ScriptSchema
.count({
...search,
_id: {
$in: search_ids
}
})
.skip(page * limit)
.limit(limit)
.then(total => {
if (total === 0) {

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

schemas.ScriptSchema
.find({
...search,
_id: {
$in: search_ids
}
})
.skip(page * limit)
.limit(limit)
.select({ __v: 0 })
.then(docs => {
schemas.ScriptSchema
.count({
...search,
_id: {
$in: search_ids
}
})
.then(total => {
if (total === 0) {

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

schemas.ScriptSchema
.find({
...search,
_id: {
$in: search_ids
}
})
.skip(page * limit)
.limit(limit)
.select({ __v: 0 })
.then(docs => {

docs = docs.map(doc2 => {
docs = docs.map(doc2 => {

const doc2_obj = doc2.toObject();
const doc2_obj = doc2.toObject();

for (let script of doc.scripts) {
for (let script of doc.scripts) {

if (script.object_id.equals(doc2_obj._id)) {
if (script.object_id.equals(doc2_obj._id)) {

delete doc2_obj._id;
delete doc2_obj._id;

doc2_obj.object_id = script.object_id;
doc2_obj.match_type_override = script.match_type_override;
doc2_obj.match_override = script.match_override;
doc2_obj.permissions = script.permissions;

break;
doc2_obj.object_id = script.object_id;
doc2_obj.match_type_override = script.match_type_override;
doc2_obj.match_override = script.match_override;
doc2_obj.permissions = script.permissions;

break;
}
}
}

return doc2_obj;
return doc2_obj;
});

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

apiLogger.error(error);
return res.json({ status: 500 });
});

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

apiLogger.error(error);
return res.json({ status: 500 });
});
})
.catch(error => {

apiLogger.error(error);
return res.json({ status: 500 });
});
} else {
})
.catch(error => {

apiLogger.error(error);
return res.json({ status: 500 });
});
} else {

return res.json({ status: 200, page, limit, total: doc.scripts.length, scripts: doc.scripts.slice(page * limit, page * limit + limit) });
}
})
.catch(error => {
return res.json({ status: 200, page, limit, total: doc.scripts.length, scripts: doc.scripts.slice(page * limit, page * limit + limit) });
}
})
.catch(error => {

apiLogger.error(error);
return res.json({ status: 500 });
});
apiLogger.error(error);
return res.json({ status: 500 });
});

}).post(authUser, (req, res) => {

Expand Down
65 changes: 48 additions & 17 deletions src/web/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,45 +163,51 @@ router.get("/api/v3/patrons", (req, res) => {
const patrons = [
{
username: "Airborn56",
avatar: "https://cdn.discordapp.com/avatars/99626024181968896/a_d69fc64082896a7cb51c2aa20557b080.png?size=512",
avatar: "https://cdn.discordapp.com/attachments/379432139856412682/508434629422874624/e0e22d84ce70e350376c8c78756d94a3.png",
date: "2018-04-27T21:32:11.928165+00:00",
amount: 10
},
{
username: "timmys9inchjimmy",
avatar: "https://cdn.discordapp.com/avatars/430503118262894614/c016210777c0eed529c6ae9b3a3c7a37.png?size=512",
avatar: "https://cdn.discordapp.com/attachments/379432139856412682/508434624666664961/c016210777c0eed529c6ae9b3a3c7a37.png",
date: "2018-06-07T20:54:53.048475+00:00",
amount: 5
},
{
username: "Kamui",
avatar: "https://cdn.discordapp.com/avatars/161573813379792899/a_e6cc2fa791bbefce65e928492eaebe91.png?size=512",
avatar: "https://cdn.discordapp.com/attachments/379432139856412682/508019481642270740/a_ecc5cdc51043b5b3810c923e8075411e.gif",
date: "2018-01-03T01:39:37.152671+00:00",
amount: 1
},
{
username: "KlausHeissler",
avatar: "https://cdn.discordapp.com/avatars/342086358010953728/1bd96364cbb3ad48df37374b73c6c72c.png?size=512",
avatar: "https://cdn.discordapp.com/attachments/379432139856412682/508434630559662139/429937e230deb16a5bc87ca5b0fabb75.png",
date: "2018-03-03T02:20:43.132314+00:00",
amount: 1
},
{
username: "lonelychef",
avatar: "https://cdn.discordapp.com/avatars/328837258788601857/92706e9f3a5342dee38c5279863bf500.png?size=512",
avatar: "https://cdn.discordapp.com/attachments/379432139856412682/508434619297824768/92706e9f3a5342dee38c5279863bf500.png",
date: "2018-05-27T10:59:42.665346+00:00",
amount: 10
},
{
username: "Savagekiller115",
avatar: "https://cdn.discordapp.com/avatars/393620893835984896/3b1333657ff839838d281bfb02abbec8.png?size=512",
avatar: "https://cdn.discordapp.com/attachments/379432139856412682/508434615296327691/3b1333657ff839838d281bfb02abbec8.png",
date: "2018-05-24T00:56:22.462165+00:00",
amount: 10
},
{
username: "Tweeno",
avatar: "https://cdn.discordapp.com/avatars/215982178046181376/79209171354b0d6a28f2c5672b1d5bbd.png?size=512",
avatar: "https://cdn.discordapp.com/attachments/379432139856412682/508434634200186880/555bd89923fd4c08b37c540ba1e75ba7.png",
date: "2018-06-16T00:00:00.000000+00:00",
amount: 1
},
{
username: "Dr. Normal",
avatar: "https://cdn.discordapp.com/attachments/379432139856412682/508435598223212575/a_58812516bac2ed8a503ef3ac02600f53.png",
date: "2018-11-02T00:00:00.000000+00:00",
amount: 10
}
];

Expand Down Expand Up @@ -229,7 +235,27 @@ router.get("/api/v3/sloc", (req, res) => {
router.get("/dashboard/profiles/:discord_id", authUser, async (req, res) => {

res.render("dashboard/profile")
});
});

router.get("/terms", (req, res) => {

res.render("soontm")
});

router.get("/help", (req, res) => {

res.render("soontm")
});

router.get("/feedback", (req, res) => {

res.render("soontm")
});

router.get("/soontm", (req, res) => {

res.render("soontm");
});

router.get("/logout", async (req, res) => {

Expand Down Expand Up @@ -313,7 +339,8 @@ router.get("/auth/discord/callback", async (req, res) => {
} catch(error) {

apiLogger.error(error);
return res.render("401", { status: 401, message: "Unauthorized", error });
//return res.render("401", { status: 401, message: "Unauthorized", error });
return res.redirect("/auth/discord");
}

if (session_doc.nonce !== req.query.state) {
Expand Down Expand Up @@ -417,8 +444,11 @@ router.get("/api/docs", async (req, res) => {
});

router.get("/privacy", async (req, res) => {
const privacy = fs.readFileSync(path.join(__dirname, "..", "markdown", "terms", "privacy.md")).toString();
res.render("privacy", { md: text => { return converter.makeHtml(text); }, user: {}, privacy});

//const privacy = fs.readFileSync(path.join(__dirname, "..", "markdown", "terms", "privacy.md")).toString();
//res.render("privacy", { md: text => { return converter.makeHtml(text); }, user: {}, privacy});

res.render("soontm");
});

router.get("/credits", async (req, res) => {
Expand All @@ -433,10 +463,6 @@ router.get("/credits", async (req, res) => {
res.render("credits", { md: text => { return converter.makeHtml(text); }, user: {}, credits:credits});
});

router.get("/commands", (req, res) => {
res.render("commands", { md: text => { return converter.makeHtml(text); }, user: {}});
});

router.get("/surveys", (req, res) => {
res.render("surveys", { md: text => { return converter.makeHtml(text); }, user: {}});
});
Expand Down Expand Up @@ -513,7 +539,7 @@ router.get("/dashboard/leaderboards/legacy/v1", authUser, async (req, res) => {
apiLogger.fatalError(`Could not read config file: ${err}`);
}

res.render("dashboard/legacy-leaderboards", {v1:v1});
res.render("dashboard/legacy-leaderboards", {v1:JSON.stringify(v1)});
});

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

apiLogger.fatalError(`Could not read config file: ${err}`);
}
res.render("dashboard/legacy-leaderboards-2", {v2:v2});
res.render("dashboard/legacy-leaderboards-2", {v2:JSON.stringify(v2)});
});

router.get("/dashboard/commands", authUser, (req, res) => {

res.render("dashboard/commands");
});

router.get("/dashboard/leaderboards", authUser, (req, res) => {
Expand Down
Binary file added src/web/static/img/feature0.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/feature1.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/feature2.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/feature3.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/feature4.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/feature5.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/feature6.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/lol.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 0df15ad

Please sign in to comment.