Commit 0f517e4c authored by Vladislav Bashkirev's avatar Vladislav Bashkirev

Introduce pin and unpin methods

Wrap IPFS pin.add and pin.rm to allow access for other classes.
parent a6f3bac8
...@@ -20,6 +20,16 @@ class Ipfs { ...@@ -20,6 +20,16 @@ class Ipfs {
} }
/** /**
* Stores an IPFS object from a given path locally to disk.
* @param {String} hash IPFS hash.
* @return {Promise} Pinned object.
*/
pin(hash) {
logging.verbose(`Pinning object ${hash} to local storage`);
return this.ipfs.pin.add(hash);
}
/**
* Serves attachment to the client. * Serves attachment to the client.
* @param {String} hash IPFS hash. * @param {String} hash IPFS hash.
* @return {Promise} Readable Stream of attachment. * @return {Promise} Readable Stream of attachment.
...@@ -36,6 +46,17 @@ class Ipfs { ...@@ -36,6 +46,17 @@ class Ipfs {
} }
/** /**
* Removes the pin from the given object allowing it to be garbage
* collected if needed.
* @param {String} hash IPFS hash.
* @return {Promise} Unpinned object.
*/
unpin(hash) {
logging.verbose(`Unpinning object ${hash} from local storage`);
return this.ipfs.pin.rm(hash);
}
/**
* Uploads attachment to IPFS. * Uploads attachment to IPFS.
* @param {File} file Multipart/form-data file. * @param {File} file Multipart/form-data file.
* @return {Promise} IPFS hash of uploaded attachment. * @return {Promise} IPFS hash of uploaded attachment.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment