@learnpack/learnpack 5.0.288 → 5.0.290

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -458,6 +458,7 @@ class ServeCommand extends SessionCommand_1.default {
458
458
  await uploadFileToBucket(bucket, JSON.stringify(syllabusJson), `courses/${courseSlug}/.learn/initialSyllabus.json`);
459
459
  res.json({ status: "SUCCESS" });
460
460
  });
461
+ // TODO: Check if this command is being used
461
462
  app.post("/actions/generate-image/:courseSlug", async (req, res) => {
462
463
  const rigoToken = req.header("x-rigo-token");
463
464
  const { courseSlug } = req.params;
@@ -674,7 +675,6 @@ class ServeCommand extends SessionCommand_1.default {
674
675
  const { slug } = req.params;
675
676
  const courseSlug = req.query.slug;
676
677
  const lang = req.query.lang || "en";
677
- console.log("LANG", lang);
678
678
  if (!courseSlug) {
679
679
  return res.status(400).json({ error: "Missing courseSlug" });
680
680
  }
@@ -1024,44 +1024,6 @@ class ServeCommand extends SessionCommand_1.default {
1024
1024
  return res.status(500).json({ error: "Error getting syllabus" });
1025
1025
  }
1026
1026
  });
1027
- // app.post("/actions/continue-course/:courseSlug", async (req, res) => {
1028
- // console.log("POST /actions/continue-course/:courseSlug")
1029
- // const { courseSlug } = req.params
1030
- // const { feedback }: { feedback: string } = req.body
1031
- // const rigoToken = req.header("x-rigo-token")
1032
- // const bcToken = req.header("x-breathecode-token")
1033
- // if (!rigoToken || !bcToken) {
1034
- // return res.status(400).json({ error: "Missing tokens" })
1035
- // }
1036
- // const syllabus = await bucket.file(
1037
- // `courses/${courseSlug}/.learn/initialSyllabus.json`
1038
- // )
1039
- // const [content] = await syllabus.download()
1040
- // const syllabusJson: Syllabus = JSON.parse(content.toString())
1041
- // const notGeneratedLessons = syllabusJson.lessons.filter(
1042
- // lesson => !lesson.generated
1043
- // )
1044
- // const lastGeneratedLesson = findLast(
1045
- // syllabusJson.lessons,
1046
- // lesson => lesson.generated ?? false
1047
- // )
1048
- // console.log("ABout to generate", notGeneratedLessons.length, "lessons")
1049
- // const firstLessonToGenerate = notGeneratedLessons[0]
1050
- // const completionId = await startExerciseGeneration(
1051
- // rigoToken,
1052
- // syllabusJson.lessons,
1053
- // syllabusJson.courseInfo,
1054
- // firstLessonToGenerate,
1055
- // courseSlug,
1056
- // syllabusJson.courseInfo.purpose,
1057
- // JSON.stringify(lastGeneratedLesson) +
1058
- // `\n\nThe user provided this feedback in relation to the course: ${feedback}`
1059
- // )
1060
- // return res.json({
1061
- // message: "Course continued",
1062
- // slug: courseSlug,
1063
- // })
1064
- // })
1065
1027
  app.get("/courses/:courseSlug/exercises/:exerciseSlug/", async (req, res) => {
1066
1028
  var _a;
1067
1029
  console.log("GET /courses/:courseSlug/exercises/:exerciseSlug/");
@@ -1382,43 +1344,57 @@ class ServeCommand extends SessionCommand_1.default {
1382
1344
  try {
1383
1345
  let outputPath;
1384
1346
  let filename;
1385
- if (format === "scorm") {
1386
- outputPath = await (0, export_1.exportToScorm)({
1387
- courseSlug: course_slug,
1388
- format: "scorm",
1389
- bucket,
1390
- outDir: path.join(__dirname, "../output/directory"),
1391
- });
1392
- filename = `${course_slug}-scorm.zip`;
1393
- }
1394
- else if (format === "epub") {
1395
- console.log("EPUB export", metadata);
1396
- // Validate required metadata for EPUB
1397
- if (!metadata ||
1398
- !metadata.creator ||
1399
- !metadata.publisher ||
1400
- !metadata.title ||
1401
- !metadata.rights ||
1402
- !metadata.lang) {
1403
- console.log("Missing required metadata for EPUB export", metadata);
1347
+ switch (format) {
1348
+ case "scorm": {
1349
+ outputPath = await (0, export_1.exportToScorm)({
1350
+ courseSlug: course_slug,
1351
+ format: "scorm",
1352
+ bucket,
1353
+ outDir: path.join(__dirname, "../output/directory"),
1354
+ });
1355
+ filename = `${course_slug}-scorm.zip`;
1356
+ break;
1357
+ }
1358
+ case "zip": {
1359
+ outputPath = await (0, export_1.exportToZip)({
1360
+ courseSlug: course_slug,
1361
+ format: "zip",
1362
+ bucket,
1363
+ outDir: path.join(__dirname, "../output/directory"),
1364
+ });
1365
+ filename = `${course_slug}.zip`;
1366
+ break;
1367
+ }
1368
+ case "epub": {
1369
+ console.log("EPUB export", metadata);
1370
+ // Validate required metadata for EPUB
1371
+ if (!metadata ||
1372
+ !metadata.creator ||
1373
+ !metadata.publisher ||
1374
+ !metadata.title ||
1375
+ !metadata.rights ||
1376
+ !metadata.lang) {
1377
+ console.log("Missing required metadata for EPUB export", metadata);
1378
+ return res.status(400).json({
1379
+ error: "Missing required metadata for EPUB export",
1380
+ required: ["creator", "publisher", "title", "rights", "lang"],
1381
+ });
1382
+ }
1383
+ outputPath = await (0, export_1.exportToEpub)({
1384
+ courseSlug: course_slug,
1385
+ format: "epub",
1386
+ bucket,
1387
+ outDir: path.join(__dirname, "../output/directory"),
1388
+ language: language,
1389
+ }, metadata);
1390
+ filename = `${course_slug}.epub`;
1391
+ break;
1392
+ }
1393
+ default: {
1404
1394
  return res.status(400).json({
1405
- error: "Missing required metadata for EPUB export",
1406
- required: ["creator", "publisher", "title", "rights", "lang"],
1395
+ error: "Invalid format. Supported formats: scorm, epub, zip",
1407
1396
  });
1408
1397
  }
1409
- outputPath = await (0, export_1.exportToEpub)({
1410
- courseSlug: course_slug,
1411
- format: "epub",
1412
- bucket,
1413
- outDir: path.join(__dirname, "../output/directory"),
1414
- language: language,
1415
- }, metadata);
1416
- filename = `${course_slug}.epub`;
1417
- }
1418
- else {
1419
- return res.status(400).json({
1420
- error: "Invalid format. Supported formats: scorm, epub",
1421
- });
1422
1398
  }
1423
1399
  // Send the file and clean up
1424
1400
  res.download(outputPath, filename, err => {