import puppeteer from "puppeteer"; const BASE_URL = process.env.BASE_URL ?? "http://localhost"; const browser = await puppeteer.launch(); const page = await browser.newPage(); try { await page.goto(`${BASE_URL}/auth/signup`); await page.locator('[name="username"]').fill("admin"); await page.locator('[name="password"]').fill(process.env.ADMIN_PASSWORD); await page.locator('[type="submit"]').click(); await new Promise((resolve) => setTimeout(resolve, 5000)); if (page.content.toString().includes("This username is already taken.")) { console.log("admin user exists"); } else { console.log("admin user created"); await page.goto(`${BASE_URL}/upload`); const elementHandle = await page.$("input[type=file]"); await elementHandle.uploadFile("./flag.jpeg"); await page.locator('[name="caption"]').fill(process.env.FLAG_1); await page.locator('[type="submit"]').click(); await new Promise((resolve) => setTimeout(resolve, 5000)); } await browser.close(); } catch (e) { console.error("Script failed to run due to an error", e); process.exit(1); }