ghost-storage-adapter-oracle-ords, A Oracle Cloud Autonomous JSON Databases storage adapter for Ghost 5.x
npm install ghost-storage-adapter-oracle-ords
https://www.npmjs.com/package/ghost-storage-adapter-oracle-ords
https://github.com/lengerrong/ghost-storage-adapter-oracle-ords#readme
In my last post, how to custom storage adapters to make your self-hosted Ghost instance filesystem completely external?, I had a plan to implement a storage adapter of Ghost for Oracle Cloud Autonomous JSON Databases to leverage the always free 40Gb space provided by Oracle Cloud.
After researched Oracle ORDS REST API, I implement a orcal-ords-client lib to encapsulate the REST APIs for easy usage. Then I developed this storage adapter based on the orcal-ords-client lib.
Core Idea
The storage adapter is to save the images uploaded to Ghost into external rather than the file system where your Ghost instance deployed. I designed the below JSON document for a image:
{ "path": "the unique path of the image, just consider the image is saved to local file system", "blob": "the json string of a Buffer object which is the content of the image, maximum size is 4.4M after tested", "type": "the mimetype of the image, such as png, jpeg and etc, used to set the content-type when the image been requested"}
With the three interfaces provided by the orcal-ords-client lib,
putJSONDocument(alias: string, json: JSONValue): Promise<Item>;
deleteJSONObject(alias: string, id: string): Promise<boolean>;
queryJSONDocument(alias: string, query: any, payload: any): Promise<Collection>;
We are able to implement the required methods to custom the storage adapter.delete: first use queryJSONDocument to find the id of the image stored by path, and then delete the image via deleteJSONObjectexists: use queryJSONDocument to find the image stored by pathsave: construct the JSON object and save into database via putJSONDocumentserve: use queryJSONDocument to find the image stored by path and thenpipe the Buffer content to response stream
read: |
use queryJSONDocument to find the image stored by path andreturn the Buffer from the blob field.