H5P NodeJS Library
    Preparing search index...

    This class manages library installations, enumerating installed libraries etc. It is storage agnostic and can be re-used in all implementations/plugins.

    Index

    Constructors

    • Parameters

      • libraryStorage: ILibraryStorage

        the library repository that persists library somewhere.

      • fileUrlResolver: ILibraryFileUrlResolver = ...

        gets URLs at which a file in a library can be downloaded. Must be passed through from the implementation.

      • OptionalalterLibrarySemantics: (library: ILibraryName, semantics: ISemanticsEntry[]) => ISemanticsEntry[]

        a hook that allows implementations to change the semantics of certain libraries; should be used together with alterLibraryLanguageFile if you plan to use any other language than English! See the documentation of IH5PEditorOptions for more details.

      • OptionalalterLibraryLanguageFile: (
            library: ILibraryName,
            languageFile: ILanguageFileEntry[],
            language: string,
        ) => ILanguageFileEntry[]

        a hook that allows implementations to change the language files of certain libraries; should be used together with alterLibrarySemantics if you plan to use any other language than English! See the documentation of IH5PEditorOptions for more details.

      • OptionaltranslationFunction: ITranslationFunction

        (optional) The translation function to use if you want to localize library metadata (titles). If undefined, no localization will be performed.

      • OptionallockProvider: ILockProvider

        (optional) an implementation of a locking mechanism that prevents race conditions. If this is left undefined a simple single-process lock mechanism will be used. If the library is used within a multi-process or cluster setup, it is necessary to pass in a distributed locking implementation.

      • Optionalconfig: {
            installLibraryLockMaxOccupationTime: number;
            installLibraryLockTimeout: number;
        }

      Returns LibraryManager

    Properties

    libraryStorage: ILibraryStorage

    the library repository that persists library somewhere.

    Methods

    • Returns a readable stream of a library file's contents. Throws an exception if the file does not exist.

      Parameters

      • library: ILibraryName

        library

      • file: string

        the relative path inside the library

      Returns Promise<IFileStats>

      a readable stream of the file's contents

    • Returns a readable stream of a library file's contents. Throws an exception if the file does not exist.

      Parameters

      • library: ILibraryName

        library

      • file: string

        the relative path inside the library

      Returns Promise<Readable>

      a readable stream of the file's contents

    • Gets the language file for the specified language.

      Parameters

      Returns Promise<string>

      a string with the contents language file; null if the library isn't localized to the language

    • Returns the information about the library that is contained in library.json.

      Parameters

      • library: ILibraryName

        The library to get (machineName, majorVersion and minorVersion is enough)

      • Optionallanguage: string

        (optional) the language to use for the title, will always fall back to English if it is not possible to localize

      Returns Promise<IInstalledLibrary>

      the decoded JSON data or undefined if library is not installed

    • Returns a (relative) URL for a library file that can be used to hard-code URLs of specific files if necessary. Avoid using this method when possible! This method does NOT check if the file exists!

      Parameters

      • library: ILibraryName

        the library for which the URL should be retrieved

      • file: string

        the filename inside the library (path)

      Returns string

      the URL of the file

    • Returns a URL of the upgrades script in the library

      Parameters

      • library: ILibraryName

        the library whose upgrade script should be accessed

      Returns Promise<string>

      the URL of upgrades.js. Null if there is no upgrades file. (The null value can be passed back to the client.)

    • Installs or updates a library from a temporary directory. It does not delete the library files in the temporary directory. The method does NOT validate the library! It must be validated before calling this method! Throws an error if something went wrong and deletes the files already installed.

      Parameters

      • directory: string

        The path to the temporary directory that contains the library files (the root directory that includes library.json)

      • restricted: boolean = false

      Returns Promise<ILibraryInstallResult>

      a structure telling if a library was newly installed, updated or nothing happened (e.g. because there already is a newer patch version installed).

    • Checks if a library was installed.

      Parameters

      Returns Promise<boolean>

      true if the library has been installed

    • Check if the library contains a file

      Parameters

      Returns Promise<boolean>

      true if file exists in library, false otherwise

    • Checks if the given library has a higher version than the highest installed version.

      Parameters

      • library: IFullLibraryName

        Library to compare against the highest locally installed version.

      Returns Promise<boolean>

      true if the passed library contains a version that is higher than the highest installed version, false otherwise

    • Gets a list of files that exist in the library.

      Parameters

      • library: ILibraryName

        the library for which the files should be listed

      Returns Promise<string[]>

      the files in the library including language files

    • Get a list of the currently installed libraries.

      Parameters

      • OptionalmachineName: string

        (optional) only return results for the machine name

      Returns Promise<{ [machineName: string]: IInstalledLibrary[] }>

      An object which has properties with the existing library machine names. The properties' values are arrays of Library objects, which represent the different versions installed of this library.

    • Gets a list of translations that exist for this library.

      Parameters

      Returns Promise<string[]>

      the language codes for translations of this library