ghost-storage-adapter-oracle-ords, A Oracle Cloud Autonomous JSON Databases storage adapter for Ghost 5.x

npm install ghost-storage-adapter-oracle-ords

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


use queryJSONDocument to find the image stored by path andreturn the Buffer from the blob field.

Ghost Configuration"storage": { "active": "OracleImagesStorage", "OracleImagesStorage": { "oauthClients": [ { "client_id": "YOUR_ORACLE_AUTONOMOUS_JSON_DATABASE_OAUTH_CLIENT_ID", "client_secret": "YOUR_ORACLE_AUTONOMOUS_JSON_DATABASE_OAUTH_CLIENT_SECRET", "schema": "YOUR_ORACLE_AUTONOMOUS_JSON_DATABASE_USER", "ords_url": "YOUR_ORACLE_AUTONOMOUS_JSON_DATABASE_ORDS_URL", "alias": "YOUR_ORACLE_AUTONOMOUS_JSON_DATABASE_COLLECTION_NAME"        }, ] } }You can put multiple Oracle Cloud Autonomous JSON Databases clients in the above.You can get 40Gb free space to use per account. if you have 10 Oracle Cloud account,You can use 400Gb free space.:)

Use this adapter in your GhostIn my another blog( hosted on free Google Computer Engine,It is a self hosted Ghost instance. The below photo is served with path startingwith /content/images/, but you can't any images under the /content/images directoryon my GCP vm's local file system.

Subscribe to Post, Code and Quiet Time.

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.