H5P NodeJS Library
    Preparing search index...

    Persists content to the disk.

    Implements

    Index

    Constructors

    • Parameters

      • contentPath: string

        The absolute path to the directory where the content should be stored

      • Optionaloptions: { invalidCharactersRegexp?: RegExp; maxPathLength?: number }
        • OptionalinvalidCharactersRegexp?: RegExp

          These characters will be removed from files that are saved to S3. There is a very strict default list that basically only leaves alphanumeric filenames intact. Should you need more relaxed settings you can specify them here.

        • OptionalmaxPathLength?: number

      Returns FileContentStorage

    Properties

    contentPath: string

    The absolute path to the directory where the content should be stored

    options?: { invalidCharactersRegexp?: RegExp; maxPathLength?: number }

    Type declaration

    • OptionalinvalidCharactersRegexp?: RegExp

      These characters will be removed from files that are saved to S3. There is a very strict default list that basically only leaves alphanumeric filenames intact. Should you need more relaxed settings you can specify them here.

    • OptionalmaxPathLength?: number

    Methods

    • Creates a content object in the repository. Add files to it later with addContentFile(...). Throws an error if something went wrong. In this case no traces of the content are left in storage and all changes are reverted.

      Parameters

      • metadata: IContentMetadata

        The metadata of the content (= h5p.json)

      • content: any

        the content object (= content/content.json)

      • user: IUser

        The user who owns this object.

      • Optionalid: string

        (optional) The content id to use

      Returns Promise<string>

      The newly assigned content id

    • Adds a content file to an existing content object. The content object has to be created with createContent(...) first.

      Parameters

      • id: string

        The id of the content to add the file to

      • filename: string

        The filename

      • stream: Stream

        A readable stream that contains the data

      • user: IUser

        The user who owns this object

      Returns Promise<void>

    • Checks if a file exists.

      Parameters

      • contentId: string

        The id of the content to add the file to

      • filename: string

        the filename of the file to get

      Returns Promise<boolean>

      true if the file exists

    • Returns a readable stream of a content file (e.g. image or video) inside a piece of content

      Parameters

      • id: string

        the id of the content object that the file is attached to

      • filename: string

        the filename of the file to get

      • user: IUser

        the user who wants to retrieve the content file

      • OptionalrangeStart: number

        (optional) the position in bytes at which the stream should start

      • OptionalrangeEnd: number

        (optional) the position in bytes at which the stream should end

      Returns Promise<ReadStream>

    • Returns the parameters (=content.json) for a content id

      Parameters

      • contentId: string

        the content id for which to retrieve the metadata

      • Optionaluser: IUser

        (optional) the user who wants to access the metadata. If undefined, access must be granted.

      Returns Promise<any>

      the parameters

    • Calculates how often a library is in use.

      Parameters

      • library: ILibraryName

        the library for which to calculate usage.

      Returns Promise<{ asDependency: number; asMainLibrary: number }>

      asDependency: how often the library is used as subcontent in content; asMainLibrary: how often the library is used as a main library

    • Gets the filenames of files added to the content with addContentFile(...) (e.g. images, videos or other files)

      Parameters

      • contentId: string

        the piece of content

      • user: IUser

        the user who wants to access the piece of content

      Returns Promise<string[]>

      a list of files that are used in the piece of content, e.g. ['image1.png', 'video2.mp4']

    • Removes invalid characters from filenames and enforces other filename rules required by the storage implementation (e.g. filename length restrictions).

      Parameters

      • filename: string

        the filename to sanitize; this can be a relative path (e.g. "images/image1.png")

      Returns string

      the clean filename