H5P NodeJS Library
    Preparing search index...

    Implementations need to implement the ILibraryStorage interface and pass it to H5PEditor. It is used to persist library information and files permanently. Note that the library metadata and semantics are accessed regularly, so caching them is a good idea. The library files will also be accessed frequently, so it makes sense to keep them in memory and not access a hard disk every time they are downloaded. See the FileLibraryStorage sample implementation in the examples directory for more details.

    interface ILibraryStorage {
        addFile(
            library: ILibraryName,
            filename: string,
            readStream: Readable,
        ): Promise<boolean>;
        addLibrary(
            libraryData: ILibraryMetadata,
            restricted: boolean,
        ): Promise<IInstalledLibrary>;
        clearFiles(library: ILibraryName): Promise<void>;
        deleteLibrary(library: ILibraryName): Promise<void>;
        fileExists(library: ILibraryName, filename: string): Promise<boolean>;
        getAllDependentsCount(): Promise<{ [ubername: string]: number }>;
        getDependentsCount(library: ILibraryName): Promise<number>;
        getFileAsJson(library: ILibraryName, file: string): Promise<any>;
        getFileAsString(library: ILibraryName, file: string): Promise<string>;
        getFileStats(library: ILibraryName, file: string): Promise<IFileStats>;
        getFileStream(library: ILibraryName, file: string): Promise<Readable>;
        getInstalledLibraryNames(machineName?: string): Promise<ILibraryName[]>;
        getLanguages(library: ILibraryName): Promise<string[]>;
        getLibrary(library: ILibraryName): Promise<IInstalledLibrary>;
        isInstalled(library: ILibraryName): Promise<boolean>;
        listAddons(): Promise<ILibraryMetadata[]>;
        listFiles(library: ILibraryName): Promise<string[]>;
        updateAdditionalMetadata(
            library: ILibraryName,
            additionalMetadata: Partial<IAdditionalLibraryMetadata>,
        ): Promise<boolean>;
        updateLibrary(
            libraryMetadata: ILibraryMetadata,
        ): Promise<IInstalledLibrary>;
    }

    Implemented by

    Index

    Methods

    • Adds a library file to a library. The library metadata must have been installed with addLibrary(...) first. Throws an error if something unexpected happens. In this case the method calling addFile(...) will clean up the partly installed library.

      Parameters

      • library: ILibraryName

        The library that is being installed

      • filename: string

        Filename of the file to add, relative to the library root

      • readStream: Readable

        The stream containing the file content

      Returns Promise<boolean>

      true if successful

    • Adds the metadata of the library to the repository and assigns a new id to the installed library. This dea is used later when the library must be referenced somewhere. Throws errors if something goes wrong.

      Parameters

      • libraryData: ILibraryMetadata

        The library metadata object (= content of library.json)

      • restricted: boolean

        True if the library can only be used be users allowed to install restricted libraries.

      Returns Promise<IInstalledLibrary>

      The newly created library object to use when adding library files with addFile(...)

    • Removes all files of a library. Doesn't delete the library metadata. (Used when updating libraries.)

      Parameters

      • library: ILibraryName

        the library whose files should be deleted

      Returns Promise<void>

    • Removes the library and all its files from the repository. Throws errors if something went wrong.

      Parameters

      Returns Promise<void>

    • Check if the library contains a file.

      Parameters

      Returns Promise<boolean>

      true if file exists in library, false otherwise

    • Counts how often libraries are listed in the dependencies of other libraries and returns a list of the number.

      Note: Implementations should not count circular dependencies that are caused by editorDependencies. Example: H5P.InteractiveVideo has H5PEditor.InteractiveVideo in its editor dependencies. H5PEditor.Interactive video has H5P.InteractiveVideo in its preloaded dependencies. In this case H5P.InteractiveVideo should get a dependency count of 0 and H5PEditor.InteractiveVideo should have 1. That way it is still possible to delete the library from storage.

      Returns Promise<{ [ubername: string]: number }>

      an object with ubernames as key. Example: { 'H5P.Example': 10 } This means that H5P.Example is used by 10 other libraries.

    • Returns the number of libraries that depend on this (single) library.

      Parameters

      Returns Promise<number>

      the number of libraries that depend on this library.

    • Returns a information about a library file. Throws an exception if the file does not exist.

      Parameters

      • library: ILibraryName

        library

      • file: string

        the relative path inside the library

      Returns Promise<IFileStats>

      the file stats

    • 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

    • Returns all installed libraries or the installed libraries that have the machine name.

      Parameters

      • OptionalmachineName: string

        (optional) only return libraries that have this machine name

      Returns Promise<ILibraryName[]>

      the libraries installed

    • Gets a list of installed language files for the library.

      Parameters

      Returns Promise<string[]>

      The list of JSON files in the language folder (without the extension .json)

    • Checks if a library is installed.

      Parameters

      Returns Promise<boolean>

      true if the library is installed

    • Returns a list of library addons that are installed in the system. Addons are libraries that have the property 'addTo' in their metadata. ILibraryStorage implementation CAN but NEED NOT implement the method. If it is not implemented, addons won't be available in the system.

      Returns Promise<ILibraryMetadata[]>

    • Gets a list of all library files that exist for this library.

      Parameters

      Returns Promise<string[]>

      all files that exist for the library

    • Updates the additional metadata properties that is added to the stored libraries. This metadata can be used to customize behavior like restricting libraries to specific users.

      Implementations should avoid updating the metadata if the additional metadata if nothing has changed.

      Parameters

      Returns Promise<boolean>

      true if the additionalMetadata object contained real changes and if they were successfully saved; false if there were not changes. Throws an error if saving was not possible.

    • Updates the library metadata. This is necessary when updating to a new patch version. After this clearFiles(...) is called by the LibraryManager to remove all old files. The next step is to add the patched files with addFile(...).

      Parameters

      Returns Promise<IInstalledLibrary>

      The updated library object