ClojureScript library for calling the IPFS HTTP API
Using:
(ns my.app
(:require [cljs-ipfs-api.core :as icore :refer [init-ipfs]]
[cljs-ipfs-api.files :as ifiles]))
https://district0x.github.io/cljs-ipfs-http-client/
So basically, stick with the js-ipfs-api docs, all methods there have their kebab-cased version in this library. Also, return values and responses in callbacks are automatically kebab-cased and keywordized. You can provide IPFS instance as an additional first argument to each function, in case you'd need more than one connection.
(init-ipfs)
;;(init-ipfs {:host "http://127.0.0.1:5001" :endpoint "/api/v0"})
;;fls to avoid clashes with ls from files.ls
(ifiles/fls "/ipfs/QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG/" (fn [err files]
(info [err "ERROR"])
(info [files "FILES"])))
;;Files upload on NODEJS see files_test
;;Files upload -- reagent
(let [f (atom nil)]
(fn []
[:form
{:on-submit
(fn [e]
(.preventDefault e)
(ifiles/add @f (fn [err files]
(info ["DONE" err files]))))}
[:input {:type "file"
:on-change #(let [v (-> % .-target .-files (aget 0))]
(reset! f v))}]
[:input
{:type "submit"
:value "Import"}]]))
You can also provide an async channel instead of the callback function
As this library is meant to work both in browsers and on Node.js (server), it must be tested on both as well. Additionally CI runs the tests slightly different way, so that's the 3rd test environment.
- it's still in browser, but CI gets success vs failure depending on the
- browser process exit code so a bit of extra work is needed to get it out from JS (Karma is used for that)
- Build:
npx shadow-cljs compile test-node
- Tests:
node out/node-tests.js
- Build:
npx shadow-cljs watch test-browser
- Tests: http://d0x-vm:6502
- Build:
npx shadow-cljs compile test-ci
- Tests:
CHROME_BIN=`which chromium-browser` npx karma start karma.conf.js --single-run
- Run headless chrome:
chromium-browser --headless --remote-debugging-port=9222 --remote-debugging-address=0.0.0.0 --allowed-origins="*" https://chromium.org
- Open
chrome://inspect/#devices
and configure remote target with IP ADDRESS (hostname doesn't work)
- Build:
clj -T:build jar
- Release:
clj -T:build deploy