| 114 | } |
| 115 | |
| 116 | function parseDatabaseUrl(url) { |
| 117 | if (!url) throw new Error("DATABASE_URL not found"); |
| 118 | if (!url.startsWith("mysql://")) |
| 119 | throw new Error("DATABASE_URL is not a MySQL URL"); |
| 120 | |
| 121 | const parsed = new URL(url); |
| 122 | const config = { |
| 123 | host: parsed.hostname, |
| 124 | port: parsed.port ? parseInt(parsed.port, 10) : 3306, |
| 125 | user: parsed.username, |
| 126 | password: parsed.password, |
| 127 | database: parsed.pathname.slice(1), |
| 128 | ssl: { |
| 129 | rejectUnauthorized: false, |
| 130 | }, |
| 131 | }; |
| 132 | |
| 133 | return config; |
| 134 | } |
| 135 | |
| 136 | async function getVideoIds() { |
| 137 | const dbUrl = process.env.DATABASE_URL; |