initialize project with basic structure and dependencies
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { db } from "../../../db/index";
|
||||
import { topics, lessons } from "../../../db/schema";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { generateLesson } from "../../../utils/generateLesson";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const id = getRouterParam(event, "id")!;
|
||||
|
||||
const topic = await db.query.topics.findFirst({ where: eq(topics.id, id) });
|
||||
if (!topic) throw createError({ statusCode: 404, message: "Topic not found" });
|
||||
|
||||
if (topic.status === "ready") {
|
||||
return { status: "ready" };
|
||||
}
|
||||
|
||||
if (topic.status === "generating") {
|
||||
return { status: "generating" };
|
||||
}
|
||||
|
||||
try {
|
||||
await generateLesson(id);
|
||||
return { status: "ready" };
|
||||
} catch (err: any) {
|
||||
console.error(`[generate.post] topic ${id} failed: ${err?.message ?? err}`);
|
||||
return { status: "error" };
|
||||
}
|
||||
});
|
||||
@@ -14,5 +14,6 @@ export default defineEventHandler(async (event) => {
|
||||
return {
|
||||
...lesson,
|
||||
content: JSON.parse(lesson.content),
|
||||
branchStatus: lesson.branchStatus,
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user