Skip to content

Commit

Permalink
Bumping version to 0.16.20
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Dec 16, 2018
1 parent 8eb8106 commit 6d72809
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 14 deletions.
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Client/ReleaseNotes.fs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
59 changes: 53 additions & 6 deletions src/Server/AzureTable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -126,16 +121,22 @@ 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


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
Expand All @@ -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
Expand Down Expand Up @@ -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 |]
}
23 changes: 18 additions & 5 deletions src/Server/Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -177,9 +179,6 @@ let firmwareEndpoint =
})
}




let tagHistoryBroadcaster = ConnectionManager()

let t = task {
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions src/Shared/Shared.fs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ type TagAction =
|> Decode.map TagAction.PlayBlobMusik
]

type Link = {
Token : string
Url : string
Order : int
}

type Tag =
{ Token : string
Object : string
Expand Down

0 comments on commit 6d72809

Please sign in to comment.