Files
hobbs-iac/tv app/Hobbs-Family-Organizer-Self-Hosted-v1.0.0/app/api/admin/calendars/test/route.ts
T
jeremy 8715589cbb feat(hobbs-organizer): v1.1.0 password-protected LAN-only admin for calendar links
- /admin: first-visit password setup (scrypt), signed 30-day session cookie,
  calendars add/remove/reorder/rename/color/hide, masked URLs, per-feed test,
  history (20) with restore; /photo-admin -> /admin#photos placeholder
- settings in local /data (settings.json + auth.json + history/), seeded once
  from the calendar secret; dashboard + health read from settings
- start.mjs drops privileges after reading secrets and runs a front proxy that
  stamps the real client IP; admin refuses non-LAN and proxied requests
- deploy: HOBBS_DATA_DIR=/var/lib/hobbs-organizer/data, image 1.1.0 (1.0.0 kept)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E9NnVEico3WvFxLyjy1iW3
2026-11-04 18:55:00 -06:00

33 lines
1.4 KiB
TypeScript

import { json, readJsonBody, requireAdmin } from "../../../../_lib/auth";
import { addCalendarDays, organizerDate, readCalendar } from "../../../../_lib/calendar-feed";
import { readSettings, validCalendarUrl } from "../../../../_lib/store";
export const dynamic = "force-dynamic";
/** Fetches one feed (saved by id, or a not-yet-saved URL) and reports what it found. */
export async function POST(request: Request) {
const denied = await requireAdmin(request, { mutating: true });
if (denied) return denied;
const body = await readJsonBody<{ id?: string; url?: string }>(request);
let url: string | null = null;
if (body?.url) url = validCalendarUrl(body.url);
else if (body?.id) url = (await readSettings()).calendars.find((calendar) => calendar.id === body.id)?.url ?? null;
if (!url) return json({ ok: false, error: "Not a Google Calendar basic.ics address." }, 400);
const now = Date.now();
const today = organizerDate(new Date(now));
try {
const result = await readCalendar(
url,
{ feedIndex: 0, tone: "cyan", nameOverride: "" },
now,
now + 60 * 24 * 60 * 60 * 1_000,
today,
addCalendarDays(today, 60),
);
return json({ ok: true, sourceName: result.sourceName, eventCount: result.eventCount, upcoming: result.items.length });
} catch (error) {
return json({ ok: false, error: error instanceof Error ? error.message : "Fetch failed" });
}
}