@@ -2,6 +2,7 @@ import { Readable } from 'stream';
22import { delay , inject , singleton } from 'tsyringe' ;
33
44import {
5+ H5PItemExtra ,
56 ItemType ,
67 ItemVisibilityType ,
78 MAX_DESCENDANTS_FOR_COPY ,
@@ -31,6 +32,7 @@ import type {
3132} from '../../drizzle/types' ;
3233import { BaseLogger } from '../../logger' ;
3334import type { AuthenticatedUser , MaybeUser , MinimalMember } from '../../types' ;
35+ import { H5P_INTEGRATION_URL } from '../../utils/config' ;
3436import {
3537 CannotReorderRootItem ,
3638 InvalidMembership ,
@@ -464,7 +466,13 @@ export class ItemService {
464466 ) ;
465467 const thumbnails = await this . itemThumbnailService . getUrlsByItems ( [ item ] ) ;
466468
467- return new ItemWrapper ( item , itemMembership , visibilities , thumbnails [ item . id ] ) . packed ( ) ;
469+ const packedItem = new ItemWrapper (
470+ item ,
471+ itemMembership ,
472+ visibilities ,
473+ thumbnails [ item . id ] ,
474+ ) . packed ( ) ;
475+ return this . transformItemByType ( packedItem ) ;
468476 }
469477
470478 async getAccessible (
@@ -527,7 +535,7 @@ export class ItemService {
527535 const thumbnails = await this . itemThumbnailService . getUrlsByItems ( children ) ;
528536
529537 // TODO optimize?
530- return filterOutPackedItems (
538+ const filteredChildren = await filterOutPackedItems (
531539 dbConnection ,
532540 actor ,
533541 {
@@ -537,6 +545,7 @@ export class ItemService {
537545 children ,
538546 thumbnails ,
539547 ) ;
548+ return filteredChildren . map ( ( children ) => this . transformItemByType ( children ) ) ;
540549 }
541550
542551 async getDescendants (
@@ -1045,4 +1054,24 @@ export class ItemService {
10451054 await this . itemRepository . rescaleOrder ( dbConnection , parentItem ) ;
10461055 }
10471056 }
1057+
1058+ private transformItemByType ( item : PackedItem ) {
1059+ switch ( item . type ) {
1060+ case ItemType . H5P : {
1061+ const { h5p : h5pExtraProperties } = item . extra as H5PItemExtra ;
1062+ const integrationUrl = new URL ( H5P_INTEGRATION_URL ) ;
1063+ // add the contentId param to the integration
1064+ integrationUrl . searchParams . set ( 'contentId' , h5pExtraProperties . contentId ) ;
1065+ const newExtra = {
1066+ h5p : {
1067+ ...h5pExtraProperties ,
1068+ integrationUrl : integrationUrl . toString ( ) ,
1069+ } ,
1070+ } ;
1071+ return { ...item , extra : newExtra } ;
1072+ }
1073+ default :
1074+ return item ;
1075+ }
1076+ }
10481077}
0 commit comments