Client API for Dat pinning services. Conforms to the Dat Pinning Service API.
To create a client:
const {createClient} = require('dat-pinning-service-client')
createClient('https://my-pinning-service.com', {username: 'bob', password: 'hunter2'}, (err, client) => {
if (err) throw err
// ...
})
Alternatively:
const {DatPinningServiceClient} = require('dat-pinning-service-client')
var client = new DatPinningServiceClient('https://my-pinning-service.com')
client.fetchPSADoc(err => {
if (err) throw err
client.login('bob', 'hunter2', err => {
if (err) throw err
// ...
})
})
All of the methods provide the response body and give an error if a non-2xx response is received.
The errors will have the .statusCode
and .responseBody
set.
Create a new client object. Will fetch the PSA document and run login if the creds are specified.
Create a new client object. You can optionally provide the PSA document, which is useful if you've cached it from a previous session.
Manually set the PSA document (useful if you've cached it from a previous session).
You can find the PSA doc on client.psaDoc
.
Manually set the session token (useful if you've cached it from a previous session).
You can find the token on client.sessionToken
.
Start a session.
You can check client.hasSession
to see if a session token has been stored.
End the session.
Get the account info for the current session. Returns
{
email: String, the accounts email (required)
username: String, the accounts username (required)
diskUsage: Number, how much disk space has the user's data taken? (optional)
diskQuota: Number, how much disk space can the user's data take? (optional)
updatedAt: Number, the Unix timestamp of the last time the user account was updated (optional)
createdAt: Number, the Unix timestamp of the last time the user account was updated (optional)
}
Get the dats pinned by the user. Returns
{
items: [{
url: String, dat url
name: String, optional shortname assigned by the user
title: String, optional title extracted from the dat's manifest file
description: String, optional description extracted from the dat's manifest file
additionalUrls: Array of Strings, optional list of URLs the dat can be accessed at
}]
}
Pin a dat. Params:
url
String, required url/key of the datname
String, optional shortname for the archivedomains
Array of Strings, optional list of domain-names the dat should be made available at
Unpin a dat. Params:
url
String, required url/key of the dat
Get a pinned dat. Returns:
{
url: String, dat url
name: String, optional shortname assigned by the user
title: String, optional title extracted from the dat's manifest file
description: String, optional description extracted from the dat's manifest file
additionalUrls: Array of Strings, optional list of URLs the dat can be accessed at
}
Update a pinned dat. Params:
url
String, required url/key of the datname
String, optional shortname for the archivedomains
Array of Strings, optional list of domain-names the dat should be made available at
Small utility for testing endpoints:
npm i -g dat-pinning-service-client
dat-pinning-service-client https://my-pinning-service.com bob hunter2 getDat 9900f9aad4d6e79e0beb1c46333852b99829e4dfcdfa9b690eeeab3c367c1b9a
The usage is:
dat-pinning-service-client [service] [username] [password] [action] [args...]