From 8045a528dfd709bd0669ec3f560d20bb6c6a6a5f Mon Sep 17 00:00:00 2001 From: Caspar Neumann Date: Thu, 16 Nov 2023 09:49:41 +0100 Subject: [PATCH] review comment: solve use of config.get --- .../h5p-library-management.config.ts | 3 +++ .../service/h5p-library-management.service.ts | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 apps/server/src/modules/h5p-library-management/h5p-library-management.config.ts diff --git a/apps/server/src/modules/h5p-library-management/h5p-library-management.config.ts b/apps/server/src/modules/h5p-library-management/h5p-library-management.config.ts new file mode 100644 index 00000000000..78130f9c3f8 --- /dev/null +++ b/apps/server/src/modules/h5p-library-management/h5p-library-management.config.ts @@ -0,0 +1,3 @@ +export interface H5pLibraryManagementConfig { + libraryListPath: string; +} diff --git a/apps/server/src/modules/h5p-library-management/service/h5p-library-management.service.ts b/apps/server/src/modules/h5p-library-management/service/h5p-library-management.service.ts index e0ae71c8903..6f06dce57a5 100644 --- a/apps/server/src/modules/h5p-library-management/service/h5p-library-management.service.ts +++ b/apps/server/src/modules/h5p-library-management/service/h5p-library-management.service.ts @@ -11,9 +11,10 @@ import ContentManager from '@lumieducation/h5p-server/build/src/ContentManager'; import ContentTypeInformationRepository from '@lumieducation/h5p-server/build/src/ContentTypeInformationRepository'; import { Injectable } from '@nestjs/common'; import { ContentStorage, LibraryStorage } from '@src/modules/h5p-editor'; -import { Configuration } from '@hpi-schul-cloud/commons'; import { readFileSync } from 'fs'; import { parse } from 'yaml'; +import { ConfigService } from '@nestjs/config'; +import { H5pLibraryManagementConfig } from '../h5p-library-management.config'; const h5pConfig = new H5PConfig(undefined, { baseUrl: '/api/v3/h5p-editor', @@ -33,7 +34,13 @@ export class H5PLibraryManagementService { libraryWishList: string[]; - constructor(private readonly libraryStorage: LibraryStorage, private readonly contentStorage: ContentStorage) { + libraryListPath: string; + + constructor( + private readonly libraryStorage: LibraryStorage, + private readonly contentStorage: ContentStorage, + private configService: ConfigService + ) { const kvCache = new cacheImplementations.CachedKeyValueStorage('kvcache'); this.contentTypeCache = new ContentTypeCache(h5pConfig, kvCache); this.libraryManager = new LibraryManager( @@ -48,7 +55,12 @@ export class H5PLibraryManagementService { this.contentTypeRepo = new ContentTypeInformationRepository(this.contentTypeCache, this.libraryManager, h5pConfig); const contentManager = new ContentManager(this.contentStorage); this.libraryAdministration = new LibraryAdministration(this.libraryManager, contentManager); - const librariesYamlContent = readFileSync(Configuration.get('H5P_EDITOR__LIBRARY_LIST_PATH') as string, { + const config = this.configService.get( + 'H5P_EDITOR__LIBRARY_LIST_PATH' + ) as H5pLibraryManagementConfig; + this.libraryListPath = config.libraryListPath; + + const librariesYamlContent = readFileSync(this.libraryListPath, { encoding: 'utf-8', }); this.libraryWishList = (parse(librariesYamlContent) as { h5p_libraries: string[] }).h5p_libraries;