From cc650645501b8feee517f3226d3b915f73e215ca Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Thu, 22 Sep 2022 12:43:11 +0200 Subject: [PATCH 1/6] Use default Drakma encoding in url-encode. This fixes the load of URLs like bafybeiemxf5abjwjbikoz4mc3a3dla6ual3jsgpdr4cjr3oz3evfyavhwq/I/m/Van_Gogh_-_Bildnis_der_Mutter_des_K%C3%BCnstlers.jpeg --- main.lisp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.lisp b/main.lisp index 2ea88c7..9f8e113 100644 --- a/main.lisp +++ b/main.lisp @@ -1101,6 +1101,6 @@ will be passed directly to the files-write function." ignored (cl-ppcre:regex-replace-all "%2520" (drakma:url-encode - (cl-ppcre:regex-replace-all " " string "%20") - :utf-8) + (cl-ppcre:regex-replace-all " " string "%20") + drakma:*drakma-default-external-format*) "%20")) -- 2.46.0 From a52676d5c3a60adce297dd2c5a223aff36916849 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Fri, 23 Sep 2022 10:23:59 +0200 Subject: [PATCH 2/6] Ensure ipfs-call URL is a 'character string and not a base-string. Otherwise it breaks PURI. --- cl-ipfs-api2.asd | 2 +- main.lisp | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cl-ipfs-api2.asd b/cl-ipfs-api2.asd index 9e66186..e8d8fce 100755 --- a/cl-ipfs-api2.asd +++ b/cl-ipfs-api2.asd @@ -3,6 +3,6 @@ :license "LGPLv3" :author "Jaidyn Ann " :description "Bindings for the IPFS HTTP API." - :depends-on (:drakma :yason :arnesi :uiop) + :depends-on (:alexandria :drakma :yason :arnesi :uiop) :components ((:file "package") (:file "main"))) diff --git a/main.lisp b/main.lisp index 9f8e113..4514367 100644 --- a/main.lisp +++ b/main.lisp @@ -32,7 +32,9 @@ (let ((result (multiple-value-list (drakma:http-request - (make-call-url call arguments) + ;; We ensure the string is of 'character elements and not 'base-char + ;; which would break Puri. + (alexandria:copy-array (make-call-url call arguments) :element-type 'character) :method method :url-encoder #'ipfs::url-encode :parameters parameters -- 2.46.0 From 09ebe83f3707ff9b87febddf6c7be36aee3cf008 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Fri, 23 Sep 2022 13:31:33 +0200 Subject: [PATCH 3/6] Allow reporting multiple results. For instance when adding a directory with multiple files. --- main.lisp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/main.lisp b/main.lisp index 4514367..00bd8ea 100644 --- a/main.lisp +++ b/main.lisp @@ -48,8 +48,10 @@ (let* ((result (cond ((stringp body) body) ((vectorp body) (flexi-streams:octets-to-string body)))) (result (if (search "application/json" (cdr (assoc :content-type headers))) - (unless (empty-string-p result) - (simplify (yason:parse result :object-as :alist))) + (mapcar (lambda (line) + (simplify (yason:parse line :object-as :alist))) + (delete "" (uiop:split-string result :separator (string #\newline)) + :test 'string=)) result))) (if (eql 200 status-code) result -- 2.46.0 From ed9381341754c30e874de75f7aff408bb83930cf Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Fri, 23 Sep 2022 15:45:21 +0200 Subject: [PATCH 4/6] Allow adding directories. --- main.lisp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/main.lisp b/main.lisp index 00bd8ea..56b31c6 100644 --- a/main.lisp +++ b/main.lisp @@ -87,12 +87,39 @@ ;; ————————————————————————————————————— ;; 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) (defun add (pathname &key (pin 't) (only-hash nil) (cid-version 0)) "Add a file to IPFS, return it's hash. /ipns/docs.ipfs.io/reference/api/http/#api-v0-add" (ipfs-call "add" `(("pin" ,pin) ("only-hash" ,only-hash) ("cid-version" ,cid-version)) - :parameters `(("file" . ,pathname)))) + :parameters (if (uiop:directory-exists-p pathname) + (directory->parameters pathname) + `(("file" . ,pathname))))) ;; STRING :NUMBER :NUMBER → STRING || (NIL STRING) (defun cat (ipfs-path &key (offset nil) (length nil)) -- 2.46.0 From a1c5281a389658426390c0a82056e2b9f344c79c Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Sat, 24 Sep 2022 10:33:06 +0200 Subject: [PATCH 5/6] Make files-ls more useful. --- main.lisp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.lisp b/main.lisp index 56b31c6..b1611fb 100644 --- a/main.lisp +++ b/main.lisp @@ -493,7 +493,7 @@ (defun files-ls (&optional (path "/")) "List directories in local mutable namespace. /ipns/docs.ipfs.io/reference/api/http/#api-v0-files-ls" - (ipfs-call "files/ls" `(("arg" ,path)))) + (ipfs-call "files/ls" `(("arg" ,path) ("long" "true")))) ;; STRING [:BOOLEAN :NUMBER :STRING] → NIL || (NIL STRING) (defun files-mkdir (path &key (parents nil) (cid-version nil) (hash nil)) -- 2.46.0 From 63ab3308687649b0fb7c0882872d9167a9142266 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Tue, 27 Sep 2022 17:06:41 +0200 Subject: [PATCH 6/6] Fix files-rm. --- main.lisp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.lisp b/main.lisp index b1611fb..6af98af 100644 --- a/main.lisp +++ b/main.lisp @@ -522,8 +522,8 @@ (defun files-rm (path &key (recursive nil) (force nil)) "Remove a given file. /ipns/docs.ipfs.io/reference/api/http/#api-v0-files-rm" - (ipfs-call "files/read" `(("arg" ,source) ("recursive" ,recursive) - ("force" ,force)))) + (ipfs-call "files/rm" `(("arg" ,path) ("recursive" ,recursive) + ("force" ,force)))) ;; STRING → ALIST || (NIL STRING) (defun files-stat (path) -- 2.46.0