Creating a Storage Plugin
Creating a Storage Plugin
Storage plugins are used to store image data.
A storage plugin must implement two methods.
Methods
get(id)
get will be called with an image id, it will look something like this.
It should return a promise that resolves with a buffer of image data:
If there is no image that matches the key, the promise should resolve with null
.
NOTE: The only reason the promise should ever reject is if there was some sort of fetching error (e.g. Amazon S3 returns a 500 error). A missing key is a normal occurrence, do not error for this.
put(id, record)
put will be called with a record that looks like the following:
It should return a promise that resolves when the file has been successfully saved, and rejects if there was some problem saving the file.
init()
Any plugin may also (optionally) provide an init
method.
If one is found, librarian will wait until the init()
promise resolves before processing requests.
This is a good way for plugins to check for the availability of external resources.
The init()
promise should resolve when the plugin is good to go,
and should reject if the plugin will never be able to function correctly.
An example of this would be invalid api keys for the S3 Storage plugin or bad connection details for the Mysql Data plugin.
Tests
Your plugin should pass the storage plugin tests.