Compare commits
3 Enmetoj
Ambrevar/m
...
master
Author | SHA1 | Date | |
---|---|---|---|
Jaidyn Ann | d5c2aa2511 | ||
bnmcgn@gmail.com | 00d79f4173 | ||
Jaidyn Ann | 13cd1091fd |
|
@ -5,7 +5,7 @@ CL-IPFS-API²
|
||||||
:cl-ipfs-api² is a pretty simple set of IPFS bindings for Common Lisp, using
|
:cl-ipfs-api² is a pretty simple set of IPFS bindings for Common Lisp, using
|
||||||
the HTTP API for (almost) everything, except for pubsub (which uses the locally
|
the HTTP API for (almost) everything, except for pubsub (which uses the locally
|
||||||
installed go-ipfs program).
|
installed go-ipfs program).
|
||||||
It uses Dexador, YASON, and UIOP.
|
It uses Drakma, YASON, and UIOP.
|
||||||
|
|
||||||
|
|
||||||
————————————————————————————————————————
|
————————————————————————————————————————
|
||||||
|
@ -118,6 +118,5 @@ BORING STUFF
|
||||||
————————————————————————————————————————
|
————————————————————————————————————————
|
||||||
License is the GNU LGPLv3:
|
License is the GNU LGPLv3:
|
||||||
check COPYING.txt (/ipfs/QmR8Rnk5QdXgrXRqmgMLmG5PuHZEjujfa3rfVhPV99TLY7)
|
check COPYING.txt (/ipfs/QmR8Rnk5QdXgrXRqmgMLmG5PuHZEjujfa3rfVhPV99TLY7)
|
||||||
Author is Jaidyn Ann <jadedctrl@teknik.io>
|
Author is Jaidyn Ann <jadedctrl@posteo.at>
|
||||||
Sauce is at https://git.feneas.org/detruota/cl-ipfs-api2
|
Sauce is at https://hak.xwx.moe/jadedctrl/cl-ipfs-api2
|
||||||
https://github.com/JadedCtrl/cl-ipfs-api2
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
(defsystem "cl-ipfs-api2"
|
(defsystem "cl-ipfs-api2"
|
||||||
:version "0.51"
|
:version "0.51"
|
||||||
:license "LGPLv3"
|
:license "LGPLv3"
|
||||||
:author "Jaidyn Ann <jadedctrl@teknik.io>"
|
:author "Jaidyn Ann <jadedctrl@posteo.at>"
|
||||||
:description "Bindings for the IPFS HTTP API."
|
:description "Bindings for the IPFS HTTP API."
|
||||||
:depends-on (:alexandria :drakma :yason :arnesi :uiop)
|
:depends-on (:drakma :yason :arnesi :uiop)
|
||||||
:components ((:file "package")
|
:components ((:file "package")
|
||||||
(:file "main")))
|
(:file "main")))
|
||||||
|
|
51
main.lisp
51
main.lisp
|
@ -32,9 +32,7 @@
|
||||||
(let ((result
|
(let ((result
|
||||||
(multiple-value-list
|
(multiple-value-list
|
||||||
(drakma:http-request
|
(drakma:http-request
|
||||||
;; We ensure the string is of 'character elements and not 'base-char
|
(make-call-url call arguments)
|
||||||
;; which would break Puri.
|
|
||||||
(alexandria:copy-array (make-call-url call arguments) :element-type 'character)
|
|
||||||
:method method
|
:method method
|
||||||
:url-encoder #'ipfs::url-encode
|
:url-encoder #'ipfs::url-encode
|
||||||
:parameters parameters
|
:parameters parameters
|
||||||
|
@ -48,10 +46,8 @@
|
||||||
(let* ((result (cond ((stringp body) body)
|
(let* ((result (cond ((stringp body) body)
|
||||||
((vectorp body) (flexi-streams:octets-to-string body))))
|
((vectorp body) (flexi-streams:octets-to-string body))))
|
||||||
(result (if (search "application/json" (cdr (assoc :content-type headers)))
|
(result (if (search "application/json" (cdr (assoc :content-type headers)))
|
||||||
(mapcar (lambda (line)
|
(unless (empty-string-p result)
|
||||||
(simplify (yason:parse line :object-as :alist)))
|
(simplify (yason:parse result :object-as :alist)))
|
||||||
(delete "" (uiop:split-string result :separator (string #\newline))
|
|
||||||
:test 'string=))
|
|
||||||
result)))
|
result)))
|
||||||
(if (eql 200 status-code)
|
(if (eql 200 status-code)
|
||||||
result
|
result
|
||||||
|
@ -87,39 +83,12 @@
|
||||||
;; —————————————————————————————————————
|
;; —————————————————————————————————————
|
||||||
;; ROOT CALLS
|
;; ROOT CALLS
|
||||||
|
|
||||||
(defun parent-directory (path)
|
|
||||||
(if (uiop:directory-pathname-p path)
|
|
||||||
(uiop:pathname-parent-directory-pathname path)
|
|
||||||
(uiop:pathname-directory-pathname path)))
|
|
||||||
|
|
||||||
(defun directory->parameters (dir)
|
|
||||||
(let* ((result '())
|
|
||||||
(root (uiop:ensure-pathname dir :truenamize t))
|
|
||||||
(parent (parent-directory root)))
|
|
||||||
(uiop:collect-sub*directories
|
|
||||||
root
|
|
||||||
#'uiop:directory-exists-p
|
|
||||||
(constantly t)
|
|
||||||
(lambda (subdirectory)
|
|
||||||
(setf result
|
|
||||||
(cons `("file" ,subdirectory
|
|
||||||
:content-type "application/x-directory"
|
|
||||||
:filename ,(uiop:native-namestring (uiop:enough-pathname subdirectory parent)))
|
|
||||||
(append result
|
|
||||||
(mapcar (lambda (file)
|
|
||||||
`("file" ,file
|
|
||||||
:filename ,(uiop:native-namestring (uiop:enough-pathname file parent))))
|
|
||||||
(uiop:directory-files subdirectory)))))))
|
|
||||||
result))
|
|
||||||
|
|
||||||
;; PATHNAME → (HASH-STRING SIZE-NUMBER) || (NIL STRING)
|
;; PATHNAME → (HASH-STRING SIZE-NUMBER) || (NIL STRING)
|
||||||
(defun add (pathname &key (pin 't) (only-hash nil) (cid-version 0))
|
(defun add (pathname &key (pin 't) (only-hash nil) (cid-version 0))
|
||||||
"Add a file to IPFS, return it's hash.
|
"Add a file to IPFS, return it's hash.
|
||||||
/ipns/docs.ipfs.io/reference/api/http/#api-v0-add"
|
/ipns/docs.ipfs.io/reference/api/http/#api-v0-add"
|
||||||
(ipfs-call "add" `(("pin" ,pin) ("only-hash" ,only-hash) ("cid-version" ,cid-version))
|
(ipfs-call "add" `(("pin" ,pin) ("only-hash" ,only-hash) ("cid-version" ,cid-version))
|
||||||
:parameters (if (uiop:directory-exists-p pathname)
|
:parameters `(("file" . ,pathname))))
|
||||||
(directory->parameters pathname)
|
|
||||||
`(("file" . ,pathname)))))
|
|
||||||
|
|
||||||
;; STRING :NUMBER :NUMBER → STRING || (NIL STRING)
|
;; STRING :NUMBER :NUMBER → STRING || (NIL STRING)
|
||||||
(defun cat (ipfs-path &key (offset nil) (length nil))
|
(defun cat (ipfs-path &key (offset nil) (length nil))
|
||||||
|
@ -493,7 +462,7 @@
|
||||||
(defun files-ls (&optional (path "/"))
|
(defun files-ls (&optional (path "/"))
|
||||||
"List directories in local mutable namespace.
|
"List directories in local mutable namespace.
|
||||||
/ipns/docs.ipfs.io/reference/api/http/#api-v0-files-ls"
|
/ipns/docs.ipfs.io/reference/api/http/#api-v0-files-ls"
|
||||||
(ipfs-call "files/ls" `(("arg" ,path) ("long" "true"))))
|
(ipfs-call "files/ls" `(("arg" ,path))))
|
||||||
|
|
||||||
;; STRING [:BOOLEAN :NUMBER :STRING] → NIL || (NIL STRING)
|
;; STRING [:BOOLEAN :NUMBER :STRING] → NIL || (NIL STRING)
|
||||||
(defun files-mkdir (path &key (parents nil) (cid-version nil) (hash nil))
|
(defun files-mkdir (path &key (parents nil) (cid-version nil) (hash nil))
|
||||||
|
@ -523,12 +492,12 @@
|
||||||
"Remove a given file.
|
"Remove a given file.
|
||||||
/ipns/docs.ipfs.io/reference/api/http/#api-v0-files-rm"
|
/ipns/docs.ipfs.io/reference/api/http/#api-v0-files-rm"
|
||||||
(ipfs-call "files/rm" `(("arg" ,path) ("recursive" ,recursive)
|
(ipfs-call "files/rm" `(("arg" ,path) ("recursive" ,recursive)
|
||||||
("force" ,force))))
|
("force" ,force))))
|
||||||
|
|
||||||
;; STRING → ALIST || (NIL STRING)
|
;; STRING → ALIST || (NIL STRING)
|
||||||
(defun files-stat (path)
|
(defun files-stat (path)
|
||||||
"Remove a given file.
|
"Get file status.
|
||||||
/ipns/docs.ipfs.io/reference/api/http/#api-v0-files-rm"
|
/ipns/docs.ipfs.io/reference/api/http/#api-v0-files-stat"
|
||||||
(ipfs-call "files/stat" `(("arg" ,path))))
|
(ipfs-call "files/stat" `(("arg" ,path))))
|
||||||
|
|
||||||
;; PATHNAME STRING [:NUMBER :BOOLEAN :BOOLEAN :BOOLEAN :NUMBER :BOOLEAN
|
;; PATHNAME STRING [:NUMBER :BOOLEAN :BOOLEAN :BOOLEAN :NUMBER :BOOLEAN
|
||||||
|
@ -1132,6 +1101,6 @@ will be passed directly to the files-write function."
|
||||||
ignored
|
ignored
|
||||||
(cl-ppcre:regex-replace-all
|
(cl-ppcre:regex-replace-all
|
||||||
"%2520" (drakma:url-encode
|
"%2520" (drakma:url-encode
|
||||||
(cl-ppcre:regex-replace-all " " string "%20")
|
(cl-ppcre:regex-replace-all " " string "%20")
|
||||||
drakma:*drakma-default-external-format*)
|
:utf-8)
|
||||||
"%20"))
|
"%20"))
|
||||||
|
|
Ŝarĝante…
Reference in New Issue