27 lines
1.3 KiB
JavaScript
27 lines
1.3 KiB
JavaScript
// Simular la APROBACION desde Discord: llama al endpoint con token bueno
|
|
// y verifica que el post termina publicado. Despues borra todo el test.
|
|
const Database = require("better-sqlite3");
|
|
const fs = require("fs");
|
|
|
|
const MOD_TOKEN = fs.readFileSync("./.env", "utf8").match(/DISCORD_MOD_TOKEN=(\w+)/)[1];
|
|
|
|
const db = new Database("./data/worst-scan.db", { readonly: true });
|
|
const row = db.prepare("SELECT id FROM posts WHERE gid = ?").get("999999999");
|
|
db.close();
|
|
|
|
if (!row) { console.log("No existe el post de prueba"); process.exit(1); }
|
|
|
|
// 1) Llamar al endpoint de aprobacion (como haria el link de Discord)
|
|
fetch(`https://worstscan.xyz/api/review/${row.id}?action=approve&token=${MOD_TOKEN}`)
|
|
.then(async (res) => {
|
|
const html = await res.text();
|
|
console.log("Endpoint approve -> HTTP", res.status);
|
|
console.log("Contiene 'Aprobado'?", html.includes("Aprobado"));
|
|
|
|
// 2) Verificar en DB que quedó publicado
|
|
const db2 = new Database("./data/worst-scan.db", { readonly: true });
|
|
const p = db2.prepare("SELECT title, published FROM posts WHERE gid = ?").get("999999999");
|
|
console.log("\nPost en DB:", p.title, "| published =", p.published, p.published === 1 ? "✅ PUBLICADO" : "❌ sigue en cuarentena");
|
|
db2.close();
|
|
})
|
|
.catch((e) => console.log("ERROR:", e.message)); |