Skip to content

Commit

Permalink
fix(h5p-server): library list works if library dependencies are missi…
Browse files Browse the repository at this point in the history
…ng (#1342)

Fixes #1183
  • Loading branch information
sr258 committed Apr 25, 2021
1 parent e5ac643 commit 6dab877
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"test:db": "npx jest --config jest.db.config.js --maxWorkers=${BUILD_WORKERS-`nproc`} --logHeapUsage",
"test:html-exporter": "jest --config packages/h5p-html-exporter/jest.config.js --logHeapUsage --maxWorkers=${BUILD_WORKERS-`nproc`}",
"test:integration": "npx jest --config jest.integration.config.js --maxWorkers=${BUILD_WORKERS-`nproc`} --logHeapUsage",
"test:server+upload": "npm run test:server+upload --repfix packages/h5p-server",
"test:server+upload": "npm run test:server+upload --prefix packages/h5p-server",
"test:upload": "npm run test:upload --prefix packages/h5p-server",
"test:watch": "npm run test:watch --prefix packages/h5p-server",
"test:watch:h5p-express": "npm run test:watch --prefix packages/h5p-express",
Expand Down
8 changes: 8 additions & 0 deletions packages/h5p-server/src/LibraryAdministration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {
ILibraryAdministrationOverviewItem,
IInstalledLibrary
} from './types';
import Logger from './helpers/Logger';

const log = new Logger('LibraryAdministration');

/**
* This class has methods that perform library administration, i.e, deleted
Expand Down Expand Up @@ -48,17 +51,22 @@ export default class LibraryAdministration {
* usage of libraries across all content objects on the system.
*/
public async getLibraries(): Promise<ILibraryAdministrationOverviewItem[]> {
log.debug('Getting all libraries');
const libraryNames = await this.libraryManager.libraryStorage.getInstalledLibraryNames();
const libraryMetadata = (
await Promise.all(
libraryNames.map((lib) => this.libraryManager.getLibrary(lib))
)
).sort((a, b) => a.compare(b));

log.debug('Getting all dependents count');
const dependents = await this.libraryManager.libraryStorage.getAllDependentsCount();

return Promise.all(
libraryMetadata.map(async (metadata) => {
log.debug(
`Getting usage data of ${LibraryName.toUberName(metadata)}`
);
const usage = await this.contentManager.contentStorage.getUsage(
metadata
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export default class FileLibraryStorage implements ILibraryStorage {
const ubername = LibraryName.toUberName(dependency);
const index = librariesMetadataMap[
ubername
].preloadedDependencies?.findIndex((ln) =>
]?.preloadedDependencies?.findIndex((ln) =>
LibraryName.equal(ln, libraryMetadata)
);
if (index >= 0) {
Expand Down

0 comments on commit 6dab877

Please sign in to comment.