From 6d72809cd85c51dbd81f4731e484e636efb86317 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Sun, 16 Dec 2018 18:50:50 +0100 Subject: [PATCH] Bumping version to 0.16.20 --- RELEASE_NOTES.md | 2 +- src/Client/ReleaseNotes.fs | 4 +-- src/Server/AzureTable.fs | 59 ++++++++++++++++++++++++++++++++++---- src/Server/Server.fs | 23 +++++++++++---- src/Shared/Shared.fs | 6 ++++ 5 files changed, 80 insertions(+), 14 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 40f50c6..18208b3 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,6 +1,6 @@ # Release Notes -## 0.16.19 - 2018-12-15 +## 0.16.20 - 2018-12-15 * Update to ASP.NET 2.2 ## 0.15.11 - 2018-11-05 diff --git a/src/Client/ReleaseNotes.fs b/src/Client/ReleaseNotes.fs index 6ce6c2d..f7c9078 100644 --- a/src/Client/ReleaseNotes.fs +++ b/src/Client/ReleaseNotes.fs @@ -1,13 +1,13 @@ module internal ReleaseNotes -let Version = "0.16.19" +let Version = "0.16.20" let IsPrerelease = false let Notes = """ # Release Notes -## 0.16.19 - 2018-12-15 +## 0.16.20 - 2018-12-15 * Update to ASP.NET 2.2 ## 0.15.11 - 2018-11-05 diff --git a/src/Server/AzureTable.fs b/src/Server/AzureTable.fs index 469cf66..4c8673c 100644 --- a/src/Server/AzureTable.fs +++ b/src/Server/AzureTable.fs @@ -5,11 +5,6 @@ open Microsoft.WindowsAzure.Storage.Table open System.Threading.Tasks open FSharp.Control.Tasks.ContextInsensitive -type AzureConnection = - | AzureConnection of string - member this.Connect() = - match this with - | AzureConnection connectionString -> CloudStorageAccount.Parse connectionString let getTable tableName (connection: CloudStorageAccount) = async { @@ -126,9 +121,10 @@ let storageConnectionString = else str -let connection = (AzureConnection storageConnectionString).Connect() +let connection = CloudStorageAccount.Parse storageConnectionString let tagsTable = getTable "tags" connection +let linksTable = getTable "links" connection let requestsTable = getTable "requests" connection @@ -136,6 +132,11 @@ open ServerCore.Domain open Thoth.Json.Net +let mapLink (entity: DynamicTableEntity) : Link = + { Token = entity.PartitionKey + Order = int entity.RowKey + Url = getStringProperty "Url" entity } + let mapTag (entity: DynamicTableEntity) : Tag = { Token = entity.RowKey Description = getStringProperty "Description" entity @@ -156,6 +157,19 @@ let saveTag (userID:string) (tag:Tag) = let operation = TableOperation.InsertOrReplace entity tagsTable.ExecuteAsync operation + +let saveLinks (tag:Tag) (urls:string []) = + let batch = TableBatchOperation() + let mutable i = 0 + for url in urls do + let entity = DynamicTableEntity() + entity.PartitionKey <- tag.Token + entity.RowKey <- string i + entity.Properties.["Url"] <- EntityProperty.GeneratePropertyForString url + batch.InsertOrReplace entity + i <- i + 1 + tagsTable.ExecuteBatchAsync batch + let saveRequest (userID:string) (token:string) = let entity = DynamicTableEntity() entity.PartitionKey <- userID @@ -190,3 +204,36 @@ let getAllTagsForUser (userID:string) = task { return [| for result in results -> mapTag result |] } + +let getAllTags () = task { + let rec getResults token = task { + let! result = tagsTable.ExecuteQuerySegmentedAsync(TableQuery(), token) + let token = result.ContinuationToken + let result = result |> Seq.toList + if isNull token then + return result + else + let! others = getResults token + return result @ others } + + let! results = getResults null + + return [| for result in results -> mapTag result |] +} + +let getAllLinksForTag (tagToken:string) = task { + let rec getResults token = task { + let query = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, tagToken) + let! result = linksTable.ExecuteQuerySegmentedAsync(TableQuery(FilterString = query), token) + let token = result.ContinuationToken + let result = result |> Seq.toList + if isNull token then + return result + else + let! others = getResults token + return result @ others } + + let! results = getResults null + + return [| for result in results -> mapLink result |] +} \ No newline at end of file diff --git a/src/Server/Server.fs b/src/Server/Server.fs index acee620..6468809 100644 --- a/src/Server/Server.fs +++ b/src/Server/Server.fs @@ -13,6 +13,7 @@ open System.Threading.Tasks open Giraffe.WebSocket open Microsoft.AspNetCore.Builder open System.Diagnostics +open ServerCode.Storage.AzureTable #if DEBUG let publicPath = Path.GetFullPath "../Client/public" @@ -90,8 +91,9 @@ let discoverYoutubeLink (youtubeURL:string) = task { let mapYoutube (tag:Tag) = task { match tag.Action with - | TagAction.PlayYoutube url -> - let! _,links = discoverYoutubeLink url + | TagAction.PlayYoutube _ -> + let! links = getAllLinksForTag tag.Token + let links = links |> Array.map (fun l -> l.Url) return { tag with Action = TagAction.PlayMusik links } | _ -> return tag } @@ -177,9 +179,6 @@ let firmwareEndpoint = }) } - - - let tagHistoryBroadcaster = ConnectionManager() let t = task { @@ -218,4 +217,18 @@ let app = application { app_config configureApp } +let discoverTask = task { + while true do + let! tags = getAllTags() + for tag in tags do + match tag.Action with + | TagAction.PlayYoutube url -> + let! _,urls = discoverYoutubeLink url + let! _ = saveLinks tag urls + () + | _ -> () + do! Task.Delay (1000 * 60 * 20) + return () +} + run app diff --git a/src/Shared/Shared.fs b/src/Shared/Shared.fs index 19475ff..371f16e 100644 --- a/src/Shared/Shared.fs +++ b/src/Shared/Shared.fs @@ -66,6 +66,12 @@ type TagAction = |> Decode.map TagAction.PlayBlobMusik ] +type Link = { + Token : string + Url : string + Order : int +} + type Tag = { Token : string Object : string