| const express = require('express'); | |
| const fs = require('fs'); | |
| const path = require('os'); | |
| const axios = require('axios'); | |
| const cheerio = require('cheerio'); | |
| const app = express(); | |
| const port = 7860; | |
| const allowed = ['MLBB', 'BS', 'PUBG']; | |
| async function fetchKey(game) { | |
| if (!allowed.includes(game)) throw new Error('Invalid game'); | |
| const idxRes = await axios.get('https://web.aachann.my.id/Get-key/'); | |
| const m = idxRes.data.match(/const sessionToken\s*=\s*["']([^"']+)["']/); | |
| if (!m) throw new Error('sessionToken not found'); | |
| const sessionToken = m[1]; | |
| const data = Buffer.from(`game=${game}&token=${sessionToken}`).toString('base64'); | |
| const genRes = await axios.get(`https://web.aachann.my.id/Get-key/genkey.php?data=${data}`); | |
| const $ = cheerio.load(genRes.data); | |
| const key = $('#gameKey').text().trim(); | |
| if (!key) throw new Error('key not found in response'); | |
| return key; | |
| } | |
| app.get('/key', async (req, res) => { | |
| try { | |
| const game = (req.query.game || 'MLBB').toUpperCase(); | |
| const key = await fetchKey(game); | |
| res.json({ game, key }); | |
| } catch (e) { | |
| res.status(500).json({ error: e.message }); | |
| } | |
| }); | |
| app.get('/key/bulk', async (req, res) => { | |
| try { | |
| const game = (req.query.game || 'MLBB').toUpperCase(); | |
| const qty = Math.min(parseInt(req.query.qty) || 10, 1000); | |
| const keys = []; | |
| for (let i = 0; i < qty; i++) keys.push(await fetchKey(game)); | |
| const file = `${path.tmpdir()}/${game}-${Date.now()}.txt`; | |
| fs.writeFileSync(file, keys.join('\n')); | |
| res.download(file, `${game}-keys.txt`, () => fs.unlinkSync(file)); | |
| } catch (e) { | |
| res.status(500).json({ error: e.message }); | |
| } | |
| }); | |
| app.listen(port, () => console.log(`Running on :${port}`)); | |