pineafan | 513c0a2 | 2021-09-04 09:54:42 +0100 | [diff] [blame] | 1 | import { MongoClient } from 'mongodb'; |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 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 | |
pineafan | aed3024 | 2021-09-04 09:33:40 +0100 | [diff] [blame] | 8 | const Validate = (req, res) => { |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 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}); |
pineafan | 98f4297 | 2021-09-04 10:01:56 +0100 | [diff] [blame] | 12 | |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 13 | if (!db_response) return resolve(res.status(404).end()); |
| 14 | if (db_response.timestamp + (1800) >= Date.now()) return resolve(res.status(410)); |
pineafan | 98f4297 | 2021-09-04 10:01:56 +0100 | [diff] [blame] | 15 | |
pineafan | c540da9 | 2021-09-03 20:33:36 +0100 | [diff] [blame] | 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 | }) |
pineafan | aed3024 | 2021-09-04 09:33:40 +0100 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | export default Validate; |