A music player that connects to your cloud/distributed storage. diffuse.sh
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105module Sources.Services.Azure.FileParser exposing (parseErrorResponse, parseTreeResponse)
import Dict.Ext as Dictimport Sources.Processing exposing (Marker(..), TreeAnswer)import Sources.Services.Azure.BlobParserimport Sources.Services.Azure.FileMarker as FileMarker exposing (MarkerItem(..))import Sources.Services.Common exposing (cleanPath)import Xml.Decode exposing (..)
-- TREE
parseTreeResponse : String -> Marker -> TreeAnswer MarkerparseTreeResponse response previousMarker = response |> decodeString (treeDecoder previousMarker) |> Result.withDefault { filePaths = [], marker = TheEnd }
treeDecoder : Marker -> Decoder (TreeAnswer Marker)treeDecoder previousMarker = usedDirectoryDecoder |> map cleanPath |> andThen (\usedDirectory -> map2 (\a b -> ( usedDirectory, a, b )) (map (List.map <| String.append usedDirectory) filePathsDecoder) (map (List.map <| String.append usedDirectory) directoryPathsDecoder) ) |> andThen (\( usedDirectory, filePaths, directoryPaths ) -> previousMarker |> FileMarker.removeOne |> FileMarker.concat (List.map Directory directoryPaths) |> markerDecoder usedDirectory |> map (\marker -> { filePaths = filePaths, marker = marker }) )
usedDirectoryDecoder : Decoder StringusedDirectoryDecoder = stringAttr "DirectoryPath"
filePathsDecoder : Decoder (List String)filePathsDecoder = string |> single |> path [ "Name" ] |> list |> path [ "Entries", "File" ]
directoryPathsDecoder : Decoder (List String)directoryPathsDecoder = string |> single |> path [ "Name" ] |> list |> path [ "Entries", "Directory" ]
markerDecoder : String -> Marker -> Decoder MarkermarkerDecoder usedDirectory markerWithDirectories = map (\maybeNextMarker -> case maybeNextMarker of Just "" -> markerWithDirectories
Just marker -> FileMarker.concat [ Param { directory = usedDirectory, marker = marker } ] markerWithDirectories
Nothing -> markerWithDirectories ) (maybe <| path [ "NextMarker" ] <| single string)
-- ERROR
parseErrorResponse : String -> StringparseErrorResponse response = response |> decodeString errorMessagesDecoder |> Result.toMaybe |> Maybe.andThen List.head |> Maybe.withDefault "Invalid request"
errorMessagesDecoder : Decoder (List String)errorMessagesDecoder = string |> single |> path [ "Message" ] |> list |> path [ "Error" ]