dbdbdb
v0.0.7
Published
Utility for using the Dropbox Javascript SDK as a FS System with a hacky JSON database
Downloads
6
Readme
DBDBDB - Simple JSON File Database Using Dropbox Javascript SDK
Prerequisites
- Create an dropbox api App folder app: https://www.dropbox.com/developers
- Save the app key
Usage:
Install: npm i dbdbdb --save
import dbdb from "dbdbdb";
const {
authUrl,
getClient,
logOutDropbox,
readDatabase,
updateDatabase,
uploadImage
} = dbdb({ clientId: "YOUR_APP_KEY" });
authUrl
String
A url to enable a user to authenticate with Dropbox and redirect to your app with an auth token.
Dropbox SDK Reference: http://dropbox.github.io/dropbox-sdk-js/Dropbox.html#getAuthenticationUrl
Authentication Flow Information: https://www.dropbox.com/developers/reference/oauth-guide
getClient
Function
Returns a Dropbox SDK class instance. If a client instance is not yet available, it creates a new one by using a token found in sessionStorage or in the current url.
logOutDropbox
Function
Removes authentication token from localStorage. You are responsible for destroying your application's SDK client instance.
readDatabase
Function
Returns a Promise. Fetches the configured JSON database file from dropbox, parses the data and returns it.
Usage:
readDatabase().then(({ articles }) => {
// do something with articles
});
updateDatabase
Async Function
Returns a Promise. Reads the current database, then peforms a shallow merge of that with the new data provided in argument.
Usage:
updateDatabase({ data: { articles: [{ title: "My Article" }] } });
uploadImage
Async Function
Returns a file object containing a public image url.
Usage:
const image = await uploadImage({ file: { ... } });
console.log(image.url); // https://public-url-to-image
See React example