This storage implementation stores content data in a MongoDB collection and a S3 bucket. The parameters and metadata of a H5P content object are stored in MongoDB, while all files are put into S3 storage.

Implements

Constructors

  • Parameters

    • s3: S3

      the S3 content storage; Must be either set to a bucket or the bucket must be specified in the options!

    • mongodb: Collection<{ creator: string; metadata: IContentMetadata; parameters: any }>

      a MongoDB collection (read- and writable)

    • options: {
          invalidCharactersRegexp?: RegExp;
          maxKeyLength?: number;
          s3Acl?: ObjectCannedACL;
          s3Bucket: string;
      }

      options

      • 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.

      • OptionalmaxKeyLength?: number

        Indicates how long keys in S3 can be. Defaults to 1024. (S3 supports 1024 characters, other systems such as Minio might only support 255 on Windows).

      • Optionals3Acl?: ObjectCannedACL

        The ACL to use for uploaded content files. Defaults to private.

      • s3Bucket: string

        The bucket to upload to and download from. (required)

    Returns MongoS3ContentStorage

Methods

  • Creates or updates a content object in the repository. Throws an error if something went wrong.

    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.

    • OptionalcontentId: string

      (optional) The content id to use

    Returns Promise<string>

    The newly assigned content id

  • Adds a content file to an existing content object. Throws an error if something went wrong.

    Parameters

    • contentId: 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 piece of content exists in storage.

    Parameters

    • contentId: string

      the content id to check

    Returns Promise<boolean>

    true if the piece of content exists

  • Deletes a content object and all its dependent files from the repository. Throws errors if something goes wrong.

    Parameters

    • contentId: string

      The content id to delete.

    • Optionaluser: IUser

      The user who wants to delete the content

    Returns Promise<void>

  • Deletes a file from a content object.

    Parameters

    • contentId: string

      the content object the file is attached to

    • filename: string

      the file to delete

    • Optionaluser: IUser

    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 information about a content file (e.g. image or video) inside a piece of content.

    Parameters

    • contentId: string
    • filename: string

      the filename of the file to get information about

    • user: IUser

      the user who wants to retrieve the content file

    Returns Promise<IFileStats>

  • Returns a readable stream of a content file (e.g. image or video) inside a piece of content Note: Make sure to handle the 'error' event of the Readable! This method does not check if the file exists in storage to avoid the extra request. However, this means that there will be an error when piping the Readable to the response if the file doesn't exist!

    Parameters

    • contentId: 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
    • OptionalrangeEnd: number

    Returns Promise<Readable>

  • Returns the content object (=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 content object

  • 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

  • Lists the content objects in the system (if no user is specified) or owned by the user.

    Parameters

    • Optionaluser: IUser

      (optional) the user who owns the content

    Returns Promise<string[]>

    a list of contentIds

  • 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