summaryrefslogtreecommitdiff
path: root/app/routes/api.scrape-status.ts
blob: 28d08d4afd00960edd3415bb55b31b78e16fe998 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/**
 * GET /api/scrape-status?run_id=xxx — 指定 run_id の結果を返す
 * GET /api/scrape-status           — 最新 run の結果を返す
 */
import type { Route } from "./+types/api.scrape-status";
import { getScrapeRunById, getLatestScrapeRun } from "~/lib/db.server";

export async function loader({ request }: Route.LoaderArgs) {
  const url = new URL(request.url);
  const run_id = url.searchParams.get("run_id");

  const logs = run_id ? getScrapeRunById(run_id) : getLatestScrapeRun();
  const running = logs.some((l) => l.status === "running");

  return Response.json({ running, results: logs });
}