From 32dafa3eab1ed83727412576c3ffb1cbcea1a4c9 Mon Sep 17 00:00:00 2001 From: Steven Vandevelde Date: Mon, 18 Nov 2024 23:35:30 +0100 Subject: [PATCH] fix: Prefer file extension over mime type in WebDAV sources + ignore Synology metadata --- Justfile | 2 +- .../Sources/Services/WebDav/Parser.elm | 61 ++++++++++++------- 2 files changed, 39 insertions(+), 24 deletions(-) diff --git a/Justfile b/Justfile index 3cf21c47..86bb684f 100644 --- a/Justfile +++ b/Justfile @@ -226,7 +226,7 @@ js-prod: @watch-elm: - watchexec -p -w {{SRC_DIR}} -e elm -- just elm css + watchexec -p -w {{SRC_DIR}} -e elm -- just elm js css @watch-js: diff --git a/src/Library/Sources/Services/WebDav/Parser.elm b/src/Library/Sources/Services/WebDav/Parser.elm index e1b8a75c..8e2d359f 100644 --- a/src/Library/Sources/Services/WebDav/Parser.elm +++ b/src/Library/Sources/Services/WebDav/Parser.elm @@ -1,6 +1,7 @@ module Sources.Services.WebDav.Parser exposing (..) import Maybe.Extra as Maybe +import Sources.Pick exposing (isMusicFile) import Sources.Processing exposing (Marker, TreeAnswer) import Sources.Services.Ipfs.Marker as Marker import String.Ext as String @@ -82,29 +83,43 @@ treeItemDecoder namespace = withNamespace = String.append namespace in - map2 - (\_ h -> h) - (oneOf - [ -- Audio - -------- - string - |> single - |> path [ withNamespace "propstat", withNamespace "prop", withNamespace "getcontenttype" ] - |> andThen mustBeAudio - - -- Directory - ------------ - , string - |> single - |> path [ withNamespace "propstat", withNamespace "prop", withNamespace "resourcetype", withNamespace "collection" ] - ] - ) - (path [ withNamespace "href" ] (single string)) - - -mustBeAudio : String -> Decoder String -mustBeAudio contentType = - if String.startsWith "audio/" contentType then + 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 String +mustBeAudio href contentType = + if isMusicFile href then + succeed contentType + + else if String.startsWith "audio/" contentType then succeed contentType else -- 2.51.2