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

View File

@ -14,7 +14,8 @@
<PackageReference Include="Microsoft.FSharpLu.Json" Version="0.11.7" /> <PackageReference Include="Microsoft.FSharpLu.Json" Version="0.11.7" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="RethinkDb.Driver" Version="2.3.150" /> <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>
<ItemGroup> <ItemGroup>

View File

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

View File

@ -62,16 +62,31 @@ module private Helpers =
open System.Security.Claims open System.Security.Claims
open System.IO 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 /// Add a message to the user's session
let addMessage (ctx : HttpContext) message = task { 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 -> [] let msg = match ctx.Session.Get<UserMessage list> "messages" with Some it -> it | None -> []
ctx.Session.Set ("messages", message :: msg) ctx.Session.Set ("messages", message :: msg)
} }
/// Get any messages from the user's session, removing them in the process /// Get any messages from the user's session, removing them in the process
let messages (ctx : HttpContext) = task { let messages (ctx : HttpContext) = task {
do! ctx.Session.LoadAsync () do! loadSession ctx
match ctx.Session.Get<UserMessage list> "messages" with match ctx.Session.Get<UserMessage list> "messages" with
| Some msg -> | Some msg ->
ctx.Session.Remove "messages" ctx.Session.Remove "messages"
@ -98,7 +113,7 @@ module private Helpers =
hash.Add ("current_page", ctx.Request.Path.Value.Substring 1) hash.Add ("current_page", ctx.Request.Path.Value.Substring 1)
hash.Add ("messages", messages) 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 // 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 // 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 /// Redirect after doing some action; commits session and issues a temporary redirect
let redirectToGet url : HttpHandler = fun next ctx -> task { let redirectToGet url : HttpHandler = fun next ctx -> task {
do! ctx.Session.CommitAsync () do! commitSession ctx
return! redirectTo false url next ctx return! redirectTo false url next ctx
} }

View File

@ -16,7 +16,8 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="DotLiquid" Version="2.2.610" /> <PackageReference Include="DotLiquid" Version="2.2.610" />
<PackageReference Include="Giraffe" Version="6.0.0" /> <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>
<ItemGroup> <ItemGroup>

View File

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

View File

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

View File

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