Merge pull request #2992 from dpalou/MOBILE-3918
MOBILE-3918 h5p: Fix undefined title for some packagesmain
commit
3d784427cf
|
@ -483,6 +483,10 @@ export class CoreH5PFramework {
|
||||||
if (!params.metadata) {
|
if (!params.metadata) {
|
||||||
params.metadata = {};
|
params.metadata = {};
|
||||||
}
|
}
|
||||||
|
// Add title to metadata.
|
||||||
|
if (typeof params.title === 'string' && !params.metadata.title) {
|
||||||
|
params.metadata.title = params.title;
|
||||||
|
}
|
||||||
content.metadata = params.metadata;
|
content.metadata = params.metadata;
|
||||||
content.params = JSON.stringify(typeof params.params != 'undefined' && params.params != null ? params.params : params);
|
content.params = JSON.stringify(typeof params.params != 'undefined' && params.params != null ? params.params : params);
|
||||||
|
|
||||||
|
@ -834,6 +838,14 @@ export class CoreH5PFramework {
|
||||||
content.library.libraryId = mainLibrary.id;
|
content.library.libraryId = mainLibrary.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add title to 'params' to be able to add it to metadata later.
|
||||||
|
if (typeof content.title === 'string') {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
const params = CoreTextUtils.parseJSON<any>(content.params || '{}');
|
||||||
|
params.title = content.title;
|
||||||
|
content.params = JSON.stringify(params);
|
||||||
|
}
|
||||||
|
|
||||||
const data: Partial<CoreH5PContentDBRecord> = {
|
const data: Partial<CoreH5PContentDBRecord> = {
|
||||||
id: undefined,
|
id: undefined,
|
||||||
jsoncontent: content.params,
|
jsoncontent: content.params,
|
||||||
|
@ -844,23 +856,26 @@ export class CoreH5PFramework {
|
||||||
fileurl: fileUrl,
|
fileurl: fileUrl,
|
||||||
timecreated: undefined,
|
timecreated: undefined,
|
||||||
};
|
};
|
||||||
|
let contentId: number | undefined;
|
||||||
|
|
||||||
if (typeof content.id != 'undefined') {
|
if (typeof content.id != 'undefined') {
|
||||||
data.id = content.id;
|
data.id = content.id;
|
||||||
|
contentId = content.id;
|
||||||
} else {
|
} else {
|
||||||
data.timecreated = data.timemodified;
|
data.timecreated = data.timemodified;
|
||||||
}
|
}
|
||||||
|
|
||||||
await db.insertRecord(CONTENT_TABLE_NAME, data);
|
await db.insertRecord(CONTENT_TABLE_NAME, data);
|
||||||
|
|
||||||
if (!data.id) {
|
if (!contentId) {
|
||||||
// New content. Get its ID.
|
// New content. Get its ID.
|
||||||
const entry = await db.getRecord<CoreH5PContentDBRecord>(CONTENT_TABLE_NAME, data);
|
const entry = await db.getRecord<CoreH5PContentDBRecord>(CONTENT_TABLE_NAME, data);
|
||||||
|
|
||||||
content.id = entry.id;
|
content.id = entry.id;
|
||||||
|
contentId = content.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
return content.id!;
|
return contentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -173,6 +173,11 @@ export class CoreH5PStorage {
|
||||||
|
|
||||||
const content: CoreH5PContentBeingSaved = {};
|
const content: CoreH5PContentBeingSaved = {};
|
||||||
|
|
||||||
|
// Add the 'title' if exists from 'h5p.json' data to be able to add it to metadata later.
|
||||||
|
if (typeof data.mainJsonData.title === 'string') {
|
||||||
|
content.title = data.mainJsonData.title;
|
||||||
|
}
|
||||||
|
|
||||||
if (!skipContent) {
|
if (!skipContent) {
|
||||||
// Find main library version.
|
// Find main library version.
|
||||||
if (data.mainJsonData.preloadedDependencies) {
|
if (data.mainJsonData.preloadedDependencies) {
|
||||||
|
@ -226,6 +231,7 @@ export type CoreH5PContentBeingSaved = {
|
||||||
id?: number;
|
id?: number;
|
||||||
params?: string;
|
params?: string;
|
||||||
library?: CoreH5PContentLibrary;
|
library?: CoreH5PContentLibrary;
|
||||||
|
title?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type CoreH5PContentLibrary = CoreH5PLibraryBasicData & {
|
export type CoreH5PContentLibrary = CoreH5PLibraryBasicData & {
|
||||||
|
|
Loading…
Reference in New Issue