···11+module Sources.Services exposing (..)
22+33+{-| Service functions used in other modules.
44+-}
55+66+import Date exposing (Date)
77+import Sources.Types exposing (..)
88+99+1010+-- Services
1111+1212+import Sources.Services.AmazonS3 as AmazonS3
1313+import Sources.Services.Ipfs as Ipfs
1414+1515+1616+-- Functions implemented by services
1717+1818+1919+initialData : Service -> SourceData
2020+initialData service =
2121+ case service of
2222+ AmazonS3 ->
2323+ AmazonS3.initialData
2424+2525+ Ipfs ->
2626+ Ipfs.initialData
2727+2828+2929+makeTrackUrl : Service -> Date -> SourceData -> HttpMethod -> String -> String
3030+makeTrackUrl service =
3131+ case service of
3232+ AmazonS3 ->
3333+ AmazonS3.makeTrackUrl
3434+3535+ Ipfs ->
3636+ Ipfs.makeTrackUrl
3737+3838+3939+makeTree : Service -> SourceData -> Marker -> (TreeStepResult -> msg) -> Date -> Cmd msg
4040+makeTree service =
4141+ case service of
4242+ AmazonS3 ->
4343+ AmazonS3.makeTree
4444+4545+ Ipfs ->
4646+ Ipfs.makeTree
4747+4848+4949+parseErrorResponse : Service -> String -> String
5050+parseErrorResponse service =
5151+ case service of
5252+ AmazonS3 ->
5353+ AmazonS3.parseErrorResponse
5454+5555+ Ipfs ->
5656+ Ipfs.parseErrorResponse
5757+5858+5959+parseTreeResponse : Service -> String -> Marker -> ParsedResponse Marker
6060+parseTreeResponse service =
6161+ case service of
6262+ AmazonS3 ->
6363+ AmazonS3.parseTreeResponse
6464+6565+ Ipfs ->
6666+ Ipfs.parseTreeResponse
6767+6868+6969+postProcessTree : Service -> List String -> List String
7070+postProcessTree service =
7171+ case service of
7272+ AmazonS3 ->
7373+ AmazonS3.postProcessTree
7474+7575+ Ipfs ->
7676+ Ipfs.postProcessTree
7777+7878+7979+properties : Service -> List ( String, String, String, Bool )
8080+properties service =
8181+ case service of
8282+ AmazonS3 ->
8383+ AmazonS3.properties
8484+8585+ Ipfs ->
8686+ Ipfs.properties
8787+8888+8989+9090+-- Utility functions
9191+9292+9393+makeSource : Service -> SourceData -> Source
9494+makeSource service data =
9595+ { id = "change_me_please"
9696+ , data = data
9797+ , enabled = True
9898+ , service = service
9999+ }
100100+101101+102102+keyToType : String -> Service
103103+keyToType str =
104104+ case str of
105105+ "AmazonS3" ->
106106+ AmazonS3
107107+108108+ "Ipfs" ->
109109+ Ipfs
110110+111111+ _ ->
112112+ Debug.crash "Invalid Service type string"
113113+114114+115115+typeToKey : Service -> String
116116+typeToKey service =
117117+ case service of
118118+ AmazonS3 ->
119119+ "AmazonS3"
120120+121121+ Ipfs ->
122122+ "Ipfs"
123123+124124+125125+{-| Service labels.
126126+127127+Maps a service key to a label.
128128+129129+-}
130130+labels : List ( String, String )
131131+labels =
132132+ [ ( typeToKey AmazonS3, "Amazon S3" )
133133+ , ( typeToKey Ipfs, "IPFS" )
134134+ ]
+2-2
src/App/Sources/Services/AmazonS3.elm
···1212import Dict
1313import Http
1414import Regex
1515+import Sources.Pick
1516import Sources.Services.AmazonS3.Parser as Parser
1617import Sources.Services.AmazonS3.Presign exposing (..)
1718import Sources.Types exposing (..)
1818-import Sources.Utils
1919import Time
20202121···155155-}
156156postProcessTree : List String -> List String
157157postProcessTree =
158158- Sources.Utils.selectMusicFiles
158158+ Sources.Pick.selectMusicFiles
···1010import Response.Ext exposing (do)
1111import Sources.Ports as Ports
1212import Sources.Processing as Processing
1313+import Sources.Services as Services exposing (makeSource)
1314import Sources.Types exposing (..)
1415import Sources.Utils exposing (..)
1516import Tracks.Types exposing (emptyTrack)
1617import Types as TopLevel
1717-1818-1919--- Services
2020-2121-import Sources.Services.AmazonS3 as AmazonS3
2222-import Sources.Services.Ipfs as Ipfs
231824192520-- 💧
···42374338initialSource : Source
4439initialSource =
4545- makeSource AmazonS3 AmazonS3.initialData
4040+ makeSource AmazonS3 (Services.initialData AmazonS3)
464147424843···134129 [ Processing.takeTreeStep ctx resp associatedTracks model.timestamp ]
135130 []
136131132132+ --
133133+ -- Error
134134+ --
137135 ProcessTreeStep ctx (Err err) ->
138136 let
139137 publicError =
···145143 "Source did not respond (timeout)"
146144147145 BadStatus response ->
148148- Processing.decodeError ctx.source response.body
146146+ Services.parseErrorResponse ctx.source.service response.body
149147150148 _ ->
151149 toString err
···158156 [ do ProcessNextInLine ]
159157 []
160158159159+ --
160160+ -- Remove tracks
161161+ --
161162 ProcessTreeStepRemoveTracks sourceId filePaths ->
162163 ($)
163164 model
···212213 ------------------------------------
213214 -- Forms
214215 ------------------------------------
216216+ --
217217+ -- Set
218218+ --
215219 SetNewSourceProperty source key value ->
216220 let
217221 newSource =
···219223 in
220224 (!) { model | newSource = newSource } []
221225226226+ --
227227+ -- Change
228228+ --
222229 SetNewSourceType typeString ->
223230 let
224224- newSource =
225225- case typeString of
226226- "AmazonS3" ->
227227- makeSource AmazonS3 AmazonS3.initialData
228228-229229- "Ipfs" ->
230230- makeSource Ipfs Ipfs.initialData
231231+ service =
232232+ Services.keyToType typeString
231233232232- _ ->
233233- initialSource
234234+ newSource =
235235+ makeSource service (Services.initialData service)
234236 in
235237 (!) { model | newSource = newSource } []
236238239239+ --
240240+ -- Submit
241241+ --
237242 SubmitNewSourceForm ->
238243 let
239244 ns =
···243248 { ns | data = Dict.map (always String.trim) ns.data }
244249245250 newCollection =
246246- setProperSourceId model newSource :: model.collection
251251+ (setProperSourceId model newSource) :: model.collection
247252 in
248253 ($)
249254 { model
-13
src/App/Sources/Types.elm
···120120type Page
121121 = Index
122122 | New
123123-124124-125125-126126--- 🌱
127127-128128-129129-makeSource : Service -> SourceData -> Source
130130-makeSource service data =
131131- { id = "change_me_please"
132132- , data = data
133133- , enabled = True
134134- , service = service
135135- }