import { zip } from "https://esm.town/v/pomdtr/sql";
import { db } from "https://esm.town/v/sqlite/db?v=9";
import { renderTable } from "npm:console-table-printer";
import stripAnsi from "npm:strip-ansi";
export default async function() {
const res = await db.execute(
"SELECT author_username, COUNT(*) AS val_count FROM vals GROUP BY author_username ORDER BY 2 DESC LIMIT 10",
);
const table = stripAnsi(renderTable(zip(res)));
const resp = await fetch("https://sourcecodeshots.com/api/image", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(
{ code: table, language: "text" },
),
});
if (!resp.ok) {
throw new Error(await resp.text());
}
return new Response(resp.body, {
headers: {
"Content-Type": "image/png",
"Cache-Control": "fsjkdfdsjkj"
},
});
}