@@ -426,6 +426,76 @@ export default class projectManager {
426426 */
427427 async checkAndImportElp ( ) {
428428 const urlParams = new URLSearchParams ( window . location . search ) ;
429+
430+ // =====================================================
431+ // PLATFORM INTEGRATION: Fetch ELP from LMS if requested
432+ // =====================================================
433+ const fetchPlatformElp = urlParams . get ( 'fetchPlatformElp' ) === '1' ;
434+ const jwtToken = urlParams . get ( 'jwt_token' ) ;
435+
436+ if ( jwtToken && fetchPlatformElp ) {
437+ Logger . log ( '[ProjectManager] Detected platform integration new project, fetching ELP from platform...' ) ;
438+ try {
439+ if ( this . app ?. modals ?. loader ) {
440+ this . app . modals . loader . show ( { message : window . _ ? window . _ ( 'Downloading from platform...' ) : 'Downloading from platform...' } ) ;
441+ }
442+
443+ const basePath = window . eXeLearning ?. config ?. basePath || '' ;
444+ const response = await fetch ( `${ basePath } /api/platform/integration/openPlatformElp` , {
445+ method : 'POST' ,
446+ headers : { 'Content-Type' : 'application/json' } ,
447+ body : JSON . stringify ( { jwt_token : jwtToken } )
448+ } ) ;
449+
450+ if ( response . ok ) {
451+ const data = await response . json ( ) ;
452+
453+ if ( data . responseMessage === 'OK' && data . elpFile ) {
454+ Logger . log ( '[ProjectManager] ELP file fetched from platform, base64 size:' , data . elpFile . length ) ;
455+
456+ // Convert base64 to Blob/File
457+ const binaryString = atob ( data . elpFile ) ;
458+ const len = binaryString . length ;
459+ const bytes = new Uint8Array ( len ) ;
460+ for ( let i = 0 ; i < len ; i ++ ) {
461+ bytes [ i ] = binaryString . charCodeAt ( i ) ;
462+ }
463+ const fileName = data . elpFileName || 'platform_import.elpx' ;
464+ const file = new File ( [ bytes ] , fileName , { type : 'application/octet-stream' } ) ;
465+
466+ const stats = await this . importFromElpxViaYjs ( file ) ;
467+ Logger . log ( '[ProjectManager] Platform ELP import complete:' , stats ) ;
468+
469+ try {
470+ await this . _yjsBridge . documentManager . saveToServer ( ) ;
471+ Logger . log ( '[ProjectManager] Document saved to server after platform import' ) ;
472+ } catch ( saveError ) {
473+ console . warn ( '[ProjectManager] Failed to save to server after platform import' , saveError ) ;
474+ }
475+
476+ } else {
477+ Logger . log ( '[ProjectManager] No ELP file returned by platform or error:' , data . error ) ;
478+ }
479+ } else {
480+ console . warn ( `[ProjectManager] Platform API responded with status ${ response . status } ` ) ;
481+ }
482+ } catch ( error ) {
483+ // Do not block the user, just log and continue
484+ console . error ( '[ProjectManager] Failed to fetch ELP from platform:' , error ) ;
485+ } finally {
486+ if ( this . app ?. modals ?. loader ) {
487+ this . app . modals . loader . hide ( ) ;
488+ }
489+
490+ // Cleanup fetchPlatformElp url parameter
491+ const newUrl = new URL ( window . location . href ) ;
492+ newUrl . searchParams . delete ( 'fetchPlatformElp' ) ;
493+ window . history . replaceState ( { } , '' , newUrl . toString ( ) ) ;
494+ }
495+
496+ return ; // We handled the platform import, skip subsequent checks
497+ }
498+
429499 const importPathFromUrl = urlParams . get ( 'import' ) ;
430500 const importPathFromEmbedding = this . app ?. runtimeConfig ?. embeddingConfig ?. initialProjectUrl || '' ;
431501 const importPath = importPathFromUrl || importPathFromEmbedding ;
0 commit comments