mirror of
https://github.com/heyarne/airsonic-ui.git
synced 2026-05-07 02:33:39 +02:00
Handle events via UI instead of just the REPL
This commit is contained in:
parent
d782b49b94
commit
afe5b4015f
2 changed files with 37 additions and 19 deletions
|
|
@ -18,27 +18,40 @@
|
|||
(string/join "&"))]
|
||||
(str config/server "/rest/" endpoint "?" query)))
|
||||
|
||||
(defn api-error?
|
||||
"We need to look at the message body because the subsonic api always responds
|
||||
with status 200"
|
||||
[response]
|
||||
(= "failed" (-> response :subsonic-response :status)))
|
||||
|
||||
(defn error-message
|
||||
[response]
|
||||
(let [{:keys [code message]} (-> response :subsonic-response :error)]
|
||||
(str "Code " code ": " message)))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::authenticate
|
||||
(fn [{:keys [db]} [_ {:keys [user pass]}]]
|
||||
(fn [{:keys [db]} [_ user pass]]
|
||||
{:db (update db :active-requests inc)
|
||||
:http-xhrio {:method :get
|
||||
:uri (api-url "ping" {:u user :p pass})
|
||||
:response-format (ajax/text-response-format)
|
||||
:response-format (ajax/json-response-format {:keywords? true})
|
||||
:on-success [::auth-successful user pass]
|
||||
:on-failure [::auth-gone-bad]}}))
|
||||
:on-failure [::api-failure]}}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::auth-successful
|
||||
(fn [db [_ user pass]]
|
||||
(fn [db [_ user pass response]]
|
||||
;; TODO: Handle failures differently
|
||||
(-> (update db :active-requests dec)
|
||||
(assoc :login {:u user
|
||||
:p pass}))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::auth-gone-bad
|
||||
::api-failure
|
||||
(fn [db event]
|
||||
(println "auth gone bad" event)))
|
||||
(println "api call gone bad; CORS headers missing? check for :status 0" event)
|
||||
db))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::initialize-db
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue