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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155module Sources.Services.Azure.FileMarker exposing (MarkerItem(..), concat, itemToString, paramSeparator, prefixer, removeOne, separator, stringToItem, takeOne)
{-| Custom `Marker` for the Azure File API.
The Azure File API currently doesn't make a recursive list,so we have to manage that ourselves.
This custom marker is a combination of:
- The default `marker` param, see URI parameters at <https://docs.microsoft.com/en-us/rest/api/storageservices/list-directories-and-files> - Our custom logic to handle recursive listings
Example: InProgress "dir=example ¶ param=defaultMarker"
-}
import Sources.Processing exposing (Marker(..))
type MarkerItem = Directory String | Param { directory : String, marker : String }
separator : Stringseparator = " ɑ "
prefixer : Stringprefixer = " β "
paramSeparator : StringparamSeparator = " ɣ "
-- IN
concat : List MarkerItem -> Marker -> Markerconcat list marker = let listStringified = List.map itemToString list
result = case marker of InProgress m -> [ listStringified, String.split separator m ] |> List.concat |> String.join separator
_ -> String.join separator listStringified in case result of "" -> TheEnd
r -> InProgress r
-- OUT
{-| Take the first item and return it.-}takeOne : Marker -> Maybe MarkerItemtakeOne marker = case marker of InProgress m -> m |> String.split separator |> List.head |> Maybe.andThen stringToItem
_ -> Nothing
{-| Remove the first item if there is one.-}removeOne : Marker -> MarkerremoveOne marker = case marker of InProgress m -> let tmp = m |> String.split separator |> List.drop 1 |> String.join separator in case tmp of "" -> TheEnd
x -> InProgress x
_ -> TheEnd
-- CONVERSIONS
itemToString : MarkerItem -> StringitemToString item = case item of Directory d -> "dir" ++ prefixer ++ d
Param { directory, marker } -> "par" ++ prefixer ++ directory ++ paramSeparator ++ marker
stringToItem : String -> Maybe MarkerItemstringToItem string = let exploded = String.split prefixer string in case List.head exploded of Just "dir" -> exploded |> List.drop 1 |> String.join prefixer |> Directory |> Just
Just "par" -> exploded |> List.drop 1 |> String.join prefixer |> String.split paramSeparator |> (\x -> case x of [ dir, mar ] -> Just (Param { directory = dir, marker = mar })
_ -> Nothing )
_ -> Nothing