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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136module Sources.Services.WebDav.Parser exposing (..)
import Maybe.Extra as Maybeimport Sources.Pick exposing (isMusicFile)import Sources.Processing exposing (Marker, TreeAnswer)import Sources.Services.Ipfs.Marker as Markerimport String.Ext as Stringimport Urlimport Xml.Decode exposing (..)import XmlParser
-- TREE
parseTreeResponse : String -> Marker -> TreeAnswer MarkerparseTreeResponse response previousMarker = let currentDir = Maybe.withDefault "//" (Marker.takeOne previousMarker)
parseResult = XmlParser.parse response
namespace = parseResult |> Result.map (\xml -> case xml.root of XmlParser.Element nodeName _ _ -> nodeName |> String.split ":" |> List.head
_ -> Nothing ) |> Result.withDefault Nothing |> (\maybe -> case maybe of Just n -> n ++ ":"
Nothing -> if String.contains "<d:" response then "d:"
else "D:" )
entries = response |> decodeString (treeDecoder namespace) |> Result.withDefault [] |> List.map Url.percentDecode |> Maybe.values |> List.filter ((/=) currentDir)
( dirs, files ) = List.partition (String.endsWith "/") entries in { filePaths = List.map (String.chopStart "/") files , marker = previousMarker |> Marker.removeOne |> Marker.concat dirs }
treeDecoder : String -> Decoder (List String)treeDecoder namespace = path [ namespace ++ "response" ] (leakyList <| treeItemDecoder namespace)
treeItemDecoder : String -> Decoder StringtreeItemDecoder namespace = let withNamespace = String.append namespace in string |> single |> path [ withNamespace "href" ] |> andThen (\href -> oneOf [ -- Audio -------- string |> single |> path [ withNamespace "propstat", withNamespace "prop", withNamespace "getcontenttype" ] |> andThen (mustBeAudio href) |> map (\_ -> href)
-- Directory ------------ , string |> single |> path [ withNamespace "propstat", withNamespace "prop", withNamespace "resourcetype", withNamespace "collection" ] |> andThen (\_ -> if String.endsWith "/@eaDir/" href then fail "Ignore Synology metadata"
else succeed href ) ] )
mustBeAudio : String -> String -> Decoder StringmustBeAudio href contentType = if isMusicFile href then succeed contentType
else if String.startsWith "audio/" contentType then succeed contentType
else fail "Ignore this, not an audio file"
-- ERROR
parseErrorResponse : String -> Maybe StringparseErrorResponse = Just