pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame^] | 1 | import MongoClient from 'mongodb'; |
| 2 | |
| 3 | |
| 4 | const url = 'mongodb://rsm:LJMy*orVFAATQ5PaX7EKXq74&HCDFaLE@192.168.101.2:27017/rsm'; |
| 5 | const db = 'rsm'; |
| 6 | const collection = 'rsmv-tokens' |
| 7 | |
| 8 | export default (req, res) => { |
| 9 | return new Promise((resolve, reject) => { |
| 10 | MongoClient.connect(url, async function(err, client) { |
| 11 | let db_response = await client.db(db).collection(collection).findOne({code: req.body.code}); |
| 12 | |
| 13 | if (!db_response) return resolve(res.status(404).end()); |
| 14 | if (db_response.timestamp + (1800) >= Date.now()) return resolve(res.status(410)); |
| 15 | |
| 16 | let props = { |
| 17 | user: db_response.user, |
| 18 | role: db_response.role, |
| 19 | role_name: db_response.role_name, |
| 20 | guild: db_response.guild, |
| 21 | guild_name: db_response.guild_name, |
| 22 | guild_icon_url: db_response.guild_icon_url, |
| 23 | guild_size: db_response.guild_size |
| 24 | } |
| 25 | return resolve(res.status(200).send(props)); |
| 26 | }) |
| 27 | }) |
| 28 | } |