| 2 | const { RegisterConnection } = require('../db/Connections.js') |
| 3 | |
| 4 | function ParseCredentials(credentials) { |
| 5 | if (!credentials || credentials === "null") return ParseError(`^3Can't find credentials in server.cfg.^0`); |
| 6 | |
| 7 | const values = {}; |
| 8 | if (!credentials.includes("mysql://")) |
| 9 | credentials.split(';').forEach((item) => { |
| 10 | const [key, value] = item.split('='); |
| 11 | if (key && value) |
| 12 | values[key.trim()] = value.trim(); |
| 13 | }); |
| 14 | else { |
| 15 | const urlParts = new URL(credentials); |
| 16 | values.user = urlParts.username; |
| 17 | values.password = urlParts.password; |
| 18 | values.host = urlParts.hostname; |
| 19 | values.port = urlParts.port; |
| 20 | values.database = urlParts.pathname.slice(1); |
| 21 | } |
| 22 | |
| 23 | if (!values.host || !values.user || !values.database) { |
| 24 | ParseError(`^1Invalid credentials provided in server.cfg.^0`); |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | const host = values.host; |
| 29 | const user = values.user; |
| 30 | const password = values.password || ''; |
| 31 | const database = values.database; |
| 32 | const port = values.port || '3306'; |
| 33 | |
| 34 | return { |
| 35 | host: host, |
| 36 | user: user, |
| 37 | password: password, |
| 38 | database: database, |
| 39 | port: port |
| 40 | }; |
| 41 | } |
| 42 | |
| 43 | async function ReadCFG() { |
| 44 | var i = 0; |