@@ -21,6 +21,21 @@ interface PackCourseResponse {
2121 errorText ?: string ;
2222}
2323
24+ /**
25+ * Extract original courseId from decorated studio database name
26+ * Handles formats like: unpacked_originalId_timestamp_random
27+ */
28+ function extractOriginalCourseId ( decoratedId : string ) : string {
29+ // Remove unpacked_ prefix if present
30+ let courseId = decoratedId . replace ( / ^ u n p a c k e d _ / , '' ) ;
31+
32+ // Remove timestamp_random suffix pattern: _YYYYMMDD_abcdef
33+ courseId = courseId . replace ( / _ \d { 8 } _ [ a - z 0 - 9 ] { 6 } $ / , '' ) ;
34+
35+ // If no changes were made, return original (handles non-decorated IDs)
36+ return courseId === decoratedId ? decoratedId : courseId ;
37+ }
38+
2439export async function packCourse ( data : PackCourseData ) : Promise < PackCourseResponse > {
2540 logger . info ( `Starting PACK_COURSE for ${ data . courseId } ...` ) ;
2641
@@ -150,7 +165,11 @@ export async function packCourse(data: PackCourseData): Promise<PackCourseRespon
150165 const courseDb = new PouchDB ( courseDbUrl ) ;
151166 // logger.info(`PouchDB instance created, adapter: ${(courseDb as any).adapter}`);
152167
153- const packResult = await packer . packCourseToFiles ( courseDb , data . courseId , outputPath , fsAdapter ) ;
168+ // Extract original courseId from decorated database name for manifest generation
169+ const originalCourseId = extractOriginalCourseId ( data . courseId ) ;
170+ logger . info ( `Using originalCourseId "${ originalCourseId } " for manifest (extracted from "${ data . courseId } ")` ) ;
171+
172+ const packResult = await packer . packCourseToFiles ( courseDb , originalCourseId , outputPath , fsAdapter ) ;
154173
155174 const duration = Date . now ( ) - startTime ;
156175
0 commit comments