Next.js 15 app that turns photos, PDFs, DOCX/PPTX and text into a swipeable feed of AI-generated activities (flashcards, multiple choice, true/false, fill-in-the-blank, matching, ordering, short answer) using the user's own Ollama models. Highlights: - All AI calls run in server route handlers; the browser never talks to Ollama. - Bring-your-own-key mode (default): the key lives only in the browser and is sent per-request; server, local-daemon and shared-key modes also supported. - Client-side document extraction (pdf.js, mammoth, jszip) with scanned-PDF page rendering for the vision model; notes stay in their original language. - ChatGPT-style shell: collapsible sidebar / mobile drawer, neutral token-based light + dark themes, folder organisation, PWA (manifest, SW, offline page). - Strict JSON validation with zod + auto-repair, rate limiting, and request guards (cross-origin, body-size, API-key sanitising). - setup.sh bootstraps deps, .env.local and a production build. Gitignore excludes .env*, the generated pdf.js worker and local scratch files.
44 lines
1.5 KiB
TypeScript
44 lines
1.5 KiB
TypeScript
"use client";
|
|
|
|
import { FillBlank } from "./FillBlank";
|
|
import { Flashcard } from "./Flashcard";
|
|
import { Matching } from "./Matching";
|
|
import { MultipleChoice } from "./MultipleChoice";
|
|
import { Ordering } from "./Ordering";
|
|
import { ShortAnswer } from "./ShortAnswer";
|
|
import { TrueFalse } from "./TrueFalse";
|
|
import { type ActivityComponentProps } from "./shared";
|
|
|
|
export type { ActivityComponentProps } from "./shared";
|
|
export { TYPE_META } from "./shared";
|
|
|
|
/**
|
|
* Renders an activity from JSON based on its `type` field.
|
|
* Every activity type is a self-contained React component.
|
|
*/
|
|
export function ActivityRenderer(props: ActivityComponentProps) {
|
|
const { activity } = props;
|
|
|
|
switch (activity.type) {
|
|
case "flashcard":
|
|
return <Flashcard {...props} activity={activity} />;
|
|
case "multiple_choice":
|
|
return <MultipleChoice {...props} activity={activity} />;
|
|
case "true_false":
|
|
return <TrueFalse {...props} activity={activity} />;
|
|
case "fill_blank":
|
|
return <FillBlank {...props} activity={activity} />;
|
|
case "matching":
|
|
return <Matching {...props} activity={activity} />;
|
|
case "ordering":
|
|
return <Ordering {...props} activity={activity} />;
|
|
case "short_answer":
|
|
return <ShortAnswer {...props} activity={activity} />;
|
|
default: {
|
|
// Exhaustiveness guard: adding a new activity type without a component
|
|
// becomes a TypeScript error.
|
|
const never: never = activity;
|
|
return <p className="text-sm">Unsupported activity: {JSON.stringify(never)}</p>;
|
|
}
|
|
}
|
|
}
|