import { ContentTable, db } from "@/lib/mastoauth/kysely";
import { nanoid } from "nanoid";
import { cookies } from "next/headers";
import { NextRequest } from "next/server";

export async function GET(request: NextRequest) {
  const until = parseInt(request.nextUrl.searchParams.get("until") || Date.now().toString());
  let content = await db
    .selectFrom('content')
    .where('content.submitted', '<', until)
    .limit(20)
    .orderBy('content.submitted', 'desc')
    .selectAll()
    .execute();

  if (content == null) return new Response('', {
    status: 500
  });

  return Response.json(content);
}