// Mealie probe (no writes): after the API sign-in, what the box holds and what the frontend keeps for language. const puppeteer = require('puppeteer'); const fs = require('fs'); const sleep = ms => new Promise(r => setTimeout(r, ms)); const S = JSON.parse(fs.readFileSync('/out/secrets.json')); const D = process.env.DOMAIN, URL = `https://${process.env.SUB}.${D}`; (async () => { const b = await puppeteer.launch({args: ['--no-sandbox', '--ignore-certificate-errors', '--lang=hu-HU', '--host-resolver-rules=MAP * ' + process.env.TRAEFIK]}); const p = await b.newPage(); await p.setCookie({name: 'felhom_session', value: S.session, domain: `felhom.${D}`, path: '/', secure: true}); await p.goto(URL + '/login', {waitUntil: 'networkidle2'}); const r = await p.evaluate(async (pw) => { const fd = new URLSearchParams({username: 'changeme@example.com', password: pw, remember_me: 'true'}); const st = (await fetch('/api/auth/token', {method: 'POST', body: fd})).status; const g = async (u, n = 400) => { const x = await fetch(u); return [x.status, (await x.text()).slice(0, n)]; }; const rec = await g('/api/recipes?perPage=50', 1e6); return {st, recipes: rec[0] + ' ' + (rec[1].match(/"total":\d+/) || [''])[0], names: (rec[1].match(/"name":"[^"]+"/g) || []).join(','), startup: await g('/api/app/about/startup-info'), self: Object.keys(JSON.parse((await g('/api/users/self', 1e6))[1] || '{}'))}; }, S.gen.ADMIN_PASSWORD); console.log(JSON.stringify(r).replace(/"(access_)?tok[a-z_]*":"[^"]*"/gi, '"…":"…"')); await p.goto(URL + '/g/home', {waitUntil: 'networkidle2'}); await sleep(2000); console.log('g/home ->', p.url(), JSON.stringify(await p.evaluate(() => Object.keys(localStorage))), JSON.stringify((await p.cookies()).map(c => c.name))); await b.close(); })().catch(e => { console.error(e); process.exit(1); });