A music player that connects to your cloud/distributed storage. diffuse.sh
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173module Sources.Services.AzureFile exposing (defaults, initialData, makeTrackUrl, makeTree, parseErrorResponse, parsePreparationResponse, parseTreeResponse, postProcessTree, prepare, properties)
{-| Microsoft Azure File Service.
Resources:
- <https://docs.microsoft.com/en-us/rest/api/storageservices/file-service-rest-api>
-}
import Dictimport Httpimport Sources exposing (Property, SourceData)import Sources.Pickimport Sources.Processing exposing (..)import Sources.Services.Azure.Authorization exposing (..)import Sources.Services.Azure.FileMarker as FileMarker exposing (MarkerItem(..))import Sources.Services.Azure.FileParser as Parserimport Sources.Services.Common exposing (cleanPath, noPrep)import Time
-- PROPERTIES-- 📟
defaults = { directoryPath = "/" , name = "Music from Azure File Storage" }
{-| The list of properties we need from the user.
Tuple: (property, label, placeholder, isPassword)Will be used for the forms.
-}properties : List Propertyproperties = [ { key = "accountName" , label = "Account name" , placeholder = "myaccount" , password = False } , { key = "accountKey" , label = "Account key" , placeholder = "MXFPDkaN4KBT" , password = True } , { key = "container" , label = "Share name" , placeholder = "music" , password = False } , { key = "directoryPath" , label = "Directory (aka. Prefix)" , placeholder = defaults.directoryPath , password = False } ]
{-| Initial data set.-}initialData : SourceDatainitialData = Dict.fromList [ ( "accountName", "" ) , ( "accountKey", "" ) , ( "container", "" ) , ( "directoryPath", defaults.directoryPath ) , ( "name", defaults.name ) ]
-- PREPARATION
prepare : String -> SourceData -> Marker -> (Result Http.Error String -> msg) -> Maybe (Cmd msg)prepare _ _ _ _ = Nothing
-- TREE
{-| Create a directory tree.
List all the tracks in the container.Or a specific directory in the container.
-}makeTree : SourceData -> Marker -> Time.Posix -> (Result Http.Error String -> msg) -> Cmd msgmakeTree srcData marker currentTime toMsg = let directoryPathFromSrcData = srcData |> Dict.get "directoryPath" |> Maybe.withDefault defaults.directoryPath |> cleanPath
baseParams = [ ( "maxresults", "1000" ) ]
( directoryPath, params ) = case FileMarker.takeOne marker of Just (Directory directory) -> Tuple.pair directory []
Just (Param param) -> Tuple.pair param.directory [ ( "marker", param.marker ) ]
_ -> Tuple.pair directoryPathFromSrcData []
url = presignedUrl File List Get 1 currentTime srcData directoryPath (baseParams ++ params) in Http.get { url = url , expect = Http.expectString toMsg }
{-| Re-export parser functions.-}parsePreparationResponse : String -> SourceData -> Marker -> PrepationAnswer MarkerparsePreparationResponse = noPrep
parseTreeResponse : String -> Marker -> TreeAnswer MarkerparseTreeResponse = Parser.parseTreeResponse
parseErrorResponse : String -> StringparseErrorResponse = Parser.parseErrorResponse
-- POST
{-| Post process the tree results.
!!! Make sure we only use music files that we can use.
-}postProcessTree : List String -> List StringpostProcessTree = Sources.Pick.selectMusicFiles
-- TRACK URL
{-| Create a public url for a file.
We need this to play the track.(!) Creates a presigned url that's valid for 48 hours
-}makeTrackUrl : Time.Posix -> SourceData -> HttpMethod -> String -> StringmakeTrackUrl currentTime srcData method pathToFile = presignedUrl File Read Get 48 currentTime srcData pathToFile []