@mo7yw4ng/openape 1.0.5 → 2.0.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.
Files changed (152) hide show
  1. package/bin/openape +29 -0
  2. package/bin/openape.js +29 -0
  3. package/package.json +22 -28
  4. package/LICENSE +0 -21
  5. package/README.md +0 -135
  6. package/esm/_dnt.polyfills.d.ts +0 -101
  7. package/esm/_dnt.polyfills.d.ts.map +0 -1
  8. package/esm/_dnt.polyfills.js +0 -127
  9. package/esm/_dnt.shims.d.ts +0 -6
  10. package/esm/_dnt.shims.d.ts.map +0 -1
  11. package/esm/_dnt.shims.js +0 -61
  12. package/esm/deno.d.ts +0 -25
  13. package/esm/deno.d.ts.map +0 -1
  14. package/esm/deno.js +0 -23
  15. package/esm/package.json +0 -3
  16. package/esm/src/commands/announcements.d.ts +0 -3
  17. package/esm/src/commands/announcements.d.ts.map +0 -1
  18. package/esm/src/commands/announcements.js +0 -134
  19. package/esm/src/commands/assignments.d.ts +0 -3
  20. package/esm/src/commands/assignments.d.ts.map +0 -1
  21. package/esm/src/commands/assignments.js +0 -230
  22. package/esm/src/commands/auth.d.ts +0 -3
  23. package/esm/src/commands/auth.d.ts.map +0 -1
  24. package/esm/src/commands/auth.js +0 -290
  25. package/esm/src/commands/calendar.d.ts +0 -3
  26. package/esm/src/commands/calendar.d.ts.map +0 -1
  27. package/esm/src/commands/calendar.js +0 -179
  28. package/esm/src/commands/courses.d.ts +0 -3
  29. package/esm/src/commands/courses.d.ts.map +0 -1
  30. package/esm/src/commands/courses.js +0 -348
  31. package/esm/src/commands/forums.d.ts +0 -3
  32. package/esm/src/commands/forums.d.ts.map +0 -1
  33. package/esm/src/commands/forums.js +0 -318
  34. package/esm/src/commands/grades.d.ts +0 -3
  35. package/esm/src/commands/grades.d.ts.map +0 -1
  36. package/esm/src/commands/grades.js +0 -121
  37. package/esm/src/commands/materials.d.ts +0 -3
  38. package/esm/src/commands/materials.d.ts.map +0 -1
  39. package/esm/src/commands/materials.js +0 -413
  40. package/esm/src/commands/quizzes.d.ts +0 -3
  41. package/esm/src/commands/quizzes.d.ts.map +0 -1
  42. package/esm/src/commands/quizzes.js +0 -271
  43. package/esm/src/commands/skills.d.ts +0 -3
  44. package/esm/src/commands/skills.d.ts.map +0 -1
  45. package/esm/src/commands/skills.js +0 -106
  46. package/esm/src/commands/upload.d.ts +0 -3
  47. package/esm/src/commands/upload.d.ts.map +0 -1
  48. package/esm/src/commands/upload.js +0 -58
  49. package/esm/src/commands/videos.d.ts +0 -3
  50. package/esm/src/commands/videos.d.ts.map +0 -1
  51. package/esm/src/commands/videos.js +0 -336
  52. package/esm/src/index.d.ts +0 -27
  53. package/esm/src/index.d.ts.map +0 -1
  54. package/esm/src/index.js +0 -160
  55. package/esm/src/lib/auth.d.ts +0 -47
  56. package/esm/src/lib/auth.d.ts.map +0 -1
  57. package/esm/src/lib/auth.js +0 -227
  58. package/esm/src/lib/config.d.ts +0 -6
  59. package/esm/src/lib/config.d.ts.map +0 -1
  60. package/esm/src/lib/config.js +0 -36
  61. package/esm/src/lib/logger.d.ts +0 -3
  62. package/esm/src/lib/logger.d.ts.map +0 -1
  63. package/esm/src/lib/logger.js +0 -27
  64. package/esm/src/lib/moodle.d.ts +0 -433
  65. package/esm/src/lib/moodle.d.ts.map +0 -1
  66. package/esm/src/lib/moodle.js +0 -1318
  67. package/esm/src/lib/session.d.ts +0 -8
  68. package/esm/src/lib/session.d.ts.map +0 -1
  69. package/esm/src/lib/session.js +0 -42
  70. package/esm/src/lib/token.d.ts +0 -38
  71. package/esm/src/lib/token.d.ts.map +0 -1
  72. package/esm/src/lib/token.js +0 -178
  73. package/esm/src/lib/types.d.ts +0 -189
  74. package/esm/src/lib/types.d.ts.map +0 -1
  75. package/esm/src/lib/types.js +0 -2
  76. package/esm/src/lib/utils.d.ts +0 -57
  77. package/esm/src/lib/utils.d.ts.map +0 -1
  78. package/esm/src/lib/utils.js +0 -129
  79. package/script/_dnt.polyfills.d.ts +0 -101
  80. package/script/_dnt.polyfills.d.ts.map +0 -1
  81. package/script/_dnt.polyfills.js +0 -130
  82. package/script/_dnt.shims.d.ts +0 -6
  83. package/script/_dnt.shims.d.ts.map +0 -1
  84. package/script/_dnt.shims.js +0 -65
  85. package/script/deno.d.ts +0 -25
  86. package/script/deno.d.ts.map +0 -1
  87. package/script/deno.js +0 -25
  88. package/script/package.json +0 -3
  89. package/script/src/commands/announcements.d.ts +0 -3
  90. package/script/src/commands/announcements.d.ts.map +0 -1
  91. package/script/src/commands/announcements.js +0 -140
  92. package/script/src/commands/assignments.d.ts +0 -3
  93. package/script/src/commands/assignments.d.ts.map +0 -1
  94. package/script/src/commands/assignments.js +0 -269
  95. package/script/src/commands/auth.d.ts +0 -3
  96. package/script/src/commands/auth.d.ts.map +0 -1
  97. package/script/src/commands/auth.js +0 -296
  98. package/script/src/commands/calendar.d.ts +0 -3
  99. package/script/src/commands/calendar.d.ts.map +0 -1
  100. package/script/src/commands/calendar.js +0 -185
  101. package/script/src/commands/courses.d.ts +0 -3
  102. package/script/src/commands/courses.d.ts.map +0 -1
  103. package/script/src/commands/courses.js +0 -354
  104. package/script/src/commands/forums.d.ts +0 -3
  105. package/script/src/commands/forums.d.ts.map +0 -1
  106. package/script/src/commands/forums.js +0 -324
  107. package/script/src/commands/grades.d.ts +0 -3
  108. package/script/src/commands/grades.d.ts.map +0 -1
  109. package/script/src/commands/grades.js +0 -127
  110. package/script/src/commands/materials.d.ts +0 -3
  111. package/script/src/commands/materials.d.ts.map +0 -1
  112. package/script/src/commands/materials.js +0 -419
  113. package/script/src/commands/quizzes.d.ts +0 -3
  114. package/script/src/commands/quizzes.d.ts.map +0 -1
  115. package/script/src/commands/quizzes.js +0 -277
  116. package/script/src/commands/skills.d.ts +0 -3
  117. package/script/src/commands/skills.d.ts.map +0 -1
  118. package/script/src/commands/skills.js +0 -112
  119. package/script/src/commands/upload.d.ts +0 -3
  120. package/script/src/commands/upload.d.ts.map +0 -1
  121. package/script/src/commands/upload.js +0 -64
  122. package/script/src/commands/videos.d.ts +0 -3
  123. package/script/src/commands/videos.d.ts.map +0 -1
  124. package/script/src/commands/videos.js +0 -342
  125. package/script/src/index.d.ts +0 -27
  126. package/script/src/index.d.ts.map +0 -1
  127. package/script/src/index.js +0 -167
  128. package/script/src/lib/auth.d.ts +0 -47
  129. package/script/src/lib/auth.d.ts.map +0 -1
  130. package/script/src/lib/auth.js +0 -269
  131. package/script/src/lib/config.d.ts +0 -6
  132. package/script/src/lib/config.d.ts.map +0 -1
  133. package/script/src/lib/config.js +0 -42
  134. package/script/src/lib/logger.d.ts +0 -3
  135. package/script/src/lib/logger.d.ts.map +0 -1
  136. package/script/src/lib/logger.js +0 -30
  137. package/script/src/lib/moodle.d.ts +0 -433
  138. package/script/src/lib/moodle.d.ts.map +0 -1
  139. package/script/src/lib/moodle.js +0 -1389
  140. package/script/src/lib/session.d.ts +0 -8
  141. package/script/src/lib/session.d.ts.map +0 -1
  142. package/script/src/lib/session.js +0 -45
  143. package/script/src/lib/token.d.ts +0 -38
  144. package/script/src/lib/token.d.ts.map +0 -1
  145. package/script/src/lib/token.js +0 -189
  146. package/script/src/lib/types.d.ts +0 -189
  147. package/script/src/lib/types.d.ts.map +0 -1
  148. package/script/src/lib/types.js +0 -3
  149. package/script/src/lib/utils.d.ts +0 -57
  150. package/script/src/lib/utils.d.ts.map +0 -1
  151. package/script/src/lib/utils.js +0 -175
  152. package/skills/openape/SKILL.md +0 -115
@@ -1,419 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.registerMaterialsCommand = registerMaterialsCommand;
7
- const utils_js_1 = require("../lib/utils.js");
8
- const moodle_js_1 = require("../lib/moodle.js");
9
- const auth_js_1 = require("../lib/auth.js");
10
- const index_js_1 = require("../index.js");
11
- const node_path_1 = __importDefault(require("node:path"));
12
- const node_fs_1 = __importDefault(require("node:fs"));
13
- function registerMaterialsCommand(program) {
14
- const materialsCmd = program.command("materials");
15
- materialsCmd.description("Material/resource operations");
16
- // Helper to download a single resource via HTTP (no browser needed)
17
- async function downloadResourceHttp(resource, outputDir, log, token) {
18
- try {
19
- // Only download resource type (skip url)
20
- if (resource.modType !== "resource") {
21
- log.debug(` Skipping ${resource.modType}: ${resource.name}`);
22
- return null;
23
- }
24
- const courseDir = node_path_1.default.join(outputDir, (0, utils_js_1.sanitizeFilename)(resource.course_name));
25
- await node_fs_1.default.promises.mkdir(courseDir, { recursive: true });
26
- // Build filename
27
- let filename = (0, utils_js_1.sanitizeFilename)(resource.name);
28
- if (resource.mimetype && !node_path_1.default.extname(filename)) {
29
- const extMap = {
30
- "application/pdf": ".pdf",
31
- "application/vnd.ms-powerpoint": ".ppt",
32
- "application/vnd.openxmlformats-officedocument.presentationml.presentation": ".pptx",
33
- "application/msword": ".doc",
34
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document": ".docx",
35
- "application/vnd.ms-excel": ".xls",
36
- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": ".xlsx",
37
- "application/zip": ".zip",
38
- "image/jpeg": ".jpg",
39
- "image/png": ".png",
40
- };
41
- if (extMap[resource.mimetype]) {
42
- filename += extMap[resource.mimetype];
43
- }
44
- }
45
- const outputPath = node_path_1.default.join(courseDir, filename);
46
- // Skip if already exists
47
- if (node_fs_1.default.existsSync(outputPath)) {
48
- log.debug(` Skipping (exists): ${filename}`);
49
- const stats = await node_fs_1.default.promises.stat(outputPath);
50
- return { filename, path: outputPath, size: stats.size, course_id: resource.course_id, course_name: resource.course_name };
51
- }
52
- // Download via HTTP with WS token
53
- const separator = resource.url.includes("?") ? "&" : "?";
54
- const downloadUrl = `${resource.url}${separator}token=${token}`;
55
- log.debug(` Downloading: ${resource.name}`);
56
- const response = await fetch(downloadUrl);
57
- if (!response.ok) {
58
- log.warn(` Failed to download ${resource.name}: HTTP ${response.status}`);
59
- return null;
60
- }
61
- const arrayBuffer = await response.arrayBuffer();
62
- const data = new Uint8Array(arrayBuffer);
63
- await node_fs_1.default.promises.writeFile(outputPath, data);
64
- log.success(` Downloaded: ${filename} (${(0, utils_js_1.formatFileSize)(data.byteLength, 1)} KB)`);
65
- return { filename, path: outputPath, size: data.byteLength, course_id: resource.course_id, course_name: resource.course_name };
66
- }
67
- catch (err) {
68
- log.warn(` Failed to download ${resource.name}: ${err instanceof Error ? err.message : String(err)}`);
69
- return null;
70
- }
71
- }
72
- // Helper to build material list from API resources
73
- function buildMaterialsList(courses, apiResources) {
74
- const courseMap = new Map(courses.map(c => [c.id, c]));
75
- const materials = [];
76
- for (const resource of apiResources) {
77
- const course = courseMap.get(resource.courseId);
78
- if (course) {
79
- materials.push({
80
- course_id: resource.courseId,
81
- course_name: course.fullname,
82
- cmid: resource.cmid,
83
- name: resource.name,
84
- url: resource.url,
85
- modType: resource.modType,
86
- mimetype: resource.mimetype,
87
- filesize: resource.filesize,
88
- modified: resource.modified,
89
- });
90
- }
91
- }
92
- return materials;
93
- }
94
- materialsCmd
95
- .command("list-all")
96
- .description("List all materials/resources across all courses")
97
- .option("--level <type>", "Course level: in_progress (default) | all", "in_progress")
98
- .option("--output <format>", "Output format: json|csv|table|silent")
99
- .action(async (options, command) => {
100
- const apiContext = await (0, auth_js_1.createApiContext)(options, command);
101
- if (!apiContext) {
102
- process.exitCode = 1;
103
- return;
104
- }
105
- const classification = options.level === "all" ? undefined : "inprogress";
106
- const courses = await (0, moodle_js_1.getEnrolledCoursesApi)(apiContext.session, {
107
- classification,
108
- });
109
- // Get materials via WS API (no browser needed!)
110
- const courseIds = courses.map(c => c.id);
111
- const apiResources = await (0, moodle_js_1.getResourcesByCoursesApi)(apiContext.session, courseIds);
112
- // Build a map of courseId -> course for quick lookup
113
- const courseMap = new Map(courses.map(c => [c.id, c]));
114
- const allMaterials = [];
115
- for (const resource of apiResources) {
116
- const course = courseMap.get(resource.courseId);
117
- if (course) {
118
- allMaterials.push({
119
- course_id: resource.courseId,
120
- course_name: course.fullname,
121
- cmid: resource.cmid,
122
- name: resource.name,
123
- url: resource.url,
124
- modType: resource.modType,
125
- mimetype: resource.mimetype,
126
- filesize: resource.filesize,
127
- modified: resource.modified,
128
- });
129
- }
130
- }
131
- const output = {
132
- status: "success",
133
- timestamp: new Date().toISOString(),
134
- level: options.level,
135
- materials: allMaterials.map(m => ({
136
- course_id: m.course_id,
137
- course_name: m.course_name,
138
- id: m.cmid,
139
- name: m.name,
140
- type: m.modType,
141
- mimetype: m.mimetype,
142
- filesize: m.filesize,
143
- modified: m.modified ? new Date(m.modified * 1000).toISOString() : null,
144
- url: m.url,
145
- })),
146
- summary: {
147
- total_courses: courses.length,
148
- total_materials: allMaterials.length,
149
- by_type: allMaterials.reduce((acc, m) => {
150
- acc[m.modType] = (acc[m.modType] || 0) + 1;
151
- return acc;
152
- }, {}),
153
- },
154
- };
155
- console.log(JSON.stringify(output));
156
- });
157
- materialsCmd
158
- .command("download")
159
- .description("Download all materials from a specific course")
160
- .argument("<course-id>", "Course ID")
161
- .option("--output-dir <path>", "Output directory", "./downloads")
162
- .action(async (courseId, options, command) => {
163
- const apiContext = await (0, auth_js_1.createApiContext)(options, command);
164
- if (!apiContext) {
165
- process.exitCode = 1;
166
- return;
167
- }
168
- const { log, session } = apiContext;
169
- const courses = await (0, moodle_js_1.getEnrolledCoursesApi)(session);
170
- const course = courses.find((c) => c.id === parseInt(courseId, 10));
171
- if (!course) {
172
- log.error(`Course not found: ${courseId}`);
173
- process.exitCode = 1;
174
- return;
175
- }
176
- const apiResources = await (0, moodle_js_1.getResourcesByCoursesApi)(session, [course.id]);
177
- const materials = buildMaterialsList(courses, apiResources);
178
- log.info(`Found ${materials.length} materials in course: ${course.fullname}`);
179
- const downloadedFiles = [];
180
- for (const material of materials) {
181
- const result = await downloadResourceHttp(material, options.outputDir, log, session.wsToken);
182
- if (result) {
183
- downloadedFiles.push(result);
184
- }
185
- }
186
- const output = {
187
- status: "success",
188
- timestamp: new Date().toISOString(),
189
- downloaded_files: downloadedFiles.map(f => ({
190
- filename: f.filename,
191
- path: f.path,
192
- size: f.size,
193
- course_id: f.course_id,
194
- course_name: f.course_name,
195
- })),
196
- summary: {
197
- total_materials: materials.length,
198
- downloaded: downloadedFiles.length,
199
- skipped: materials.length - downloadedFiles.length,
200
- total_size: downloadedFiles.reduce((sum, f) => sum + f.size, 0),
201
- },
202
- };
203
- console.log(JSON.stringify(output));
204
- });
205
- materialsCmd
206
- .command("download-all")
207
- .description("Download all materials from all courses")
208
- .option("--output-dir <path>", "Output directory", "./downloads")
209
- .option("--level <type>", "Course level: in_progress (default) | all", "in_progress")
210
- .action(async (options, command) => {
211
- const apiContext = await (0, auth_js_1.createApiContext)(options, command);
212
- if (!apiContext) {
213
- process.exitCode = 1;
214
- return;
215
- }
216
- const { log, session } = apiContext;
217
- const classification = options.level === "all" ? undefined : "inprogress";
218
- const courses = await (0, moodle_js_1.getEnrolledCoursesApi)(session, { classification });
219
- log.info(`Scanning ${courses.length} courses for materials...`);
220
- const courseIds = courses.map((c) => c.id);
221
- const apiResources = await (0, moodle_js_1.getResourcesByCoursesApi)(session, courseIds);
222
- const allMaterials = buildMaterialsList(courses, apiResources);
223
- log.info(`Found ${allMaterials.length} materials across ${courses.length} courses`);
224
- const downloadedFiles = [];
225
- for (const material of allMaterials) {
226
- const result = await downloadResourceHttp(material, options.outputDir, log, session.wsToken);
227
- if (result) {
228
- downloadedFiles.push(result);
229
- }
230
- }
231
- const output = {
232
- status: "success",
233
- timestamp: new Date().toISOString(),
234
- downloaded_files: downloadedFiles.map(f => ({
235
- filename: f.filename,
236
- path: f.path,
237
- size: f.size,
238
- course_id: f.course_id,
239
- course_name: f.course_name,
240
- })),
241
- summary: {
242
- total_courses: courses.length,
243
- total_materials: allMaterials.length,
244
- downloaded: downloadedFiles.length,
245
- skipped: allMaterials.length - downloadedFiles.length,
246
- total_size: downloadedFiles.reduce((sum, f) => sum + f.size, 0),
247
- },
248
- };
249
- console.log(JSON.stringify(output));
250
- });
251
- materialsCmd
252
- .command("complete")
253
- .description("Mark all incomplete resources (non-video) as complete in a course")
254
- .argument("<course-id>", "Course ID")
255
- .option("--dry-run", "Show what would be marked complete without doing it")
256
- .option("--output <format>", "Output format: json|csv|table|silent")
257
- .action(async (courseId, options, command) => {
258
- const output = (0, utils_js_1.getOutputFormat)(command);
259
- const apiContext = await (0, auth_js_1.createApiContext)(options, command);
260
- if (!apiContext) {
261
- process.exitCode = 1;
262
- return;
263
- }
264
- try {
265
- const { log, session } = apiContext;
266
- // Get user ID
267
- const siteInfo = await (0, moodle_js_1.getSiteInfoApi)(session);
268
- // Get completion status for all activities in the course
269
- const completionData = await (0, moodle_js_1.moodleApiCall)(session, "core_completion_get_activities_completion_status", { courseid: parseInt(courseId, 10), userid: siteInfo.userid });
270
- if (!completionData?.statuses) {
271
- log.info("No activities found in this course.");
272
- return;
273
- }
274
- // Filter for resources (non-video) that have completion enabled but are not complete
275
- const incompleteResources = completionData.statuses.filter((status) => {
276
- // Only resources, not supervideo
277
- if (status.modname === "supervideo")
278
- return false;
279
- // Must have completion enabled
280
- if (!status.hascompletion)
281
- return false;
282
- // Must be incomplete
283
- if (status.isoverallcomplete)
284
- return false;
285
- return true;
286
- });
287
- if (incompleteResources.length === 0) {
288
- log.info("All resources are already complete (or no resources with completion tracking).");
289
- return;
290
- }
291
- log.info(`Found ${incompleteResources.length} incomplete resources to complete:`);
292
- for (const resource of incompleteResources) {
293
- log.info(` - ${resource.name} (cmid: ${resource.cmid})`);
294
- }
295
- if (options.dryRun) {
296
- log.info("\n[Dry run] No changes made.");
297
- return;
298
- }
299
- // Mark each resource as complete
300
- const results = [];
301
- for (const resource of incompleteResources) {
302
- const success = await (0, moodle_js_1.updateActivityCompletionStatusManually)(session, resource.cmid, true);
303
- results.push({
304
- cmid: resource.cmid,
305
- name: resource.name,
306
- success,
307
- });
308
- if (success) {
309
- log.success(` ✓ Completed: ${resource.name}`);
310
- }
311
- else {
312
- log.error(` ✗ Failed: ${resource.name}`);
313
- }
314
- }
315
- const completed = results.filter(r => r.success).length;
316
- const failed = results.filter(r => !r.success).length;
317
- log.info(`\n執行結果: ${completed} 成功, ${failed} 失敗`);
318
- if (output !== "silent") {
319
- (0, index_js_1.formatAndOutput)(results, output, log);
320
- }
321
- }
322
- catch (e) {
323
- apiContext.log.error(`Error: ${e instanceof Error ? e.message : String(e)}`);
324
- process.exitCode = 1;
325
- }
326
- });
327
- materialsCmd
328
- .command("complete-all")
329
- .description("Mark all incomplete resources (non-video) as complete across all in-progress courses")
330
- .option("--dry-run", "Show what would be marked complete without doing it")
331
- .option("--level <type>", "Course level: in_progress (default) | all", "in_progress")
332
- .option("--output <format>", "Output format: json|csv|table|silent")
333
- .action(async (options, command) => {
334
- const output = (0, utils_js_1.getOutputFormat)(command);
335
- const apiContext = await (0, auth_js_1.createApiContext)(options, command);
336
- if (!apiContext) {
337
- process.exitCode = 1;
338
- return;
339
- }
340
- try {
341
- const { log, session } = apiContext;
342
- // Get user ID
343
- const siteInfo = await (0, moodle_js_1.getSiteInfoApi)(session);
344
- // Get all courses
345
- const classification = options.level === "all" ? undefined : "inprogress";
346
- const courses = await (0, moodle_js_1.getEnrolledCoursesApi)(session, { classification });
347
- log.info(`Scanning ${courses.length} courses for incomplete resources...`);
348
- const allResults = [];
349
- let totalIncomplete = 0;
350
- for (const course of courses) {
351
- try {
352
- // Get completion status for all activities in the course
353
- const completionData = await (0, moodle_js_1.moodleApiCall)(session, "core_completion_get_activities_completion_status", { courseid: course.id, userid: siteInfo.userid });
354
- if (!completionData?.statuses)
355
- continue;
356
- // Filter for resources (non-video) that have completion enabled but are not complete
357
- const incompleteResources = completionData.statuses.filter((status) => {
358
- if (status.modname === "supervideo")
359
- return false;
360
- if (!status.hascompletion)
361
- return false;
362
- if (status.isoverallcomplete)
363
- return false;
364
- return true;
365
- });
366
- if (incompleteResources.length > 0) {
367
- log.info(`\n${course.fullname}: ${incompleteResources.length} incomplete resources`);
368
- totalIncomplete += incompleteResources.length;
369
- if (options.dryRun) {
370
- for (const resource of incompleteResources) {
371
- log.info(` - ${resource.name} (cmid: ${resource.cmid})`);
372
- }
373
- }
374
- else {
375
- for (const resource of incompleteResources) {
376
- const success = await (0, moodle_js_1.updateActivityCompletionStatusManually)(session, resource.cmid, true);
377
- allResults.push({
378
- courseId: course.id,
379
- courseName: course.fullname,
380
- cmid: resource.cmid,
381
- name: resource.name,
382
- success,
383
- });
384
- if (success) {
385
- log.success(` ✓ Completed: ${resource.name}`);
386
- }
387
- else {
388
- log.error(` ✗ Failed: ${resource.name}`);
389
- }
390
- }
391
- }
392
- }
393
- }
394
- catch (e) {
395
- log.warn(`Failed to process course ${course.fullname}: ${e}`);
396
- }
397
- }
398
- if (totalIncomplete === 0) {
399
- log.info("\nAll resources are already complete (or no resources with completion tracking).");
400
- return;
401
- }
402
- if (options.dryRun) {
403
- log.info(`\n[Dry run] Found ${totalIncomplete} incomplete resources across ${courses.length} courses.`);
404
- log.info("Run without --dry-run to mark them as complete.");
405
- return;
406
- }
407
- const completed = allResults.filter(r => r.success).length;
408
- const failed = allResults.filter(r => !r.success).length;
409
- log.info(`\n執行結果: ${completed} 成功, ${failed} 失敗`);
410
- if (output !== "silent") {
411
- (0, index_js_1.formatAndOutput)(allResults, output, log);
412
- }
413
- }
414
- catch (e) {
415
- apiContext.log.error(`Error: ${e instanceof Error ? e.message : String(e)}`);
416
- process.exitCode = 1;
417
- }
418
- });
419
- }
@@ -1,3 +0,0 @@
1
- import { Command } from "commander";
2
- export declare function registerQuizzesCommand(program: Command): void;
3
- //# sourceMappingURL=quizzes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"quizzes.d.ts","sourceRoot":"","sources":["../../../src/src/commands/quizzes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAyEpC,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAoQ7D"}