diff options
author | Colin Okay <cbeok@protonmail.com> | 2020-04-12 11:59:13 -0500 |
---|---|---|
committer | Colin Okay <cbeok@protonmail.com> | 2020-04-12 11:59:13 -0500 |
commit | af85b3ae5b11b68cd0bad553041f67915fbea20b (patch) | |
tree | b10ed894406964aa97e9723120360882b9f631f2 | |
parent | e01d232cf291c056fede8c7a08ecc589edf57ae8 (diff) |
added upload
-rw-r--r-- | granolin.asd | 2 | ||||
-rw-r--r-- | granolin.lisp | 25 | ||||
-rw-r--r-- | package.lisp | 1 |
3 files changed, 27 insertions, 1 deletions
diff --git a/granolin.asd b/granolin.asd index 3b56330..35fb34e 100644 --- a/granolin.asd +++ b/granolin.asd @@ -2,7 +2,7 @@ (asdf:defsystem #:granolin :description "Lisp learns how to spam Matrix servers." - :author "thegoofist@protonmail.com" + :author "cbeok@protonmail.com" :license "AGPLv3.0" :version "0.0.1" :serial t diff --git a/granolin.lisp b/granolin.lisp index 64ba2e0..561aa0e 100644 --- a/granolin.lisp +++ b/granolin.lisp @@ -207,6 +207,7 @@ (defparameter +text-message-path+ "/_matrix/client/r0/rooms/~a/send/m.room.message/~a") (defparameter +create-room-path+ "/_matrix/client/r0/createRoom") (defparameter +update-account-data-path+ "/_matrix/client/r0/user/~a/account_data/~a") +(defparameter +upload-path+ "/_matrix/media/r0/upload?filename=~a") ;;; Utility functions and macros for making HTTP requests to the MATRIX API @@ -446,6 +447,30 @@ *response-status* (flexi-streams:octets-to-string *response-body*))))) +(defun upload (client filename content &key (content-type "application/image")) + "Uploads a file to the homeserver's media storage. + + It returns the MXC URI to the uploaded content. + + FILENAME is a string passed into the query parameters of the request URI. + + CONTENT can be a string, a sequence of octets, a pathname, an open + binary input stream, or a function designator. It is passed + directly to the :content keyword parameter of + drakma:http-request. + + See https://edicl.github.io/drakma/#http-request for more. " + (let ((url (format nil +upload-path+ filename))) + (send (client url content + :method :post + :content-type content-type + :wrap make-basic-json + :literal-body t) + (getf (basic-json-data *response-object*) :|content_uri|) + (format *error-output* "FAILED to upload content.~%HTTP response: ~a ~a~%" + *response-status* + (flexi-streams:octets-to-string *response-body*))))) + (defun update-account-data (client m-type data) "Serializes the PLIST DATA as JSON and PUTs it in account_data at the given M-TYPE. diff --git a/package.lisp b/package.lisp index 0368c9c..c5f2414 100644 --- a/package.lisp +++ b/package.lisp @@ -83,6 +83,7 @@ #:send-text-message #:join-room #:create-direct-message-room + #:upload ;; bot control #:start |