ipfs-http-client
Version:
A client library for the IPFS HTTP API
55 lines (50 loc) • 1.09 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var configure = require('../lib/configure.js');
var toUrlSearchParams = require('../lib/to-url-search-params.js');
const createSet = configure.configure(api => {
const set = async (key, value, options = {}) => {
if (typeof key !== 'string') {
throw new Error('Invalid key type');
}
const params = {
...options,
...encodeParam(key, value)
};
const res = await api.post('config', {
signal: options.signal,
searchParams: toUrlSearchParams.toUrlSearchParams(params),
headers: options.headers
});
await res.text();
};
return set;
});
const encodeParam = (key, value) => {
switch (typeof value) {
case 'boolean':
return {
arg: [
key,
value.toString()
],
bool: true
};
case 'string':
return {
arg: [
key,
value
]
};
default:
return {
arg: [
key,
JSON.stringify(value)
],
json: true
};
}
};
exports.createSet = createSet;