-
-
Notifications
You must be signed in to change notification settings - Fork 304
Extract metadata for ims scorm cp #4258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: unstable
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,7 +62,7 @@ async function getFolderMetadata(data, xmlDoc, zip, procssedFiles) { | |
| }; | ||
| if (orgNode.nodeType === 1) { | ||
| const title = orgNode.getElementsByTagName('title'); | ||
| org.title = title[0].textContent.replace(/ {2}|\r\n|\n|\r/gm, ''); | ||
| org.title = title[0].textContent.trim(); | ||
| const files = orgNode.getElementsByTagName('item'); | ||
| const immediateChildNodes = []; | ||
| const childNodes = Object.values(orgNode.children); | ||
|
|
@@ -74,7 +74,7 @@ async function getFolderMetadata(data, xmlDoc, zip, procssedFiles) { | |
| await Promise.all( | ||
| immediateChildNodes.map(async (fileNode, k) => { | ||
| const file = {}; | ||
| file.title = title[1 + k].textContent.replace(/ {2}|\r\n|\n|\r/gm, ''); | ||
| file.title = title[1 + k].textContent.trim(); | ||
| file.identifierref = fileNode.getAttribute('identifierref'); | ||
| file.resourceHref = xmlDoc | ||
| .querySelectorAll(`[identifier=${file.identifierref}]`)[0] | ||
|
|
@@ -149,41 +149,37 @@ async function getManifestMetadata(manifestFile, zip, procssedFiles) { | |
| if (xmlDoc.getElementsByTagName('lomes:title').length) { | ||
| metadata.title = xmlDoc | ||
| .getElementsByTagName('lomes:title')[0] | ||
| .children[0].textContent.replace(/ {2}|\r\n|\n|\r/gm, ''); | ||
| .children[0].textContent.trim(); | ||
| } | ||
| if ( | ||
| xmlDoc.getElementsByTagName('lomes:idiom').length && | ||
| xmlDoc | ||
| .getElementsByTagName('lomes:idiom')[0] | ||
| .textContent.replace(/ {2}|\r\n|\n|\r/gm, '') !== 'und' | ||
| LanguagesMap.has(xmlDoc.getElementsByTagName('lomes:idiom')[0].textContent.trim()) && | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could avoid a bit of repetition here and define outside of the if statement: (defaulting to the disallowed then you can do the checks and assignment against this value instead. |
||
| xmlDoc.getElementsByTagName('lomes:idiom')[0].textContent.trim() !== 'und' | ||
| ) { | ||
| metadata.language = xmlDoc | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For language extraction let's replicate the validation we are doing in H5P to check this is a supported language code.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can also add some more tests for unhappy paths! |
||
| .getElementsByTagName('lomes:idiom')[0] | ||
| .children[0].textContent.replace(/ {2}|\r\n|\n|\r/gm, ''); | ||
| .children[0].textContent.trim(); | ||
| } | ||
| if (xmlDoc.getElementsByTagName('lomes:description').length) { | ||
| metadata.description = xmlDoc | ||
| .getElementsByTagName('lomes:description')[0] | ||
| .children[0].textContent.replace(/ {2}|\r\n|\n|\r/gm, ''); | ||
| .children[0].textContent.trim(); | ||
| } | ||
| } else { | ||
| if (xmlDoc.getElementsByTagName('imsmd:title').length) { | ||
| metadata.title = xmlDoc | ||
| .getElementsByTagName('imsmd:title')[0] | ||
| .textContent.replace(/ {2}|\r\n|\n|\r/gm, ''); | ||
| metadata.title = xmlDoc.getElementsByTagName('imsmd:title')[0].textContent.trim(); | ||
| } | ||
| if ( | ||
| xmlDoc.getElementsByTagName('imsmd:language').length && | ||
| xmlDoc.getElementsByTagName('imsmd:language')[0].textContent !== 'und' | ||
| LanguagesMap.has(xmlDoc.getElementsByTagName('imsmd:language')[0].textContent.trim()) && | ||
| xmlDoc.getElementsByTagName('imsmd:language')[0].textContent.trim() !== 'und' | ||
| ) { | ||
| metadata.language = xmlDoc | ||
| .getElementsByTagName('imsmd:language')[0] | ||
| .textContent.replace(/ {2}|\r\n|\n|\r/gm, ''); | ||
| metadata.language = xmlDoc.getElementsByTagName('imsmd:language')[0].textContent.trim(); | ||
| } | ||
| if (xmlDoc.getElementsByTagName('imsmd:description').length) { | ||
| metadata.description = xmlDoc | ||
| .getElementsByTagName('imsmd:description')[0] | ||
| .textContent.replace(/ {2}|\r\n|\n|\r/gm, ''); | ||
| .textContent.trim(); | ||
| } | ||
| } | ||
| return metadata; | ||
|
|
@@ -204,9 +200,7 @@ export async function extractIMSMetadata(fileInput) { | |
| } | ||
| }) | ||
| .then(async manifestFile => { | ||
| return await getManifestMetadata(manifestFile, zip, procssedFiles).then(metadata => { | ||
| return metadata; | ||
| }); | ||
| return await getManifestMetadata(manifestFile, zip, procssedFiles); | ||
| }); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's change this to set
this.selectedif we haven't already setthis.selectedto something - so only the first finalized node gets selected.