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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165module Sources.Services.Google.Marker exposing (..)
{-| Custom `Marker` for the Google Drive API.
The Google Drive API currently doesn't make a recursive list,so we have to manage that ourselves.
This custom marker is a combination of:
- The standard `nextPageToken` param - 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, token : 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
itemDirectory : MarkerItem -> StringitemDirectory item = case item of Directory dir -> dir
Param { directory } -> directory
itemToString : MarkerItem -> StringitemToString item = case item of Directory d -> "dir" ++ prefixer ++ d
Param { directory, token } -> "par" ++ prefixer ++ directory ++ paramSeparator ++ token
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, tok ] -> Just (Param { directory = dir, token = tok })
_ -> Nothing )
_ -> Nothing