Skip to content

Commit c0173e7

Browse files
authored
fix: add H5P integration url to packed item wrapper (#2027)
* fix: add integration url to packed item wrapper * fix: update with comments
1 parent 0ce5204 commit c0173e7

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

src/services/item/item.service.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Readable } from 'stream';
22
import { delay, inject, singleton } from 'tsyringe';
33

44
import {
5+
H5PItemExtra,
56
ItemType,
67
ItemVisibilityType,
78
MAX_DESCENDANTS_FOR_COPY,
@@ -31,6 +32,7 @@ import type {
3132
} from '../../drizzle/types';
3233
import { BaseLogger } from '../../logger';
3334
import type { AuthenticatedUser, MaybeUser, MinimalMember } from '../../types';
35+
import { H5P_INTEGRATION_URL } from '../../utils/config';
3436
import {
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
}

src/utils/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export const CLIENT_HOST = process.env.CLIENT_HOST ?? 'http://localhost:3114';
2121

2222
export const LIBRARY_HOST = process.env.LIBRARY_CLIENT_HOST ?? CLIENT_HOST;
2323

24+
// Fallback to the server-provided integration is only available in dev
25+
export const H5P_INTEGRATION_URL =
26+
process.env.H5P_INTEGRATION_URL ?? 'http://localhost:3000/h5p-integration';
27+
2428
export const ALLOWED_ORIGINS = [new URL(CLIENT_HOST).origin, new URL(LIBRARY_HOST).origin];
2529

2630
// Add the hosts of the different clients

0 commit comments

Comments
 (0)