This method must be called by the GET route at the Ajax URL, e.g. GET /ajax. This route must be implemented for editor to work.
This is the sub action that should be executed. It is part of the query like this: GET /ajax?action=xyz Possible values:
Optional
machineName: string(need if action == 'libraries') The machine name of the library about which information is requested, e.g. 'H5P.Example'. It is part of the query, e.g. +machineName=H5P.Example
Optional
majorVersion: string | number(need if action == 'libraries') The major version of the library about which information is requested, e.g. '1'.
Optional
minorVersion: string | number(need if action == 'libraries') The minor version of the library about which information is requested, e.g. '0'.
Optional
language: string(can be set if action == 'libraries') The language in which the editor is currently displayed, e.g. 'en'. Will default to English if unset.
Optional
user: IUser(needed if action == 'content-type-cache') The user who is displaying the H5P Content Type Hub. It is the job of the implementation to inject this object.
an object which must be sent back in the response as JSON with HTTP status code 200
The method must be called by the GET /content/
Note: You can also use a status route to serve content files, but then you lose the rights and permission check.
the contentId of the resource
the filename of the resource
the user who is requesting the resource
Optional
getRangeCallback: (fileSize: number) => { end: number; start: number }a function that can be called to retrieve the start and end of a range; if the request doesn't specify a range, simply return undefined; if you do not specify getRangeCallback, the method will simply always use the whole file.
mimetype: the mimetype of the file, the range (undefined if unused), stats about the file and a readable. Do this with the response:
bytes <start-end>/<totalLength>
IMPORTANT: You must subscribe to the error event of the readable and
send back a 404 status code if an error occurs. This is necessary as the
AWS S3 library doesn't throw proper 404 errors.This method must be called when the editor requests the parameters
(= content.json) of a piece of content, which is done with
GET /params/
the content id of the piece of content; it is part of the requests URL (see above)
the user who is using the editor. It is the job of the implementation to inject this object.
an object which must be sent back in the response as JSON with HTTP status code 200
This method must be called when the user downloads a H5P package (the
.h5p file containing all libraries and content files). The route is
GET /download/
the id of the content object. It is part of the request URL (see above).
the user who wants to download the package. It is the job of the implementation to inject this object.
a Writable to which the file contents are piped.
no return value; the result is directly piped to the Writable, which is the Response object in Express, for instance. Note that you must set the HTTP Header 'Content-disposition: attachment; filename=xyz.h5p' in your response!
This method must be called when the client requests a library file with
GET /libraries/
Note: You can also use a static route to serve library files.
the ubername of the library (e.g. H5P.Example-1.0). This is the first component of the path after /libraries/
the filename of the requested file, e.g. xyz.js. This is the rest of the path after the uberName.
all the values that must be send back with HTTP status code 200. You should send back:
The method must be called by the GET /temp-files/
the filename of the resource
the user who is requesting the resource
Optional
getRangeCallback: (fileSize: number) => { end: number; start: number }a function that can be called to retrieve the start and end of a range; if the request doesn't specify a range, simply return undefined; if you do not specify getRangeCallback, the method will simply always use the whole file.
mimetype: the mimetype of the file, the range (undefined if unused), stats about the file and a readable. Do this with the response:
bytes <start-end>/<totalLength>
IMPORTANT: You must subscribe to the error event of the readable and
send back a 404 status code if an error occurs. This is necessary as the
AWS S3 library doesn't throw proper 404 errors.Implements the POST /ajax route. Performs various actions. Don't be confused by the fact that many of the requests dealt with here are not really POST requests, but look more like GET requests. This is simply how the H5P client works and we can't change it.
This is the sub action that should be executed. It is part of the query like this: POST /ajax?action=xyz Possible values:
Optional
body: the parsed JSON content of the request body
Optional
language: string(needed for 'translations' and optionally possible for 'libraries') the language code for which the translations should be retrieved, e.g. 'en'. This paramter is part of the query URL, e.g. POST /ajax?action=translations&language=en
Optional
user: IUser(needed for 'files', 'library-install' and 'get-content') the user who is performing the action. It is the job of the implementation to inject this object.
Optional
filesFile: {(needed for 'files') the file uploaded to the server; this file is part of the HTTP request and has the name 'file'.
Optional
id: string(needed for 'library-install') the machine name of the library to install. The id is part of the query URL, e.g. POST /ajax?action=library-install&id=H5P.Example
Optional
translate: (stringId: string, replacements: { [key: string]: any }) => string(needed for 'library-install' and 'library-upload') a translation function used to localize messages
Optional
libraryUploadFile: {Optional
hubId: string(need for 'get-content') the id of a content object on the H5P Content Hub
an object which must be sent back in the response as JSON with HTTP status code 200
Each method in this class corresponds to a route that is called by the H5P client. Normally, the implementation must call them and send back the return values as a JSON body in the HTTP response.
If something goes wrong, the methods throw H5pErrors, which include HTTP status codes. Send back these status codes in your HTTP response.
Remarks:
getContentFile
andgetTemporaryFile
for more details.