Added some more style + bumping servers
This commit is contained in:
1 parent
c83c27a8ac
commit
d91ebbfa25
12 files changed
+248
-254
No files matched your search
+101
-100
@@ -21,114 +21,115 @@ router.get('/search/:id', function (req, res) {
|
||||
res.json({
|
||||
bot: bot,
|
||||
})
|
||||
|
||||
router.use(function (req, res, next) {
|
||||
if (!req.headers.authorization) {
|
||||
return res.status(403).json({ error: 'No credentials sent!' });
|
||||
} else {
|
||||
bots.findOne({ token: req.headers.authorization }, function (err, bot) {
|
||||
if (err) {
|
||||
res.status(503).json({
|
||||
error: "Something went wrong"
|
||||
})
|
||||
}
|
||||
if (bot) {
|
||||
if (bot.token == req.headers.authorization) {
|
||||
next();
|
||||
}
|
||||
} else {
|
||||
res.status(403).json({
|
||||
error: "Unauthorized"
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
router.use(function (req, res, next) {
|
||||
if (!req.headers.authorization) {
|
||||
return res.status(403).json({ error: 'No credentials sent!' });
|
||||
} else {
|
||||
bots.findOne({ token: req.headers.authorization }, function (err, bot) {
|
||||
if (err) {
|
||||
res.status(503).json({
|
||||
error: "Something went wrong"
|
||||
})
|
||||
}
|
||||
next();
|
||||
});
|
||||
router.post('/bots/servers', function (req, res) {
|
||||
if (req.headers.authorization) {
|
||||
bots.findOne({ token: req.headers.authorization }, function (err, bot) {
|
||||
if (err) {
|
||||
res.status(503).json({
|
||||
error: "Something went wrong"
|
||||
})
|
||||
}
|
||||
if (bot) {
|
||||
if (bot.token == req.headers.authorization) {
|
||||
bot.servers = req.headers.servercount;
|
||||
bot.save(function (err) {
|
||||
if (err) {
|
||||
res.status(503).json({
|
||||
error: "Something went wrong"
|
||||
})
|
||||
} else {
|
||||
res.status(200).json({
|
||||
message: "Success"
|
||||
})
|
||||
}
|
||||
if (bot) {
|
||||
if (bot.token == req.headers.authorization) {
|
||||
next();
|
||||
}
|
||||
} else {
|
||||
res.status(403).json({
|
||||
error: "Unauthorized"
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
next();
|
||||
});
|
||||
router.post('/bots/servers', function (req, res) {
|
||||
if (req.headers.authorization) {
|
||||
bots.findOne({ token: req.headers.authorization }, function (err, bot) {
|
||||
if (err) {
|
||||
res.status(503).json({
|
||||
error: "Something went wrong"
|
||||
})
|
||||
}
|
||||
if (bot) {
|
||||
if (bot.token == req.headers.authorization) {
|
||||
bot.servers = req.headers.servercount;
|
||||
bot.save(function (err) {
|
||||
if (err) {
|
||||
res.status(503).json({
|
||||
error: "Something went wrong"
|
||||
})
|
||||
} else {
|
||||
res.status(403).json({
|
||||
error: "Invalid token or bot"
|
||||
res.status(200).json({
|
||||
message: "Success"
|
||||
})
|
||||
}
|
||||
} else {
|
||||
res.status(403).json({
|
||||
error: "Invalid token or bot"
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
res.status(403).json({
|
||||
error: "Invalid token or bot"
|
||||
})
|
||||
}
|
||||
} else {
|
||||
res.status(401).json({
|
||||
message: "Please provide a bot token"
|
||||
res.status(403).json({
|
||||
error: "Invalid token or bot"
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
router.get('/bots/search/:id', function (req, res) {
|
||||
bots.findOne({ id: req.params.id }, function (err, bot) {
|
||||
if (err) {
|
||||
res.status(503).json({
|
||||
error: "Something went wrong"
|
||||
})
|
||||
}
|
||||
if (bot) {
|
||||
res.status(200).json({
|
||||
id: bot.id,
|
||||
name: bot.name,
|
||||
description: bot.description,
|
||||
long_description: bot.long_description,
|
||||
tags: bot.tags,
|
||||
owners: bot.owners,
|
||||
premium: bot.premium,
|
||||
servers: bot.servers,
|
||||
users: bot.users,
|
||||
votes: bot.votes
|
||||
})
|
||||
} else {
|
||||
res.status(403).json({
|
||||
error: "No bot found"
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
router.get('/bots/check/:id', function (req, res) {
|
||||
votes.findOne({ user: req.params.id }, function (err, vote) {
|
||||
if (err) {
|
||||
res.status(503).json({
|
||||
error: "Something went wrong"
|
||||
})
|
||||
}
|
||||
if (vote) {
|
||||
res.status(200).json({
|
||||
vote: true
|
||||
})
|
||||
} else {
|
||||
res.status(403).json({
|
||||
vote: false
|
||||
})
|
||||
}
|
||||
});
|
||||
})
|
||||
} else {
|
||||
res.status(401).json({
|
||||
message: "Please provide a bot token"
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
router.get('/bots/search/:id', function (req, res) {
|
||||
bots.findOne({ id: req.params.id }, function (err, bot) {
|
||||
if (err) {
|
||||
res.status(503).json({
|
||||
error: "Something went wrong"
|
||||
})
|
||||
}
|
||||
if (bot) {
|
||||
res.status(200).json({
|
||||
id: bot.id,
|
||||
name: bot.name,
|
||||
description: bot.description,
|
||||
long_description: bot.long_description,
|
||||
tags: bot.tags,
|
||||
owners: bot.owners,
|
||||
premium: bot.premium,
|
||||
servers: bot.servers,
|
||||
users: bot.users,
|
||||
votes: bot.votes
|
||||
})
|
||||
} else {
|
||||
res.status(403).json({
|
||||
error: "No bot found"
|
||||
})
|
||||
}
|
||||
});
|
||||
});
|
||||
router.get('/bots/check/:id', function (req, res) {
|
||||
votes.findOne({ user: req.params.id }, function (err, vote) {
|
||||
if (err) {
|
||||
res.status(503).json({
|
||||
error: "Something went wrong"
|
||||
})
|
||||
}
|
||||
if (vote) {
|
||||
res.status(200).json({
|
||||
vote: true
|
||||
})
|
||||
} else {
|
||||
res.status(403).json({
|
||||
vote: false
|
||||
})
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
module.exports = router;
|
||||
Reference in new issue
Block a user