Something went wrong. Try again.
A music player that connects to your cloud/distributed storage. forked from tokono.ma/diffuse
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798module Common exposing (ServiceWorkerStatus(..), Switch(..), backToIndex, boolFromString, boolToString, queryString, translateHttpResponse, urlOrigin)
import Httpimport Tuple.Ext as Tupleimport Url exposing (Protocol(..), Url)import Url.Builder as Url
-- ⛩
backToIndex : StringbackToIndex = "Back to tracks"
-- 🌳
type ServiceWorkerStatus = InstallingInitial | InstallingNew | WaitingForActivation | Activated
type Switch = On | Off
-- 🔱
boolFromString : String -> BoolboolFromString string = case string of "t" -> True
_ -> False
boolToString : Bool -> StringboolToString bool = if bool then "t"
else "f"
queryString : List ( String, String ) -> StringqueryString = List.map (Tuple.uncurry Url.string) >> Url.toQuery
translateHttpResponse : Http.Response String -> Result Http.Error StringtranslateHttpResponse response = case response of Http.BadUrl_ u -> Err (Http.BadUrl u)
Http.Timeout_ -> Err Http.Timeout
Http.NetworkError_ -> Err Http.NetworkError
Http.BadStatus_ _ body -> Err (Http.BadBody body)
Http.GoodStatus_ _ body -> Ok body
urlOrigin : Url -> StringurlOrigin { host, port_, path, protocol } = let scheme = case protocol of Http -> "http://"
Https -> "https://"
thePort = port_ |> Maybe.map (String.fromInt >> (++) ":") |> Maybe.withDefault "" in scheme ++ host ++ thePort ++ path