@learnpack/learnpack 5.0.252 → 5.0.254

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.
@@ -445,6 +445,21 @@ class ServeCommand extends SessionCommand_1.default {
445
445
  const [exists] = await file.exists();
446
446
  res.json({ exists, file: file.name });
447
447
  });
448
+ app.post("/webhooks/:courseSlug/:exSlug/:lang/update-readme/:notificationId", async (req, res) => {
449
+ console.log("RECEIVING README UPDATE WEBHOOK");
450
+ const { courseSlug, exSlug, lang, notificationId } = req.params;
451
+ const body = req.body;
452
+ console.log("BODY", body);
453
+ const readmePath = `courses/${courseSlug}/exercises/${exSlug}/README${(0, creatorUtilities_1.getReadmeExtension)(lang)}`;
454
+ if (body.parsed.content) {
455
+ await uploadFileToBucket(bucket, body.parsed.content, readmePath);
456
+ }
457
+ (0, creatorSocket_1.emitToNotification)(notificationId, {
458
+ status: "SUCCESS",
459
+ message: "Readme updated successfully",
460
+ });
461
+ res.json({ status: "SUCCESS" });
462
+ });
448
463
  app.get("/create", (req, res) => {
449
464
  console.log("GET /create");
450
465
  res.redirect("/creator/");
@@ -516,8 +531,17 @@ class ServeCommand extends SessionCommand_1.default {
516
531
  foundLang = match[1].toLowerCase();
517
532
  }
518
533
  const [contentBuffer] = await bucket.file(selectedFile).download();
519
- const { attributes, body } = frontMatter(contentBuffer.toString());
520
- res.send({ attributes, body, lang: foundLang });
534
+ try {
535
+ const { attributes, body } = frontMatter(contentBuffer.toString());
536
+ res.send({ attributes, body, lang: foundLang });
537
+ }
538
+ catch (_a) {
539
+ res.status(200).json({
540
+ attributes: {},
541
+ body: contentBuffer.toString(),
542
+ lang: foundLang,
543
+ });
544
+ }
521
545
  }
522
546
  catch (error) {
523
547
  console.error(error);
package/lib/utils/api.js CHANGED
@@ -422,6 +422,7 @@ const updateRigoAssetID = async (token, slug, asset_id) => {
422
422
  const headers = {
423
423
  Authorization: "Token " + token.trim(),
424
424
  };
425
+ console.log("HEADERS", headers);
425
426
  try {
426
427
  const response = await axios_1.default.put(url, { asset_id }, { headers });
427
428
  return response.data;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@learnpack/learnpack",
3
3
  "description": "Seamlessly build, sell and/or take interactive & auto-graded tutorials, start learning now or build a new tutorial to your audience.",
4
- "version": "5.0.252",
4
+ "version": "5.0.254",
5
5
  "author": "Alejandro Sanchez @alesanchezr",
6
6
  "contributors": [
7
7
  {
@@ -715,6 +715,32 @@ export default class ServeCommand extends SessionCommand {
715
715
  res.json({ exists, file: file.name })
716
716
  })
717
717
 
718
+ app.post(
719
+ "/webhooks/:courseSlug/:exSlug/:lang/update-readme/:notificationId",
720
+ async (req, res) => {
721
+ console.log("RECEIVING README UPDATE WEBHOOK")
722
+ const { courseSlug, exSlug, lang, notificationId } = req.params
723
+ const body = req.body
724
+
725
+ console.log("BODY", body)
726
+
727
+ const readmePath = `courses/${courseSlug}/exercises/${exSlug}/README${getReadmeExtension(
728
+ lang
729
+ )}`
730
+
731
+ if (body.parsed.content) {
732
+ await uploadFileToBucket(bucket, body.parsed.content, readmePath)
733
+ }
734
+
735
+ emitToNotification(notificationId, {
736
+ status: "SUCCESS",
737
+ message: "Readme updated successfully",
738
+ })
739
+
740
+ res.json({ status: "SUCCESS" })
741
+ }
742
+ )
743
+
718
744
  app.get("/create", (req, res) => {
719
745
  console.log("GET /create")
720
746
  res.redirect("/creator/")
@@ -809,9 +835,16 @@ export default class ServeCommand extends SessionCommand {
809
835
  }
810
836
 
811
837
  const [contentBuffer] = await bucket.file(selectedFile).download()
812
- const { attributes, body } = frontMatter(contentBuffer.toString())
813
-
814
- res.send({ attributes, body, lang: foundLang })
838
+ try {
839
+ const { attributes, body } = frontMatter(contentBuffer.toString())
840
+ res.send({ attributes, body, lang: foundLang })
841
+ } catch {
842
+ res.status(200).json({
843
+ attributes: {},
844
+ body: contentBuffer.toString(),
845
+ lang: foundLang,
846
+ })
847
+ }
815
848
  } catch (error) {
816
849
  console.error(error)
817
850
  res.status(500).json({ error: "Internal server error" })