1
0
Fork 0
mirror of https://github.com/heyarne/airsonic-ui.git synced 2026-05-06 18:33:38 +02:00

Cleanup api interaction; also, not everybody is using my server ;)

This commit is contained in:
Arne Schlüter 2018-05-07 18:15:35 +02:00
commit 94d6c25d9e
4 changed files with 450 additions and 463 deletions

View file

@ -2,8 +2,8 @@
(:require [clojure.string :as str]
[airsonic-ui.config :as config]))
(defn ^:private uri-escape [s]
(js/encodeURIComponent s))
(defn- encode [c]
(js/encodeURIComponent c))
(defn url
"Returns an absolute url to an API endpoint"
@ -12,21 +12,20 @@
:f "json"
:c "airsonic-ui-cljs"
:v "1.15.0")
(map (fn [[k v]]
(str (uri-escape (name k)) "=" (uri-escape v))))
(map (fn [[k v]] (str (encode (name k)) "=" (encode v))))
(str/join "&"))]
(str server (when-not (str/ends-with? server "/") "/") "/rest/" endpoint "?" query)))
(str server (when-not (str/ends-with? server "/") "/") "rest/" endpoint "?" query)))
(defn song-url [server credentials song]
(url server "stream" (merge {:id (:id song)} credentials)))
(defn ^:private api-error?
(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 ^:private error-message
(defn- error-message
[response]
(let [{:keys [code message]} (-> response :subsonic-response :error)]
(str "Code " code ": " message)))

View file

@ -1,6 +1,4 @@
(ns airsonic-ui.config)
(def server "https://londe.arnes.space")
(def debug?
^boolean goog.DEBUG)