V2 #1

Merged
danieljsummers merged 102 commits from v2 into main 2022-06-23 00:35:12 +00:00
8 changed files with 44 additions and 26 deletions
Showing only changes of commit e8b903b33b - Show all commits

View File

@ -173,7 +173,7 @@ module Page =
rethink<Page list> {
withTable Table.Page
getAll [ webLogId ] (nameof webLogId)
without [ "text", "priorPermalinks", "revisions" ]
without [ "text"; "priorPermalinks"; "revisions" ]
result; withRetryDefault
}
@ -182,7 +182,7 @@ module Page =
rethink<Page> {
withTable Table.Page
get pageId
resultOption; withRetryDefault
resultOption; withRetryOptionDefault
}
|> verifyWebLog webLogId (fun it -> it.webLogId)
@ -191,8 +191,8 @@ module Page =
rethink<Page> {
withTable Table.Page
get pageId
without [ "priorPermalinks", "revisions" ]
resultOption; withRetryDefault
without [ "priorPermalinks"; "revisions" ]
resultOption; withRetryOptionDefault
}
|> verifyWebLog webLogId (fun it -> it.webLogId)
@ -201,7 +201,7 @@ module Page =
rethink<Page list> {
withTable Table.Page
getAll [ r.Array (webLogId, permalink) ] (nameof permalink)
without [ "priorPermalinks", "revisions" ]
without [ "priorPermalinks"; "revisions" ]
limit 1
result; withRetryDefault
}
@ -212,7 +212,7 @@ module Page =
rethink<Permalink list> {
withTable Table.Page
getAll [ permalink ] "priorPermalinks"
filter [ "webLogId", webLogId :> obj ]
filter "webLogId" webLogId
pluck [ "permalink" ]
limit 1
result; withRetryDefault
@ -225,7 +225,7 @@ module Page =
withTable Table.Page
getAll [ webLogId ] (nameof webLogId)
filter [ "showInPageList", true :> obj ]
without [ "text", "priorPermalinks", "revisions" ]
without [ "text"; "priorPermalinks"; "revisions" ]
orderBy "title"
result; withRetryDefault
}
@ -235,7 +235,7 @@ module Page =
rethink<Page list> {
withTable Table.Page
getAll [ webLogId ] (nameof webLogId)
without [ "priorPermalinks", "revisions" ]
without [ "priorPermalinks"; "revisions" ]
orderBy "title"
skip ((pageNbr - 1) * 25)
limit 25
@ -248,7 +248,7 @@ module Page =
withTable Table.Page
get page.id
update [
"title", page.title
"title", page.title :> obj
"permalink", page.permalink
"updatedOn", page.updatedOn
"showInPageList", page.showInPageList
@ -277,7 +277,7 @@ module Post =
rethink<Post list> {
withTable Table.Post
getAll [ r.Array(permalink, webLogId) ] (nameof permalink)
without [ "priorPermalinks", "revisions" ]
without [ "priorPermalinks"; "revisions" ]
limit 1
result; withRetryDefault
}
@ -288,7 +288,7 @@ module Post =
rethink<Permalink list> {
withTable Table.Post
getAll [ permalink ] "priorPermalinks"
filter [ "webLogId", webLogId :> obj ]
filter "webLogId" webLogId
pluck [ "permalink" ]
limit 1
result; withRetryDefault
@ -301,7 +301,7 @@ module Post =
withTable Table.Post
getAll [ webLogId ] (nameof webLogId)
filter "status" Published
without [ "priorPermalinks", "revisions" ]
without [ "priorPermalinks"; "revisions" ]
orderBy "publishedOn"
skip ((pageNbr - 1) * postsPerPage)
limit postsPerPage
@ -335,7 +335,7 @@ module WebLog =
rethink<WebLog> {
withTable Table.WebLog
get webLogId
resultOption; withRetryDefault
resultOption; withRetryOptionDefault
}
/// Update web log settings
@ -344,7 +344,7 @@ module WebLog =
withTable Table.WebLog
get webLog.id
update [
"name", webLog.name
"name", webLog.name :> obj
"subtitle", webLog.subtitle
"defaultPage", webLog.defaultPage
"postsPerPage", webLog.postsPerPage

View File

@ -14,7 +14,8 @@
<PackageReference Include="Microsoft.FSharpLu.Json" Version="0.11.7" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="RethinkDb.Driver" Version="2.3.150" />
<PackageReference Include="RethinkDb.Driver.FSharp" Version="0.8.0-alpha-0004" />
<PackageReference Include="RethinkDb.Driver.FSharp" Version="0.8.0-alpha-0007" />
<PackageReference Update="FSharp.Core" Version="6.0.3" />
</ItemGroup>
<ItemGroup>

View File

@ -13,6 +13,7 @@
<ItemGroup>
<PackageReference Include="Markdig" Version="0.28.1" />
<PackageReference Update="FSharp.Core" Version="6.0.3" />
</ItemGroup>
</Project>

View File

@ -62,16 +62,31 @@ module private Helpers =
open System.Security.Claims
open System.IO
/// The HTTP item key for loading the session
let private sessionLoadedKey = "session-loaded"
/// Load the session if it has not been loaded already; ensures async access but not excessive loading
let private loadSession (ctx : HttpContext) = task {
if not (ctx.Items.ContainsKey sessionLoadedKey) then
do! ctx.Session.LoadAsync ()
ctx.Items.Add (sessionLoadedKey, "yes")
}
/// Ensure that the session is committed
let private commitSession (ctx : HttpContext) = task {
if ctx.Items.ContainsKey sessionLoadedKey then do! ctx.Session.CommitAsync ()
}
/// Add a message to the user's session
let addMessage (ctx : HttpContext) message = task {
do! ctx.Session.LoadAsync ()
do! loadSession ctx
let msg = match ctx.Session.Get<UserMessage list> "messages" with Some it -> it | None -> []
ctx.Session.Set ("messages", message :: msg)
}
/// Get any messages from the user's session, removing them in the process
let messages (ctx : HttpContext) = task {
do! ctx.Session.LoadAsync ()
do! loadSession ctx
match ctx.Session.Get<UserMessage list> "messages" with
| Some msg ->
ctx.Session.Remove "messages"
@ -98,7 +113,7 @@ module private Helpers =
hash.Add ("current_page", ctx.Request.Path.Value.Substring 1)
hash.Add ("messages", messages)
do! ctx.Session.CommitAsync ()
do! commitSession ctx
// NOTE: DotLiquid does not support {% render %} or {% include %} in its templates, so we will do a two-pass
// render; the net effect is a "layout" capability similar to Razor or Pug
@ -120,7 +135,7 @@ module private Helpers =
/// Redirect after doing some action; commits session and issues a temporary redirect
let redirectToGet url : HttpHandler = fun next ctx -> task {
do! ctx.Session.CommitAsync ()
do! commitSession ctx
return! redirectTo false url next ctx
}

View File

@ -16,7 +16,8 @@
<ItemGroup>
<PackageReference Include="DotLiquid" Version="2.2.610" />
<PackageReference Include="Giraffe" Version="6.0.0" />
<PackageReference Include="RethinkDB.DistributedCache" Version="0.9.0-alpha03" />
<PackageReference Include="RethinkDB.DistributedCache" Version="0.9.0-alpha05" />
<PackageReference Update="FSharp.Core" Version="6.0.3" />
</ItemGroup>
<ItemGroup>

View File

@ -179,9 +179,9 @@ let main args =
} |> Async.AwaitTask |> Async.RunSynchronously
let _ = builder.Services.AddSingleton<IConnection> conn
// let _ = builder.Services.AddDistributedRethinkDBCache (fun opts ->
// opts.Connection <- conn)
let _ = builder.Services.AddDistributedMemoryCache ()
let _ = builder.Services.AddDistributedRethinkDBCache (fun opts ->
opts.TableName <- "Session"
opts.Connection <- conn)
let _ = builder.Services.AddSession(fun opts ->
opts.IdleTimeout <- TimeSpan.FromMinutes 30
opts.Cookie.HttpOnly <- true

View File

@ -45,7 +45,7 @@
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
{% if msg.detail %}
<hr>
<p>{{ msg.detail.value }}</p>
{{ msg.detail.value }}
{% endif %}
</div>
{% endfor %}

View File

@ -18,9 +18,9 @@
<small>
<a href="/{% unless pg.is_default %}{{ pg.permalink }}{% endunless %}" target="_blank">View Page</a>
<span class="text-muted"> &bull; </span>
<a href="/page/{{ pg.id }}/edit">Edit Page</a>
<a href="/page/{{ pg.id }}/edit">Edit</a>
<span class="text-muted"> &bull; </span>
<a href="#" class="text-danger">Delete Page</a>
<a href="#" class="text-danger">Delete</a>
</small>
</td>
<td>{{ pg.updated_on | date: "MMMM d, yyyy" }}</td>