scorm-player 1.2.2 → 1.2.3

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/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { SupabaseClient } from '@supabase/supabase-js';
2
2
 
3
3
  interface ParsedSCORM {
4
- files: Record<string, string>;
4
+ files: Record<string, string | Buffer>;
5
5
  manifestXml: string;
6
6
  }
7
7
  declare function unpackSCORM(zipData: Buffer | Uint8Array): Promise<ParsedSCORM>;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { SupabaseClient } from '@supabase/supabase-js';
2
2
 
3
3
  interface ParsedSCORM {
4
- files: Record<string, string>;
4
+ files: Record<string, string | Buffer>;
5
5
  manifestXml: string;
6
6
  }
7
7
  declare function unpackSCORM(zipData: Buffer | Uint8Array): Promise<ParsedSCORM>;
package/dist/index.js CHANGED
@@ -46,14 +46,34 @@ async function unpackSCORM(zipData) {
46
46
  const file = zip.files[filename];
47
47
  if (!file)
48
48
  continue;
49
- const content = await file.async("string");
49
+ if (file.dir)
50
+ continue;
51
+ const ext = filename.split(".").pop()?.toLowerCase() || "";
52
+ const binaryExts = [
53
+ "jpg",
54
+ "jpeg",
55
+ "png",
56
+ "gif",
57
+ "svg",
58
+ "ico",
59
+ "woff",
60
+ "woff2",
61
+ "ttf",
62
+ "mp3",
63
+ "mp4"
64
+ ];
65
+ const content = binaryExts.includes(ext) ? await file.async("nodebuffer") : await file.async("string");
50
66
  files[filename] = content;
51
67
  }
52
68
  const manifestXml = files["imsmanifest.xml"];
53
69
  if (!manifestXml) {
54
70
  throw new Error("imsmanifest.xml not found in SCORM package");
55
71
  }
56
- return { files, manifestXml };
72
+ if (Buffer.isBuffer(manifestXml)) {
73
+ return { files, manifestXml: manifestXml.toString("utf-8") };
74
+ } else {
75
+ return { files, manifestXml };
76
+ }
57
77
  }
58
78
 
59
79
  // src/backend/parseManifest.ts
@@ -80,16 +100,15 @@ var SupabaseAdapter = class {
80
100
  this.client = (0, import_supabase_js.createClient)(supabaseUrl, supabaseKey);
81
101
  this.rootFolder = rootFolder;
82
102
  }
83
- // Генерация уникального имени папки
84
103
  generateUniqueFolder(baseName) {
85
104
  return `${baseName}-${(0, import_uuid.v4)()}`;
86
105
  }
87
106
  async uploadFile(path, content) {
88
107
  const fullPath = `${this.rootFolder}/${path}`;
89
- await this.client.storage.from(this.rootFolder).upload(path, content, { upsert: true });
108
+ const fileContent = typeof content === "string" ? Buffer.from(content, "utf-8") : content;
109
+ await this.client.storage.from(this.rootFolder).upload(path, fileContent, { upsert: true });
90
110
  return fullPath;
91
111
  }
92
- // Принимаем files и optional baseName для папки
93
112
  async uploadFolder(files, baseFolderName = "course") {
94
113
  const uniqueFolder = this.generateUniqueFolder(baseFolderName);
95
114
  for (const [filePath, content] of Object.entries(files)) {
@@ -98,11 +117,9 @@ var SupabaseAdapter = class {
98
117
  }
99
118
  return uniqueFolder;
100
119
  }
101
- // Получаем публичный URL полного пути к файлу
102
120
  getFileUrl(path) {
103
121
  return this.client.storage.from(this.rootFolder).getPublicUrl(path).data.publicUrl;
104
122
  }
105
- // Удобная функция для получения URL к launch файлу
106
123
  getLaunchUrl(folderName, launchPath) {
107
124
  const fullPath = `${folderName}/${launchPath}`;
108
125
  return this.getFileUrl(fullPath);
package/dist/index.mjs CHANGED
@@ -7,14 +7,34 @@ async function unpackSCORM(zipData) {
7
7
  const file = zip.files[filename];
8
8
  if (!file)
9
9
  continue;
10
- const content = await file.async("string");
10
+ if (file.dir)
11
+ continue;
12
+ const ext = filename.split(".").pop()?.toLowerCase() || "";
13
+ const binaryExts = [
14
+ "jpg",
15
+ "jpeg",
16
+ "png",
17
+ "gif",
18
+ "svg",
19
+ "ico",
20
+ "woff",
21
+ "woff2",
22
+ "ttf",
23
+ "mp3",
24
+ "mp4"
25
+ ];
26
+ const content = binaryExts.includes(ext) ? await file.async("nodebuffer") : await file.async("string");
11
27
  files[filename] = content;
12
28
  }
13
29
  const manifestXml = files["imsmanifest.xml"];
14
30
  if (!manifestXml) {
15
31
  throw new Error("imsmanifest.xml not found in SCORM package");
16
32
  }
17
- return { files, manifestXml };
33
+ if (Buffer.isBuffer(manifestXml)) {
34
+ return { files, manifestXml: manifestXml.toString("utf-8") };
35
+ } else {
36
+ return { files, manifestXml };
37
+ }
18
38
  }
19
39
 
20
40
  // src/backend/parseManifest.ts
@@ -41,16 +61,15 @@ var SupabaseAdapter = class {
41
61
  this.client = createClient(supabaseUrl, supabaseKey);
42
62
  this.rootFolder = rootFolder;
43
63
  }
44
- // Генерация уникального имени папки
45
64
  generateUniqueFolder(baseName) {
46
65
  return `${baseName}-${uuidv4()}`;
47
66
  }
48
67
  async uploadFile(path, content) {
49
68
  const fullPath = `${this.rootFolder}/${path}`;
50
- await this.client.storage.from(this.rootFolder).upload(path, content, { upsert: true });
69
+ const fileContent = typeof content === "string" ? Buffer.from(content, "utf-8") : content;
70
+ await this.client.storage.from(this.rootFolder).upload(path, fileContent, { upsert: true });
51
71
  return fullPath;
52
72
  }
53
- // Принимаем files и optional baseName для папки
54
73
  async uploadFolder(files, baseFolderName = "course") {
55
74
  const uniqueFolder = this.generateUniqueFolder(baseFolderName);
56
75
  for (const [filePath, content] of Object.entries(files)) {
@@ -59,11 +78,9 @@ var SupabaseAdapter = class {
59
78
  }
60
79
  return uniqueFolder;
61
80
  }
62
- // Получаем публичный URL полного пути к файлу
63
81
  getFileUrl(path) {
64
82
  return this.client.storage.from(this.rootFolder).getPublicUrl(path).data.publicUrl;
65
83
  }
66
- // Удобная функция для получения URL к launch файлу
67
84
  getLaunchUrl(folderName, launchPath) {
68
85
  const fullPath = `${folderName}/${launchPath}`;
69
86
  return this.getFileUrl(fullPath);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scorm-player",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "SCORM 2004 player, unpacker and manifest parser for Node.js / Next.js with storage adapters and React iframe renderer.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",