A music player that connects to your cloud/distributed storage.
1module Sources exposing (..)
2
3import Conditional exposing (..)
4import Dict exposing (Dict)
5import Json.Decode
6import Time
7
8
9
10-- 🌳
11
12
13type alias Source =
14 { id : String
15 , data : SourceData
16 , directoryPlaylists : Bool
17 , enabled : Bool
18 , service : Service
19 }
20
21
22
23-- PIECES
24
25
26type alias Property =
27 { key : String
28 , label : String
29 , placeholder : String
30 , password : Bool
31 }
32
33
34type alias SourceData =
35 Dict String String
36
37
38
39-- SERVICES
40
41
42type Service
43 = AmazonS3
44 | AzureBlob
45 | AzureFile
46 | Btfs
47 | Dropbox
48 | Google
49 | Ipfs
50 | WebDav
51
52
53serviceDictionary : Dict String Service
54serviceDictionary =
55 Dict.fromList
56 [ ( "amazons3", AmazonS3 )
57 , ( "amazon_s3", AmazonS3 )
58 , ( "azureblob", AzureBlob )
59 , ( "azure_blob", AzureBlob )
60 , ( "azurefile", AzureFile )
61 , ( "azure_file", AzureFile )
62 , ( "btfs", Btfs )
63 , ( "dropbox", Dropbox )
64 , ( "google", Google )
65 , ( "ipfs", Ipfs )
66 , ( "webdav", WebDav )
67 , ( "web_dav", WebDav )
68 ]
69
70
71serviceDecoder : Json.Decode.Decoder Service
72serviceDecoder =
73 Json.Decode.andThen
74 (\string ->
75 serviceDictionary
76 |> Dict.get string
77 |> Maybe.map Json.Decode.succeed
78 |> Maybe.withDefault (Json.Decode.fail "Invalid source kind")
79 )
80 Json.Decode.string
81
82
83
84--- 🔱
85
86
87enabledSourceIds : List Source -> List String
88enabledSourceIds =
89 List.filterMap (\s -> ifThenElse s.enabled (Just s.id) Nothing)
90
91
92setProperId : Int -> Time.Posix -> Source -> Source
93setProperId n time source =
94 { source | id = String.fromInt (Time.posixToMillis time) ++ String.fromInt n }
95
96
97worksOffline : Source -> Bool
98worksOffline source =
99 case source.service of
100 AmazonS3 ->
101 False
102
103 AzureBlob ->
104 False
105
106 AzureFile ->
107 False
108
109 Btfs ->
110 True
111
112 Dropbox ->
113 False
114
115 Google ->
116 False
117
118 Ipfs ->
119 True
120
121 WebDav ->
122 source.data
123 |> Dict.get "url"
124 |> Maybe.map (\u -> String.contains "localhost" u || String.contains "127.0.0.1" u)
125 |> Maybe.withDefault False