@learnpack/learnpack 5.0.156 → 5.0.160

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.
package/README.md CHANGED
@@ -21,7 +21,7 @@ $ npm install -g @learnpack/learnpack
21
21
  $ learnpack COMMAND
22
22
  running command...
23
23
  $ learnpack (-v|--version|version)
24
- @learnpack/learnpack/5.0.156 win32-x64 node-v22.15.0
24
+ @learnpack/learnpack/5.0.160 win32-x64 node-v22.15.0
25
25
  $ learnpack --help [COMMAND]
26
26
  USAGE
27
27
  $ learnpack COMMAND
@@ -80,7 +80,7 @@ DESCRIPTION
80
80
  12. If there is a file within the exercises folder but not inside of any particular exercise's folder. (Warning)
81
81
  ```
82
82
 
83
- _See code: [src\commands\audit.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.156/src\commands\audit.ts)_
83
+ _See code: [src\commands\audit.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.160/src\commands\audit.ts)_
84
84
 
85
85
  ## `learnpack breakToken`
86
86
 
@@ -95,7 +95,7 @@ OPTIONS
95
95
  -y, --yes Skip all prompts and initialize an empty project
96
96
  ```
97
97
 
98
- _See code: [src\commands\breakToken.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.156/src\commands\breakToken.ts)_
98
+ _See code: [src\commands\breakToken.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.160/src\commands\breakToken.ts)_
99
99
 
100
100
  ## `learnpack clean`
101
101
 
@@ -110,7 +110,7 @@ DESCRIPTION
110
110
  Extra documentation goes here
111
111
  ```
112
112
 
113
- _See code: [src\commands\clean.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.156/src\commands\clean.ts)_
113
+ _See code: [src\commands\clean.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.160/src\commands\clean.ts)_
114
114
 
115
115
  ## `learnpack download [PACKAGE]`
116
116
 
@@ -128,7 +128,7 @@ DESCRIPTION
128
128
  Extra documentation goes here
129
129
  ```
130
130
 
131
- _See code: [src\commands\download.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.156/src\commands\download.ts)_
131
+ _See code: [src\commands\download.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.160/src\commands\download.ts)_
132
132
 
133
133
  ## `learnpack help [COMMAND]`
134
134
 
@@ -160,7 +160,7 @@ OPTIONS
160
160
  -y, --yes Skip all prompts and initialize an empty project
161
161
  ```
162
162
 
163
- _See code: [src\commands\init.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.156/src\commands\init.ts)_
163
+ _See code: [src\commands\init.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.160/src\commands\init.ts)_
164
164
 
165
165
  ## `learnpack login [PACKAGE]`
166
166
 
@@ -178,7 +178,7 @@ DESCRIPTION
178
178
  Extra documentation goes here
179
179
  ```
180
180
 
181
- _See code: [src\commands\login.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.156/src\commands\login.ts)_
181
+ _See code: [src\commands\login.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.160/src\commands\login.ts)_
182
182
 
183
183
  ## `learnpack logout [PACKAGE]`
184
184
 
@@ -196,7 +196,7 @@ DESCRIPTION
196
196
  Extra documentation goes here
197
197
  ```
198
198
 
199
- _See code: [src\commands\logout.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.156/src\commands\logout.ts)_
199
+ _See code: [src\commands\logout.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.160/src\commands\logout.ts)_
200
200
 
201
201
  ## `learnpack plugins`
202
202
 
@@ -328,7 +328,7 @@ OPTIONS
328
328
  -s, --strict strict mode
329
329
  ```
330
330
 
331
- _See code: [src\commands\publish.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.156/src\commands\publish.ts)_
331
+ _See code: [src\commands\publish.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.160/src\commands\publish.ts)_
332
332
 
333
333
  ## `learnpack serve`
334
334
 
@@ -345,7 +345,7 @@ OPTIONS
345
345
  -y, --yes Skip all prompts and initialize an empty project
346
346
  ```
347
347
 
348
- _See code: [src\commands\serve.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.156/src\commands\serve.ts)_
348
+ _See code: [src\commands\serve.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.160/src\commands\serve.ts)_
349
349
 
350
350
  ## `learnpack start`
351
351
 
@@ -367,7 +367,7 @@ OPTIONS
367
367
  -y, --yes Skip all prompts and initialize an empty project
368
368
  ```
369
369
 
370
- _See code: [src\commands\start.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.156/src\commands\start.ts)_
370
+ _See code: [src\commands\start.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.160/src\commands\start.ts)_
371
371
 
372
372
  ## `learnpack test [EXERCISESLUG]`
373
373
 
@@ -384,7 +384,7 @@ OPTIONS
384
384
  -y, --yes Skip all prompts and initialize an empty project
385
385
  ```
386
386
 
387
- _See code: [src\commands\test.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.156/src\commands\test.ts)_
387
+ _See code: [src\commands\test.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.160/src\commands\test.ts)_
388
388
 
389
389
  ## `learnpack translate`
390
390
 
@@ -398,7 +398,7 @@ OPTIONS
398
398
  -y, --yes Skip all prompts and initialize an empty project
399
399
  ```
400
400
 
401
- _See code: [src\commands\translate.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.156/src\commands\translate.ts)_
401
+ _See code: [src\commands\translate.ts](https://github.com/learnpack/learnpack-cli/blob/v5.0.160/src\commands\translate.ts)_
402
402
  <!-- commandsstop -->
403
403
 
404
404
  > > > > > > > 0cb3e56d84c197f9d008836bb573eade212b7e57
@@ -1,6 +1,8 @@
1
1
  import SessionCommand from "../utils/SessionCommand";
2
- import { TAcademy } from "../utils/api";
3
- export declare const handleAssetCreation: (sessionPayload: any, academy: TAcademy, learnJson: any, learnpackDeployUrl: string, category: number) => Promise<void>;
2
+ export declare const handleAssetCreation: (sessionPayload: {
3
+ token: string;
4
+ rigobotToken: string;
5
+ }, learnJson: any, learnpackDeployUrl: string) => Promise<void>;
4
6
  declare class BuildCommand extends SessionCommand {
5
7
  static description: string;
6
8
  static flags: {
@@ -19,32 +19,36 @@ const prompts = require("prompts");
19
19
  const rigoActions_1 = require("../utils/rigoActions");
20
20
  const misc_1 = require("../utils/misc");
21
21
  const uploadZipEndpont = api_1.RIGOBOT_HOST + "/v1/learnpack/upload";
22
- const handleAssetCreation = async (sessionPayload, academy, learnJson, learnpackDeployUrl, category) => {
22
+ const handleAssetCreation = async (sessionPayload, learnJson, learnpackDeployUrl) => {
23
23
  try {
24
- const { exists, academyId } = await api_1.default.doesAssetExists(sessionPayload.token, learnJson.slug);
24
+ const user = await api_1.default.validateToken(sessionPayload.token);
25
+ const { exists } = await api_1.default.doesAssetExists(sessionPayload.token, learnJson.slug);
25
26
  if (!exists) {
26
27
  console_1.default.info("Asset does not exist in this academy, creating it");
27
- const asset = await api_1.default.createAsset(sessionPayload.token, academy.id, {
28
+ const asset = await api_1.default.createAsset(sessionPayload.token, {
28
29
  slug: learnJson.slug,
29
30
  title: learnJson.title.us,
30
31
  lang: "us",
31
32
  description: learnJson.description.us,
32
33
  learnpack_deploy_url: learnpackDeployUrl,
33
34
  technologies: ["node", "bash"],
34
- url: "https://4geeksacademy.com",
35
- category: category,
36
- owner: sessionPayload.id,
37
- author: sessionPayload.id,
35
+ url: learnpackDeployUrl,
36
+ category: 51,
37
+ owner: user.id,
38
+ author: user.id,
39
+ preview: learnJson.preview,
38
40
  });
41
+ await api_1.default.updateRigoAssetID(sessionPayload.token, learnJson.slug, asset.id);
39
42
  console_1.default.info("Asset created with id", asset.id);
40
43
  }
41
44
  else {
42
45
  console_1.default.info("Asset exists, updating it");
43
- const asset = await api_1.default.updateAsset(sessionPayload.token, academyId, learnJson.slug, {
46
+ const asset = await api_1.default.updateAsset(sessionPayload.token, learnJson.slug, {
44
47
  learnpack_deploy_url: learnpackDeployUrl,
45
48
  title: learnJson.title.us,
46
49
  description: learnJson.description.us,
47
50
  });
51
+ await api_1.default.updateRigoAssetID(sessionPayload.rigobotToken, learnJson.slug, asset.id);
48
52
  console_1.default.info("Asset updated with id", asset.id);
49
53
  }
50
54
  }
@@ -283,9 +287,7 @@ class BuildCommand extends SessionCommand_1.default {
283
287
  console.log(res.data);
284
288
  fs.unlinkSync(zipFilePath);
285
289
  this.removeDirectory(buildDir);
286
- if (academy) {
287
- await (0, exports.handleAssetCreation)(sessionPayload, academy, learnJson, res.data.url, category);
288
- }
290
+ await (0, exports.handleAssetCreation)(sessionPayload, learnJson, res.data.url);
289
291
  }
290
292
  catch (error) {
291
293
  if (axios_1.default.isAxiosError(error)) {
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.processImage = exports.createLearnJson = void 0;
4
4
  exports.processExercise = processExercise;
5
5
  const command_1 = require("@oclif/command");
6
+ // import multer from "multer"
6
7
  // import * as ytdl from "ytdl-core"
7
8
  const youtube_transcript_1 = require("youtube-transcript");
8
9
  const express = require("express");
@@ -30,6 +31,7 @@ const misc_1 = require("../utils/misc");
30
31
  const configBuilder_1 = require("../utils/configBuilder");
31
32
  const creatorUtilities_2 = require("../utils/creatorUtilities");
32
33
  const sidebarGenerator_1 = require("../utils/sidebarGenerator");
34
+ const publish_1 = require("./publish");
33
35
  const frontMatter = require("front-matter");
34
36
  dotenv.config();
35
37
  const createLearnJson = (courseInfo) => {
@@ -250,7 +252,7 @@ class ServeCommand extends SessionCommand_1.default {
250
252
  });
251
253
  stream.end(buffer);
252
254
  });
253
- app.post("/upload-image", express.json({ limit: 20000000 }), async (req, res) => {
255
+ app.post("/upload-image", express.json({ limit: "10mb" }), async (req, res) => {
254
256
  const { image_url, destination } = req.body;
255
257
  if (!image_url || !destination) {
256
258
  return res
@@ -279,6 +281,80 @@ class ServeCommand extends SessionCommand_1.default {
279
281
  res.status(500).json({ error: error.message });
280
282
  }
281
283
  });
284
+ const upload = (0, misc_1.createUploadMiddleware)();
285
+ app.post("/upload-image-file", upload.single("file"), async (req, res) => {
286
+ console.log("UPLOADING IMAGE FILE");
287
+ const destination = req.body.destination;
288
+ // eslint-disable-next-line
289
+ // @ts-ignore
290
+ if (!req.file || !destination) {
291
+ return res
292
+ .status(400)
293
+ .json({ error: "File and destination are required" });
294
+ }
295
+ try {
296
+ // eslint-disable-next-line
297
+ // @ts-ignore
298
+ const fileData = req.file.buffer;
299
+ const file = bucket.file(destination);
300
+ await file.save(fileData, {
301
+ resumable: false,
302
+ // eslint-disable-next-line
303
+ // @ts-ignore
304
+ contentType: req.file.mimetype,
305
+ });
306
+ console.log(`✅ Image uploaded to ${file.name}`);
307
+ res.json({ message: "Image uploaded successfully", path: file.name });
308
+ }
309
+ catch (error) {
310
+ console.error("❌ upload-image-file error:", error);
311
+ res.status(500).json({ error: error.message });
312
+ }
313
+ });
314
+ app.put("/upload/preview-image/:slug", (0, misc_1.createUploadMiddleware)().single("file"), async (req, res) => {
315
+ const { slug } = req.params;
316
+ const rigoToken = req.header("x-rigo-token");
317
+ if (!rigoToken) {
318
+ return res.status(400).json({
319
+ error: "Rigo token is required. x-rigo-token header is missing",
320
+ });
321
+ }
322
+ const { isAuthor } = await (0, rigoActions_1.isPackageAuthor)(rigoToken, slug);
323
+ if (!isAuthor) {
324
+ return res.status(403).json({
325
+ error: "You are not authorized to upload a preview image",
326
+ });
327
+ }
328
+ // eslint-disable-next-line
329
+ // @ts-ignore
330
+ if (!slug || !req.file) {
331
+ return res.status(400).json({ error: "Slug and file are required" });
332
+ }
333
+ try {
334
+ const filePath = `courses/${slug}/preview.png`;
335
+ const file = bucket.file(filePath);
336
+ // eslint-disable-next-line
337
+ // @ts-ignore
338
+ await file.save(req.file.buffer, {
339
+ resumable: false,
340
+ // eslint-disable-next-line
341
+ // @ts-ignore
342
+ contentType: req.file.mimetype,
343
+ });
344
+ console.log(`✅ Preview image uploaded to ${filePath}`);
345
+ return res.json({ message: "Preview uploaded", path: filePath });
346
+ }
347
+ catch (error) {
348
+ console.error("❌ Error uploading preview image:", error);
349
+ return res.status(500).json({ error: error.message });
350
+ }
351
+ });
352
+ app.get("/check-preview-image/:slug", async (req, res) => {
353
+ const { slug } = req.params;
354
+ const file = bucket.file(`courses/${slug}/preview.png`);
355
+ const [exists] = await file.exists();
356
+ res.json({ exists, file: file.name });
357
+ });
282
358
  app.get("/create", (req, res) => {
283
359
  console.log("GET /create");
284
360
  res.redirect("/creator/");
@@ -653,14 +729,7 @@ class ServeCommand extends SessionCommand_1.default {
653
729
  const rigoRes = await axios_1.default.post(`${api_1.RIGOBOT_HOST}/v1/learnpack/upload`, form, {
654
730
  headers: Object.assign(Object.assign({}, form.getHeaders()), { Authorization: `Token ${rigoToken}` }),
655
731
  });
656
- // 11) Crear/actualizar asset en Breathecode
657
- // await handleAssetCreation(
658
- // { token: bcToken, rigobot: { key: rigoToken }, id: 0 },
659
- // { id: academyId } as any,
660
- // config,
661
- // rigoRes.data.url,
662
- // categoryId
663
- // )
732
+ await (0, publish_1.handleAssetCreation)({ token: bcToken, rigobotToken: rigoToken }, config, rigoRes.data.url);
664
733
  rimraf.sync(tmpRoot);
665
734
  console.log("RIGO RES", rigoRes.data);
666
735
  return res.json({ url: rigoRes.data.url });