-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(saving): exported packages now allows conform to the h5p.json sch…
…ema (resolves #294) (#323) * added test to find errors in metadata * fix(saving): exported packages now follow the h5p.json schema even if the metadata received from the client is incomplete (resolves #294) * fix(tests): added required property for mock of ContentMetadata
- Loading branch information
1 parent
1b62353
commit b2fd4e6
Showing
9 changed files
with
319 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { | ||
IContentAuthor, | ||
IContentChange, | ||
IContentMetadata, | ||
ILibraryName | ||
} from './types'; | ||
|
||
/** | ||
* Content metadata object with defaults for required values and | ||
* sanitization to make sure it the metadata conforms to the schema. | ||
*/ | ||
export class ContentMetadata implements IContentMetadata { | ||
/** | ||
* Creates an object conforming to the h5p.json schema. | ||
* @param furtherMetadata these objects will be merged into the newly created object | ||
*/ | ||
constructor(...furtherMetadata: any[]) { | ||
for (const metadata of furtherMetadata) { | ||
Object.assign(this, metadata); | ||
} | ||
|
||
// Remove empty arrays for authors and changes, as this validates the | ||
// H5P schema. | ||
if (this.authors && this.authors.length === 0) { | ||
this.authors = undefined; | ||
} | ||
if (this.changes && this.changes.length === 0) { | ||
this.changes = undefined; | ||
} | ||
} | ||
public author?: string; | ||
public authorComments?: string; | ||
public authors?: IContentAuthor[]; | ||
public changes?: IContentChange[]; | ||
public contentType?: string; | ||
public dynamicDependencies?: ILibraryName[]; | ||
public editorDependencies?: ILibraryName[]; | ||
public embedTypes: ('iframe' | 'div')[] = ['iframe']; | ||
public h?: string; | ||
public language: string = 'en'; | ||
public license?: string; | ||
public licenseExtras?: string; | ||
public licenseVersion?: string; | ||
public mainLibrary: string; | ||
public metaDescription?: string; | ||
public metaKeywords?: string; | ||
public preloadedDependencies: ILibraryName[]; | ||
public source?: string; | ||
public title: string; | ||
public w?: string; | ||
public yearsFrom?: string; | ||
public yearsTo?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.