A music player that connects to your cloud/distributed storage.
at main 3.3 kB view raw
1module Sources.Services.Azure.FileMarker exposing (MarkerItem(..), concat, itemToString, paramSeparator, prefixer, removeOne, separator, stringToItem, takeOne) 2 3{-| Custom `Marker` for the Azure File API. 4 5The Azure File API currently doesn't make a recursive list, 6so we have to manage that ourselves. 7 8This custom marker is a combination of: 9 10 - The default `marker` param, see URI parameters at <https://docs.microsoft.com/en-us/rest/api/storageservices/list-directories-and-files> 11 - Our custom logic to handle recursive listings 12 13Example: InProgress "dir=example param=defaultMarker" 14 15-} 16 17import Sources.Processing exposing (Marker(..)) 18 19 20type MarkerItem 21 = Directory String 22 | Param { directory : String, marker : String } 23 24 25separator : String 26separator = 27 " ɑ " 28 29 30prefixer : String 31prefixer = 32 " β " 33 34 35paramSeparator : String 36paramSeparator = 37 " ɣ " 38 39 40 41-- IN 42 43 44concat : List MarkerItem -> Marker -> Marker 45concat list marker = 46 let 47 listStringified = 48 List.map itemToString list 49 50 result = 51 case marker of 52 InProgress m -> 53 [ listStringified, String.split separator m ] 54 |> List.concat 55 |> String.join separator 56 57 _ -> 58 String.join separator listStringified 59 in 60 case result of 61 "" -> 62 TheEnd 63 64 r -> 65 InProgress r 66 67 68 69-- OUT 70 71 72{-| Take the first item and return it. 73-} 74takeOne : Marker -> Maybe MarkerItem 75takeOne marker = 76 case marker of 77 InProgress m -> 78 m 79 |> String.split separator 80 |> List.head 81 |> Maybe.andThen stringToItem 82 83 _ -> 84 Nothing 85 86 87{-| Remove the first item if there is one. 88-} 89removeOne : Marker -> Marker 90removeOne marker = 91 case marker of 92 InProgress m -> 93 let 94 tmp = 95 m 96 |> String.split separator 97 |> List.drop 1 98 |> String.join separator 99 in 100 case tmp of 101 "" -> 102 TheEnd 103 104 x -> 105 InProgress x 106 107 _ -> 108 TheEnd 109 110 111 112-- CONVERSIONS 113 114 115itemToString : MarkerItem -> String 116itemToString item = 117 case item of 118 Directory d -> 119 "dir" ++ prefixer ++ d 120 121 Param { directory, marker } -> 122 "par" ++ prefixer ++ directory ++ paramSeparator ++ marker 123 124 125stringToItem : String -> Maybe MarkerItem 126stringToItem string = 127 let 128 exploded = 129 String.split prefixer string 130 in 131 case List.head exploded of 132 Just "dir" -> 133 exploded 134 |> List.drop 1 135 |> String.join prefixer 136 |> Directory 137 |> Just 138 139 Just "par" -> 140 exploded 141 |> List.drop 1 142 |> String.join prefixer 143 |> String.split paramSeparator 144 |> (\x -> 145 case x of 146 [ dir, mar ] -> 147 Just (Param { directory = dir, marker = mar }) 148 149 _ -> 150 Nothing 151 ) 152 153 _ -> 154 Nothing