Better handling of options in buckets listing

This commit is contained in:
Lucien Cartier-Tilet 2022-07-13 18:54:36 +02:00
parent c407cea0e8
commit 7bee6dcc04
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
1 changed files with 13 additions and 9 deletions

View File

@ -324,15 +324,19 @@ acquired JSON. Otherwise, return nil and warn the user."
(setq payload (append payload `(limit ,limit))) (setq payload (append payload `(limit ,limit)))
(when offset (setq payload (append payload `(offset ,offset)))) (when offset (setq payload (append payload `(offset ,offset))))
(when cursor (setq payload (append payload `(cursor ,cursor)))) (when cursor (setq payload (append payload `(cursor ,cursor))))
(when cursor-direction (setq payload (append payload `(cursor-direction ,cursor-direction)))) (when-let ((direction (pcase cursor-direction
(when order-type (setq payload (append payload `(order-type ,order-type)))) ('before "before")
(let* ((response (appwrite--query-api :api "/v1/storage/buckets" ('after "after")
:payload (json-encode-plist payload))) (_ nil))))
(status (car response)) (setq payload (append payload `(cursorDirection ,direction))))
(json (cdr response))) (when-let ((order (pcase order-type
(if (eq 200 status) ('ascending "ASC")
json ('descending "DESC")
(appwrite--message-failure "Failed to list buckets" 200 (gethash "message" json)))))) (_ nil))))
(setq payload (append payload `(orderType ,order))))
(let ((response (appwrite--query-api :api "/v1/storage/buckets"
:payload (json-encode-plist payload))))
(appwrite--process-response "Failed to list buckets" 200 response))))
(defun appwrite-storage-get-bucket (id) (defun appwrite-storage-get-bucket (id)
"Get bucket with id ID." "Get bucket with id ID."