A fetch-based API for interacting with dat storage providers
Uses cross-fetch for HTTP requests, so it should work in many environments. Based on DEP-0003.
npm i -s dat-storage-client
const DatStorageClient = require('dat-storage-client')
const SERVICE_URL = 'https://hashbase.io'
const client = new DatStorageClient(SERVICE_URL)
await client.login(username, password)
await client.add({
url: 'dat://60c525b5589a5099aa3610a8ee550dcd454c3e118f7ac93b7d41b6b850272330'
})
const dats = await client.list()
Initialize a new client (scoped to a given provider).
The url
is the root URL of your storage provider (e.g. https://hashbase.io
).
You can optionally pass in a sessionToken
if you've saved one from a previous session.
Get the current session token. Will be set to null
if not logged in. This session token will get sent as part of every request in the authorization
header as a Bearer Token.
Get the URL of the storage provider for this client
Login to the storage provider using your username and password. This will save your sessionToken
to the client so that it will be used in subsequent requests.
You can save the sessionToken
somewhere to use with the client and reduce login attempts.
Logout of the storage provider. You need to be logged in first.
Get the info about the account that's currently logged in.
List the items that have been added to this storage provider. The items include a name
, url
, title
, description
and a list of additionalUrls
that it can be accessed at. You must be logged in for this to work.
Add an archive to the storage provider. Only the url
is required. You must be logged in for this to work.
Remove an archive from the storage provider. You must be logged in for this to work.
Get information about a given archive. The key
must be the contents of the key for that archive. E.g. 60c525b5589a5099aa3610a8ee550dcd454c3e118f7ac93b7d41b6b850272330
. You must be logged in for this to work.
Update information for a given archive. You must be logged in for this to work.