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

892
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -14,7 +14,7 @@
"create-react-class": "^15.6.3", "create-react-class": "^15.6.3",
"react": "^16.3.2", "react": "^16.3.2",
"react-dom": "^16.3.2", "react-dom": "^16.3.2",
"shadow-cljs": "^2.3.0" "shadow-cljs": "^2.3.19"
}, },
"devDependencies": { "devDependencies": {
"react-flip-move": "^3.0.1", "react-flip-move": "^3.0.1",

View file

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

View file

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