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

Give user the ability to change the server url on login

This commit is contained in:
Arne Schlüter 2018-04-25 13:40:17 +02:00
commit 00e2cf656c
3 changed files with 34 additions and 18 deletions

View file

@ -1,5 +1,5 @@
(ns airsonic-ui.api
(:require [clojure.string :as string]
(:require [clojure.string :as str]
[airsonic-ui.config :as config]))
(defn ^:private uri-escape [s]
@ -7,15 +7,18 @@
(defn url
"Returns an absolute url to an API endpoint"
[endpoint params]
[server endpoint params]
(let [query (->> (assoc params
:f "json"
:c "airsonic-ui-cljs"
:v "1.15.0")
(map (fn [[k v]]
(str (uri-escape (name k)) "=" (uri-escape v))))
(string/join "&"))]
(str config/server "/rest/" endpoint "?" query)))
(str/join "&"))]
(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?
"We need to look at the message body because the subsonic api always responds