Author SHA1 Message Date
gitea-actions[bot] da67467dd1 chore: update flake lock 2026-11-15 07:01:38 +00:00
gitea-actions[bot] ef3dab570b chore: update flake lock 2026-11-08 07:02:05 +00:00
47 changed files with 849 additions and 1753 deletions

No files matched your search

@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
"query": "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.body_gemtext, p.created_at, p.publish_date FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL ORDER BY p.view_count DESC LIMIT 3",
"query": "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.created_at, p.publish_date FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL ORDER BY p.created_at DESC LIMIT 10",
"describe": {
"columns": [
{
@@ -35,16 +35,11 @@
},
{
"ordinal": 6,
"name": "body_gemtext",
"type_info": "Text"
},
{
"ordinal": 7,
"name": "created_at",
"type_info": "Timestamptz"
},
{
"ordinal": 8,
"ordinal": 7,
"name": "publish_date",
"type_info": "Timestamptz"
}
@@ -60,9 +55,8 @@
false,
false,
true,
true,
true
]
},
"hash": "7998c2354eacb1cfbeece7dc001f57e0ce4d3ca15b28940a631cd249b72d6dc3"
"hash": "053f5b53a743065aa0105903cdd0ec803861a2477c38a02754d2d350a34aaa68"
}
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
"query": "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.body_gemtext, p.created_at, p.publish_date, p.is_featured FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL AND p.post_id = $1 ORDER BY p.created_at DESC",
"query": "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.created_at, p.publish_date, p.is_featured FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL AND p.post_id = $1 ORDER BY p.created_at DESC",
"describe": {
"columns": [
{
@@ -35,21 +35,16 @@
},
{
"ordinal": 6,
"name": "body_gemtext",
"type_info": "Text"
},
{
"ordinal": 7,
"name": "created_at",
"type_info": "Timestamptz"
},
{
"ordinal": 8,
"ordinal": 7,
"name": "publish_date",
"type_info": "Timestamptz"
},
{
"ordinal": 9,
"ordinal": 8,
"name": "is_featured",
"type_info": "Bool"
}
@@ -68,9 +63,8 @@
false,
true,
true,
true,
false
]
},
"hash": "fb4bcc2eb710ceb4bb50ec1c62326b7d709cd53d44944acc2da2e371642bfe1a"
"hash": "0891ec97ff1d5d5ab7fbc848ceb4e7ea4f46e2f6282170dfdf90ebc6ab6d5fd9"
}
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
"query": "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.body_gemtext, p.created_at, p.publish_date FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL ORDER BY p.created_at DESC LIMIT 10",
"query": "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.created_at, p.publish_date FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL GROUP BY p.post_id, a.first_name, a.last_name ORDER BY p.created_at DESC LIMIT 3",
"describe": {
"columns": [
{
@@ -35,16 +35,11 @@
},
{
"ordinal": 6,
"name": "body_gemtext",
"type_info": "Text"
},
{
"ordinal": 7,
"name": "created_at",
"type_info": "Timestamptz"
},
{
"ordinal": 8,
"ordinal": 7,
"name": "publish_date",
"type_info": "Timestamptz"
}
@@ -60,9 +55,8 @@
false,
false,
true,
true,
true
]
},
"hash": "9cc954af48cf92abaa30a8d26499fded1ce30609c29b34d10cf98573d40bdbb6"
"hash": "0ec6c9d94fceba56112e78c82acc56ae01bc3c641e28ee21e331c06e2fd9e551"
}
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
"query": "SELECT p.post_id, a.first_name, a.last_name, p.title, p.body, p.body_gemtext, p.created_at, p.publish_date, a.author_id FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL AND p.author_id = $1 ORDER BY created_at DESC LIMIT $2 OFFSET $3",
"query": "SELECT p.post_id, a.first_name, a.last_name, p.title, p.body, p.created_at, p.publish_date, a.author_id FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL AND p.author_id = $1 ORDER BY created_at DESC LIMIT $2 OFFSET $3",
"describe": {
"columns": [
{
@@ -30,21 +30,16 @@
},
{
"ordinal": 5,
"name": "body_gemtext",
"type_info": "Text"
},
{
"ordinal": 6,
"name": "created_at",
"type_info": "Timestamptz"
},
{
"ordinal": 7,
"ordinal": 6,
"name": "publish_date",
"type_info": "Timestamptz"
},
{
"ordinal": 8,
"ordinal": 7,
"name": "author_id",
"type_info": "Int4"
}
@@ -64,9 +59,8 @@
false,
true,
true,
true,
false
]
},
"hash": "1ae4bbbfd835587ea4389b3b4500d1b0f549d682f892a10586815014519bb8c4"
"hash": "3831b52c2db3d1114c4b01a761c74168b66904bacff847844d463454b7fcde43"
}
@@ -1,68 +0,0 @@
{
"db_name": "PostgreSQL",
"query": "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.body_gemtext, p.created_at, p.publish_date FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id LEFT JOIN comments c ON p.post_id = c.post_id WHERE p.deleted_at IS NULL GROUP BY p.post_id, a.first_name, a.last_name ORDER BY COUNT(c.comment_id) DESC LIMIT 3",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "post_id",
"type_info": "Int4"
},
{
"ordinal": 1,
"name": "author_id",
"type_info": "Int4"
},
{
"ordinal": 2,
"name": "first_name",
"type_info": "Varchar"
},
{
"ordinal": 3,
"name": "last_name",
"type_info": "Varchar"
},
{
"ordinal": 4,
"name": "title",
"type_info": "Text"
},
{
"ordinal": 5,
"name": "body",
"type_info": "Text"
},
{
"ordinal": 6,
"name": "body_gemtext",
"type_info": "Text"
},
{
"ordinal": 7,
"name": "created_at",
"type_info": "Timestamptz"
},
{
"ordinal": 8,
"name": "publish_date",
"type_info": "Timestamptz"
}
],
"parameters": {
"Left": []
},
"nullable": [
false,
true,
false,
false,
false,
false,
true,
true,
true
]
},
"hash": "464d1fdbed6800f3b09e3abca989d79dfcca8a6680cb0ee324ba0790e4ec3484"
}
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
"query": "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.body_gemtext, p.created_at, p.publish_date FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL GROUP BY p.post_id, a.first_name, a.last_name ORDER BY p.created_at DESC LIMIT 3",
"query": "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.created_at, p.publish_date FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id LEFT JOIN comments c ON p.post_id = c.post_id WHERE p.deleted_at IS NULL GROUP BY p.post_id, a.first_name, a.last_name ORDER BY COUNT(c.comment_id) DESC LIMIT 3",
"describe": {
"columns": [
{
@@ -35,16 +35,11 @@
},
{
"ordinal": 6,
"name": "body_gemtext",
"type_info": "Text"
},
{
"ordinal": 7,
"name": "created_at",
"type_info": "Timestamptz"
},
{
"ordinal": 8,
"ordinal": 7,
"name": "publish_date",
"type_info": "Timestamptz"
}
@@ -60,9 +55,8 @@
false,
false,
true,
true,
true
]
},
"hash": "4557c49e323c6b7c3246903e63e1c61c0f008e80308f65066bff7f4b70a8c7dd"
"hash": "49768c8b986078bdfaad191b3ea1f07ca033b2a734162a3f8fcf0ef0a44c1e7f"
}
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
"query": "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.body_gemtext, p.created_at, p.publish_date FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL AND p.is_featured IS true GROUP BY p.post_id, a.first_name, a.last_name ORDER BY p.created_at DESC LIMIT 3",
"query": "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.created_at, p.publish_date FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL AND p.is_featured IS true GROUP BY p.post_id, a.first_name, a.last_name ORDER BY p.created_at DESC LIMIT 3",
"describe": {
"columns": [
{
@@ -35,16 +35,11 @@
},
{
"ordinal": 6,
"name": "body_gemtext",
"type_info": "Text"
},
{
"ordinal": 7,
"name": "created_at",
"type_info": "Timestamptz"
},
{
"ordinal": 8,
"ordinal": 7,
"name": "publish_date",
"type_info": "Timestamptz"
}
@@ -60,9 +55,8 @@
false,
false,
true,
true,
true
]
},
"hash": "24f4b8dd651c57a8cab3ffc2fae9bfe4cb276521854b2a0a0fba2e7081093421"
"hash": "9d93a8a7c0a2442a511108af36d4adfb1ef8a2fac82448205654742f43dc4e75"
}
@@ -0,0 +1,62 @@
{
"db_name": "PostgreSQL",
"query": "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.created_at, p.publish_date FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL ORDER BY p.view_count DESC LIMIT 3",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "post_id",
"type_info": "Int4"
},
{
"ordinal": 1,
"name": "author_id",
"type_info": "Int4"
},
{
"ordinal": 2,
"name": "first_name",
"type_info": "Varchar"
},
{
"ordinal": 3,
"name": "last_name",
"type_info": "Varchar"
},
{
"ordinal": 4,
"name": "title",
"type_info": "Text"
},
{
"ordinal": 5,
"name": "body",
"type_info": "Text"
},
{
"ordinal": 6,
"name": "created_at",
"type_info": "Timestamptz"
},
{
"ordinal": 7,
"name": "publish_date",
"type_info": "Timestamptz"
}
],
"parameters": {
"Left": []
},
"nullable": [
false,
true,
false,
false,
false,
false,
true,
true
]
},
"hash": "ad39df8c37105f13b620f8898e570cdbc54d4bd4e402aac65a28c9aa81803831"
}
+137 -377
View File
@@ -2,6 +2,21 @@
# It is not intended for manual editing.
version = 4
[[package]]
name = "addr2line"
version = "0.24.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1"
dependencies = [
"gimli",
]
[[package]]
name = "adler2"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
[[package]]
name = "aho-corasick"
version = "1.1.3"
@@ -38,45 +53,6 @@ version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457"
[[package]]
name = "asn1-rs"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7f43a50ac4fdca5df8e885c21b835997f0a1cdee65494a6847694a98652d9d8"
dependencies = [
"asn1-rs-derive",
"asn1-rs-impl",
"displaydoc",
"nom",
"num-traits",
"rusticata-macros",
"thiserror 2.0.21",
"time",
]
[[package]]
name = "asn1-rs-derive"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3109e49b1e4909e9db6515a30c633684d68cdeaa252f215214cb4fa1a5bfee2c"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.104",
"synstructure",
]
[[package]]
name = "asn1-rs-impl"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.104",
]
[[package]]
name = "async-trait"
version = "0.1.88"
@@ -85,7 +61,7 @@ checksum = "e539d3fca749fcee5236ab05e93a52867dd549cc157c8cb7f99595f3cedffdb5"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.104",
"syn",
]
[[package]]
@@ -109,29 +85,6 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
[[package]]
name = "aws-lc-rs"
version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "048006790404103c488e6c5616b3e7e702a71292aadda08e8f7698a9e0d2eb53"
dependencies = [
"aws-lc-sys",
"zeroize",
]
[[package]]
name = "aws-lc-sys"
version = "0.47.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8bfbe32ac36b3c428696ce315464181bc4029d689fd58e3f2a4e58c252242f52"
dependencies = [
"cc",
"cmake",
"dunce",
"fs_extra",
"pkg-config",
]
[[package]]
name = "axum"
version = "0.7.9"
@@ -241,6 +194,21 @@ dependencies = [
"tracing",
]
[[package]]
name = "backtrace"
version = "0.3.75"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6806a6321ec58106fea15becdad98371e28d92ccbc7c8f1b3b6dd724fe8f1002"
dependencies = [
"addr2line",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
"windows-targets 0.52.6",
]
[[package]]
name = "base64"
version = "0.22.1"
@@ -310,13 +278,10 @@ dependencies = [
[[package]]
name = "cc"
version = "1.11.0"
version = "1.2.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "375989decec1a0fa424442bed520fa12ede43a48475ce8c7417d2c69b32b5f6b"
checksum = "5c1599538de2394445747c8cf7935946e3cc27e9625f889d979bfb2aaf569362"
dependencies = [
"find-msvc-tools",
"jobserver",
"libc",
"shlex",
]
@@ -337,16 +302,7 @@ dependencies = [
"js-sys",
"num-traits",
"wasm-bindgen",
"windows-link 0.1.3",
]
[[package]]
name = "cmake"
version = "0.1.58"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0f78a02292a74a88ac736019ab962ece0bc380e3f977bf72e376c5d78ff0678"
dependencies = [
"cc",
"windows-link",
]
[[package]]
@@ -444,12 +400,6 @@ dependencies = [
"parking_lot_core",
]
[[package]]
name = "data-encoding"
version = "2.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4583a4551df46e2792f82ceeac45e850d2e2d5debba0b91f102385cda5b11f06"
[[package]]
name = "der"
version = "0.7.10"
@@ -461,29 +411,6 @@ dependencies = [
"zeroize",
]
[[package]]
name = "der-parser"
version = "10.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07da5016415d5a3c4dd39b11ed26f915f52fc4e0dc197d87908bc916e51bc1a6"
dependencies = [
"asn1-rs",
"displaydoc",
"nom",
"num-bigint",
"num-traits",
"rusticata-macros",
]
[[package]]
name = "deranged"
version = "0.5.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e9de72ce2ad1f90dc62fa25f0f430ef85eb4b0d8fa0be4f30373bc40a21d28e"
dependencies = [
"powerfmt",
]
[[package]]
name = "digest"
version = "0.10.7"
@@ -504,7 +431,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.104",
"syn",
]
[[package]]
@@ -513,12 +440,6 @@ version = "0.15.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
[[package]]
name = "dunce"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813"
[[package]]
name = "either"
version = "1.15.0"
@@ -556,12 +477,6 @@ dependencies = [
"pin-project-lite",
]
[[package]]
name = "find-msvc-tools"
version = "0.1.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48"
[[package]]
name = "float-cmp"
version = "0.10.0"
@@ -596,9 +511,9 @@ checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
[[package]]
name = "form_urlencoded"
version = "1.2.2"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf"
checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456"
dependencies = [
"percent-encoding",
]
@@ -631,7 +546,7 @@ dependencies = [
"rand",
"redis-protocol",
"semver",
"socket2 0.5.10",
"socket2",
"tokio",
"tokio-stream",
"tokio-util",
@@ -647,15 +562,9 @@ checksum = "1458c6e22d36d61507034d5afecc64f105c1d39712b7ac6ec3b352c423f715cc"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.104",
"syn",
]
[[package]]
name = "fs_extra"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
[[package]]
name = "futures"
version = "0.3.31"
@@ -723,7 +632,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.104",
"syn",
]
[[package]]
@@ -762,26 +671,6 @@ dependencies = [
"slab",
]
[[package]]
name = "gemi"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48c58101caf24da682290251734dde61f7f0a7fcabb996660008d8e2b960a9ff"
dependencies = [
"matchit 0.9.2",
"ring",
"rustls",
"rustls-pki-types",
"sha2",
"thiserror 2.0.21",
"tokio",
"tokio-rustls",
"tracing",
"url",
"urlencoding",
"x509-parser",
]
[[package]]
name = "generic-array"
version = "0.14.7"
@@ -804,15 +693,10 @@ dependencies = [
]
[[package]]
name = "getrandom"
version = "0.4.3"
name = "gimli"
version = "0.31.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
dependencies = [
"cfg-if",
"libc",
"r-efi",
]
checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
[[package]]
name = "governor"
@@ -1112,9 +996,9 @@ dependencies = [
[[package]]
name = "idna"
version = "1.1.0"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de"
checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e"
dependencies = [
"idna_adapter",
"smallvec",
@@ -1141,22 +1025,23 @@ dependencies = [
"hashbrown 0.15.4",
]
[[package]]
name = "io-uring"
version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b86e202f00093dcba4275d4636b93ef9dd75d025ae560d2521b45ea28ab49013"
dependencies = [
"bitflags",
"cfg-if",
"libc",
]
[[package]]
name = "itoa"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]]
name = "jobserver"
version = "0.1.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3"
dependencies = [
"getrandom 0.4.3",
"libc",
]
[[package]]
name = "js-sys"
version = "0.3.77"
@@ -1178,9 +1063,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.191"
version = "0.2.174"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776"
[[package]]
name = "libm"
@@ -1241,12 +1126,6 @@ version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3"
[[package]]
name = "matchit"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8863b587001c1b9a8a4e36008cebc6b3612cb1226fe2de94858e06092687b608"
[[package]]
name = "md-5"
version = "0.10.6"
@@ -1276,14 +1155,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "mio"
version = "1.2.4"
name = "miniz_oxide"
version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1788edb87fdc09c7e26304471e2f5be8cdefb1b6930d6e3985fc02ff53bf86ee"
checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316"
dependencies = [
"adler2",
]
[[package]]
name = "mio"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78bed444cc8a2160f01cbcf811ef18cac863ad68ae8ca62092e8db51d51c761c"
dependencies = [
"libc",
"wasi",
"windows-sys 0.61.2",
"windows-sys 0.59.0",
]
[[package]]
@@ -1324,16 +1212,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "num-bigint"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c89e69e7e0f03bea5ef08013795c25018e101932225a656383bd384495ecc367"
dependencies = [
"num-integer",
"num-traits",
]
[[package]]
name = "num-bigint-dig"
version = "0.8.4"
@@ -1351,12 +1229,6 @@ dependencies = [
"zeroize",
]
[[package]]
name = "num-conv"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
[[package]]
name = "num-integer"
version = "0.1.46"
@@ -1388,12 +1260,12 @@ dependencies = [
]
[[package]]
name = "oid-registry"
version = "0.8.1"
name = "object"
version = "0.36.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12f40cff3dde1b6087cc5d5f5d4d65712f34016a03ed60e9c08dcc392736b5b7"
checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87"
dependencies = [
"asn1-rs",
"memchr",
]
[[package]]
@@ -1448,9 +1320,9 @@ dependencies = [
[[package]]
name = "percent-encoding"
version = "2.3.2"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e"
[[package]]
name = "pin-project"
@@ -1469,7 +1341,7 @@ checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.104",
"syn",
]
[[package]]
@@ -1526,12 +1398,6 @@ dependencies = [
"zerovec",
]
[[package]]
name = "powerfmt"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a6394b9e965e73d0a289ee54f589087e2c676aedf60885baf52c76b771e4958"
[[package]]
name = "ppv-lite86"
version = "0.2.21"
@@ -1552,15 +1418,13 @@ dependencies = [
[[package]]
name = "public"
version = "0.2.0"
version = "0.1.0"
dependencies = [
"axum 0.8.4",
"cache",
"chrono",
"dotenvy",
"fred",
"gemi",
"rustls",
"serde",
"serde_json",
"sqlx",
@@ -1596,12 +1460,6 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "r-efi"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
[[package]]
name = "rand"
version = "0.8.5"
@@ -1629,7 +1487,7 @@ version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom 0.2.16",
"getrandom",
]
[[package]]
@@ -1716,7 +1574,7 @@ checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7"
dependencies = [
"cc",
"cfg-if",
"getrandom 0.2.16",
"getrandom",
"libc",
"untrusted",
"windows-sys 0.52.0",
@@ -1743,22 +1601,17 @@ dependencies = [
]
[[package]]
name = "rusticata-macros"
version = "4.1.0"
name = "rustc-demangle"
version = "0.1.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "faf0c4a6ece9950b9abdb62b1cfcf2a68b3b67a10ba445b3bb85be2a293d0632"
dependencies = [
"nom",
]
checksum = "989e6739f80c4ad5b13e0fd7fe89531180375b18520cc8c82080e4dc4035b84f"
[[package]]
name = "rustls"
version = "0.23.46"
version = "0.23.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf"
checksum = "2491382039b29b9b11ff08b76ff6c97cf287671dbb74f0be44bda389fffe9bd1"
dependencies = [
"aws-lc-rs",
"log",
"once_cell",
"ring",
"rustls-pki-types",
@@ -1769,20 +1622,19 @@ dependencies = [
[[package]]
name = "rustls-pki-types"
version = "1.15.1"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96"
checksum = "229a4a4c221013e7e1f1a043678c5cc39fe5171437c88fb47151a21e6f5b5c79"
dependencies = [
"zeroize",
]
[[package]]
name = "rustls-webpki"
version = "0.103.16"
version = "0.103.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4443b1b6d39d7c663139942cc4558262562d2c84123bb6282ef177009ca8b281"
checksum = "0a17884ae0c1b773f1ccd2bd4a8c72f16da897310a98b0e84bf349ad5ead92fc"
dependencies = [
"aws-lc-rs",
"ring",
"rustls-pki-types",
"untrusted",
@@ -1829,7 +1681,7 @@ checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.104",
"syn",
]
[[package]]
@@ -1899,9 +1751,9 @@ dependencies = [
[[package]]
name = "shlex"
version = "2.0.1"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "signal-hook-registry"
@@ -1947,16 +1799,6 @@ dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "socket2"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4"
dependencies = [
"libc",
"windows-sys 0.61.2",
]
[[package]]
name = "spin"
version = "0.9.8"
@@ -2027,7 +1869,7 @@ dependencies = [
"serde_json",
"sha2",
"smallvec",
"thiserror 2.0.21",
"thiserror 2.0.12",
"tokio",
"tokio-stream",
"tracing",
@@ -2045,7 +1887,7 @@ dependencies = [
"quote",
"sqlx-core",
"sqlx-macros-core",
"syn 2.0.104",
"syn",
]
[[package]]
@@ -2068,7 +1910,7 @@ dependencies = [
"sqlx-mysql",
"sqlx-postgres",
"sqlx-sqlite",
"syn 2.0.104",
"syn",
"tokio",
"url",
]
@@ -2111,7 +1953,7 @@ dependencies = [
"smallvec",
"sqlx-core",
"stringprep",
"thiserror 2.0.21",
"thiserror 2.0.12",
"tracing",
"whoami",
]
@@ -2149,7 +1991,7 @@ dependencies = [
"smallvec",
"sqlx-core",
"stringprep",
"thiserror 2.0.21",
"thiserror 2.0.12",
"tracing",
"whoami",
]
@@ -2174,7 +2016,7 @@ dependencies = [
"serde",
"serde_urlencoded",
"sqlx-core",
"thiserror 2.0.21",
"thiserror 2.0.12",
"tracing",
"url",
]
@@ -2213,17 +2055,6 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "syn"
version = "3.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "sync_wrapper"
version = "1.0.2"
@@ -2238,7 +2069,7 @@ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.104",
"syn",
]
[[package]]
@@ -2252,11 +2083,11 @@ dependencies = [
[[package]]
name = "thiserror"
version = "2.0.21"
version = "2.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e"
checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708"
dependencies = [
"thiserror-impl 2.0.21",
"thiserror-impl 2.0.12",
]
[[package]]
@@ -2267,18 +2098,18 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.104",
"syn",
]
[[package]]
name = "thiserror-impl"
version = "2.0.21"
version = "2.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524"
checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
dependencies = [
"proc-macro2",
"quote",
"syn 3.0.9",
"syn",
]
[[package]]
@@ -2290,37 +2121,6 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "time"
version = "0.3.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91e7d9e3bb61134e77bde20dd4825b97c010155709965fedf0f49bb138e52a9d"
dependencies = [
"deranged",
"itoa",
"num-conv",
"powerfmt",
"serde",
"time-core",
"time-macros",
]
[[package]]
name = "time-core"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b"
[[package]]
name = "time-macros"
version = "0.2.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30cfb0125f12d9c277f35663a0a33f8c30190f4e4574868a330595412d34ebf3"
dependencies = [
"num-conv",
"time-core",
]
[[package]]
name = "tinystr"
version = "0.8.1"
@@ -2348,40 +2148,33 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]]
name = "tokio"
version = "1.54.1"
version = "1.46.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b52fd3255258d26fac7264ab5a76b53c13367136dc011d3d6ad4f8ed070396a3"
checksum = "0cc3a2344dafbe23a245241fe8b09735b521110d30fcefbbd5feb1797ca35d17"
dependencies = [
"backtrace",
"bytes",
"io-uring",
"libc",
"mio",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2 0.6.5",
"slab",
"socket2",
"tokio-macros",
"windows-sys 0.61.2",
"windows-sys 0.52.0",
]
[[package]]
name = "tokio-macros"
version = "2.7.2"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e"
checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8"
dependencies = [
"proc-macro2",
"quote",
"syn 3.0.9",
]
[[package]]
name = "tokio-rustls"
version = "0.26.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9cc2678c2cdd569ef8215e2afd7954ada2ae20b4fdd2c5fe6139a3b02d105db"
dependencies = [
"rustls",
"tokio",
"syn",
]
[[package]]
@@ -2470,9 +2263,9 @@ dependencies = [
[[package]]
name = "tracing"
version = "0.1.44"
version = "0.1.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0"
dependencies = [
"log",
"pin-project-lite",
@@ -2482,20 +2275,20 @@ dependencies = [
[[package]]
name = "tracing-attributes"
version = "0.1.31"
version = "0.1.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da"
checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.104",
"syn",
]
[[package]]
name = "tracing-core"
version = "0.1.36"
version = "0.1.34"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678"
dependencies = [
"once_cell",
"valuable",
@@ -2571,14 +2364,13 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
[[package]]
name = "url"
version = "2.5.8"
version = "2.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed"
checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60"
dependencies = [
"form_urlencoded",
"idna",
"percent-encoding",
"serde",
]
[[package]]
@@ -2645,7 +2437,7 @@ dependencies = [
"log",
"proc-macro2",
"quote",
"syn 2.0.104",
"syn",
"wasm-bindgen-shared",
]
@@ -2667,7 +2459,7 @@ checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.104",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
@@ -2749,7 +2541,7 @@ checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3"
dependencies = [
"windows-implement",
"windows-interface",
"windows-link 0.1.3",
"windows-link",
"windows-result",
"windows-strings",
]
@@ -2762,7 +2554,7 @@ checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.104",
"syn",
]
[[package]]
@@ -2773,7 +2565,7 @@ checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.104",
"syn",
]
[[package]]
@@ -2782,19 +2574,13 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]]
name = "windows-result"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6"
dependencies = [
"windows-link 0.1.3",
"windows-link",
]
[[package]]
@@ -2803,7 +2589,7 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57"
dependencies = [
"windows-link 0.1.3",
"windows-link",
]
[[package]]
@@ -2833,15 +2619,6 @@ dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "windows-sys"
version = "0.61.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
dependencies = [
"windows-link 0.2.1",
]
[[package]]
name = "windows-targets"
version = "0.48.5"
@@ -2969,23 +2746,6 @@ version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea2f10b9bb0928dfb1b42b65e1f9e36f7f54dbdf08457afefb38afcdec4fa2bb"
[[package]]
name = "x509-parser"
version = "0.18.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d43b0f71ce057da06bc0851b23ee24f3f86190b07203dd8f567d0b706a185202"
dependencies = [
"asn1-rs",
"data-encoding",
"der-parser",
"lazy_static",
"nom",
"oid-registry",
"rusticata-macros",
"thiserror 2.0.21",
"time",
]
[[package]]
name = "xml"
version = "0.8.20"
@@ -3021,7 +2781,7 @@ checksum = "38da3c9736e16c5d3c8c597a9aaa5d1fa565d0532ae05e27c24aa62fb32c0ab6"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.104",
"syn",
"synstructure",
]
@@ -3042,7 +2802,7 @@ checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.104",
"syn",
]
[[package]]
@@ -3062,7 +2822,7 @@ checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.104",
"syn",
"synstructure",
]
@@ -3102,5 +2862,5 @@ checksum = "5b96237efa0c878c64bd89c436f661be4e46b2f3eff1ebb976f7ef2321d2f58f"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.104",
"syn",
]
+1 -3
View File
@@ -1,6 +1,6 @@
[package]
name = "public"
version = "0.2.0"
version = "0.1.0"
edition = "2021"
authors = ["Wyatt J. Miller <wyatt@wyattjmiller.com"]
@@ -8,7 +8,6 @@ authors = ["Wyatt J. Miller <wyatt@wyattjmiller.com"]
[dependencies]
axum = { version = "0.8.4", features = ["http2", "tokio"] }
gemi = "0.1.0"
tower-http = { version = "0.6.1", features = ["trace", "cors"] }
tower_governor = "0.4.2"
tokio = { version = "1.40.0", features = ["full"] }
@@ -18,7 +17,6 @@ sqlx = { version = "0.8.2", features = [
"chrono",
"json",
] }
rustls = { version = "0.23", default-features = false, features = ["ring", "std", "tls12"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
dotenvy = "0.15.7"
-22
View File
@@ -18,25 +18,3 @@ For `public` to work properly, please make sure to first create the `.env` file,
- `DATABASE_URL` - needed for connecting to Postgres
- `REDIS_URL` - needed for connecting to the cache (Redis or Valkey)
- `BASE_URI_WEB` - needed for connecting to the frontend user interface of the system to this service
### Gemini
Set `SERVE_APP=gemini` to run the existing Gemini TLS server on port 1965.
It uses `dev-cert.der` and `dev-key.der` in the working directory; database and
cache configuration is shared with HTTP mode. `BASE_URI_WEB` supplies links back
to the web site for RSS, the sitemap, contact forms, and posts without Gemtext.
The capsule follows the web site's navigation and page sections:
- `/`, `/contact`, `/health`
- `/posts`, `/posts/all`, `/posts/{id}`
- `/posts/featured`, `/posts/recent`, `/posts/popular`, `/posts/hot`
- `/authors`, `/authors/{id}`, `/authors/{id}/posts`
- `/projects`
- `/comments/index`, `/comments/post/{id}`
Author and comment indexes accept `?page=1&limit=12` (maximum limit 100).
Author pages include a biography and paginated post links. Article pages render
`body_gemtext` as Gemtext, with author, publication date, and featured status;
articles without it link to the HTML version. Comments are read-only, with a
link to the web page for participation.
-17
View File
@@ -1,22 +1,5 @@
use std::path::PathBuf;
pub enum ServeAppConfig {
Http,
Gemini,
}
impl std::str::FromStr for ServeAppConfig {
type Err = &'static str;
fn from_str(value: &str) -> Result<Self, Self::Err> {
match value {
"http" => Ok(Self::Http),
"gemini" => Ok(Self::Gemini),
_ => Err("expected \"http\" or \"gemini\""),
}
}
}
pub fn config() -> Configuration {
Configuration {
env: dotenvy::dotenv(),
+3 -3
View File
@@ -1,7 +1,7 @@
use sqlx::{Pool, Postgres};
use crate::{
models::{authors::Author, posts::Post},
routes::{authors::Author, posts::Post},
utils::pagination::Pagination,
};
@@ -15,7 +15,7 @@ impl AuthorsDatasource {
sqlx::query_as!(
Author,
"SELECT author_id, first_name, last_name, bio, image FROM authors ORDER BY created_at DESC LIMIT $1 OFFSET $2",
pagination.limit,
pagination.page,
offset,
)
.fetch_all(pool)
@@ -53,7 +53,7 @@ impl AuthorsDatasource {
let posts_query = sqlx::query_as!(
Post,
"SELECT p.post_id, a.first_name, a.last_name, p.title, p.body, p.body_gemtext, p.created_at, p.publish_date, a.author_id FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL AND p.author_id = $1 ORDER BY created_at DESC LIMIT $2 OFFSET $3",
"SELECT p.post_id, a.first_name, a.last_name, p.title, p.body, p.created_at, p.publish_date, a.author_id FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL AND p.author_id = $1 ORDER BY created_at DESC LIMIT $2 OFFSET $3",
author_id,
pagination.limit,
offset,
+2 -2
View File
@@ -1,5 +1,5 @@
use crate::{
models::comments::{Comment, CommentInputPayload},
routes::comments::{Comment, CommentInputPayload},
utils::pagination::Pagination,
};
use sqlx::{Pool, Postgres};
@@ -29,7 +29,7 @@ impl CommentsDatasource {
pagination: Pagination,
) -> Result<Vec<Comment>, sqlx::Error> {
let offset: i64 = (pagination.page - 1) * pagination.limit;
sqlx::query_as!(Comment, "SELECT comment_id, name, body, created_at FROM comments ORDER BY created_at DESC LIMIT $1 OFFSET $2", pagination.limit, offset)
sqlx::query_as!(Comment, "SELECT comment_id, name, body, created_at FROM comments ORDER BY created_at DESC LIMIT $1 OFFSET $2", pagination.page, offset)
.fetch_all(pool)
.await
}
+7 -7
View File
@@ -1,11 +1,11 @@
use sqlx::{Pool, Postgres};
use crate::models::posts::{Post, PostFeaturedVariant};
use crate::routes::posts::{Post, PostFeaturedVariant};
pub struct PostsDatasource;
impl PostsDatasource {
pub async fn get_all(pool: &Pool<Postgres>) -> Result<Vec<Post>, sqlx::Error> {
sqlx::query_as!(Post, "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.body_gemtext, p.created_at, p.publish_date FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL ORDER BY p.created_at DESC LIMIT 10")
sqlx::query_as!(Post, "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.created_at, p.publish_date FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL ORDER BY p.created_at DESC LIMIT 10")
.fetch_all(pool)
.await
}
@@ -19,31 +19,31 @@ impl PostsDatasource {
.execute(pool)
.await;
sqlx::query_as!(PostFeaturedVariant, "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.body_gemtext, p.created_at, p.publish_date, p.is_featured FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL AND p.post_id = $1 ORDER BY p.created_at DESC", post_id)
sqlx::query_as!(PostFeaturedVariant, "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.created_at, p.publish_date, p.is_featured FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL AND p.post_id = $1 ORDER BY p.created_at DESC", post_id)
.fetch_one(pool)
.await
}
pub async fn get_recent(pool: &Pool<Postgres>) -> Result<Vec<Post>, sqlx::Error> {
sqlx::query_as!(Post, "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.body_gemtext, p.created_at, p.publish_date FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL GROUP BY p.post_id, a.first_name, a.last_name ORDER BY p.created_at DESC LIMIT 3")
sqlx::query_as!(Post, "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.created_at, p.publish_date FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL GROUP BY p.post_id, a.first_name, a.last_name ORDER BY p.created_at DESC LIMIT 3")
.fetch_all(pool)
.await
}
pub async fn get_popular(pool: &Pool<Postgres>) -> Result<Vec<Post>, sqlx::Error> {
sqlx::query_as!(Post, "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.body_gemtext, p.created_at, p.publish_date FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id LEFT JOIN comments c ON p.post_id = c.post_id WHERE p.deleted_at IS NULL GROUP BY p.post_id, a.first_name, a.last_name ORDER BY COUNT(c.comment_id) DESC LIMIT 3")
sqlx::query_as!(Post, "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.created_at, p.publish_date FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id LEFT JOIN comments c ON p.post_id = c.post_id WHERE p.deleted_at IS NULL GROUP BY p.post_id, a.first_name, a.last_name ORDER BY COUNT(c.comment_id) DESC LIMIT 3")
.fetch_all(pool)
.await
}
pub async fn get_hot(pool: &Pool<Postgres>) -> Result<Vec<Post>, sqlx::Error> {
sqlx::query_as!(Post, "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.body_gemtext, p.created_at, p.publish_date FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL ORDER BY p.view_count DESC LIMIT 3")
sqlx::query_as!(Post, "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.created_at, p.publish_date FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL ORDER BY p.view_count DESC LIMIT 3")
.fetch_all(pool)
.await
}
pub async fn get_featured(pool: &Pool<Postgres>) -> Result<Vec<Post>, sqlx::Error> {
sqlx::query_as!(Post, "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.body_gemtext, p.created_at, p.publish_date FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL AND p.is_featured IS true GROUP BY p.post_id, a.first_name, a.last_name ORDER BY p.created_at DESC LIMIT 3")
sqlx::query_as!(Post, "SELECT p.post_id, p.author_id, a.first_name, a.last_name, p.title, p.body, p.created_at, p.publish_date FROM posts p LEFT JOIN authors a ON a.author_id = p.author_id WHERE p.deleted_at IS NULL AND p.is_featured IS true GROUP BY p.post_id, a.first_name, a.last_name ORDER BY p.created_at DESC LIMIT 3")
.fetch_all(pool)
.await
}
+2 -2
View File
@@ -1,6 +1,6 @@
use sqlx::{Pool, Postgres};
use sqlx::{FromRow, Pool, Postgres, Row};
use crate::models::projects::Project;
use crate::routes::projects::Project;
pub struct ProjectsDatasource;
impl ProjectsDatasource {
+9 -35
View File
@@ -1,5 +1,4 @@
use axum::Router;
use gemi::{EndpointExt, GeminiConfig, GeminiServer};
use cache::ClientLike;
use config::config;
use sqlx::postgres::PgPoolOptions;
@@ -18,9 +17,7 @@ use tracing_subscriber::{filter, layer::SubscriberExt, prelude::*, util::Subscri
mod config;
mod datasources;
mod models;
mod routes;
mod services;
mod state;
mod utils;
@@ -118,27 +115,22 @@ async fn main() {
let app_state = Arc::new(Mutex::new(state::AppInternalState::new(pool, redis_pool)));
// build our application with some routes
let app_env = std::env::var("SERVE_APP")
.unwrap_or_else(|_| "http".to_string())
.parse::<config::ServeAppConfig>()
.expect("Invalid SERVE_APP value");
match app_env {
config::ServeAppConfig::Http => {
let state = app_state.clone();
let app = Router::new()
.merge(routes::http::root::RootRoute::routes())
.merge(routes::http::posts::PostsRoute::routes(&state))
.merge(routes::http::comments::CommentsRoute::routes(&state))
.merge(routes::http::authors::AuthorsRoute::routes(&state))
.merge(routes::http::projects::ProjectsRoute::routes(&state))
.merge(routes::root::RootRoute::routes())
.merge(routes::posts::PostsRoute::routes(&app_state))
.merge(routes::comments::CommentsRoute::routes(&app_state))
.merge(routes::authors::AuthorsRoute::routes(&app_state))
.merge(routes::projects::ProjectsRoute::routes(&app_state))
.layer(CorsLayer::permissive())
.layer(
TraceLayer::new_for_http()
.make_span_with(trace::DefaultMakeSpan::new().level(tracing::Level::INFO))
.on_response(trace::DefaultOnResponse::new().level(tracing::Level::INFO)),
)
.fallback(routes::http::root::RootRoute::not_found);
.fallback(routes::root::RootRoute::not_found);
//.layer(GovernorLayer {
// config: governor_conf,
//});
// run it with hyper
let listener = TcpListener::bind("0.0.0.0:3000").await.unwrap();
@@ -148,24 +140,6 @@ async fn main() {
.await
.unwrap();
}
config::ServeAppConfig::Gemini => {
rustls::crypto::ring::default_provider()
.install_default()
.expect("failed to install Rustls crypto provider");
let gemini_state = app_state.clone();
let router = routes::gemini::routes().expect("Failed to construct Gemini routes");
let config = GeminiConfig::new("localhost");
let app = router.with_state(gemini_state);
let server = GeminiServer::new(app, "dev-cert.der", "dev-key.der", config).unwrap();
server
.serve_with_shutdown(shutdown_signal())
.await
.unwrap();
}
};
}
async fn shutdown_signal() {
let ctrl_c = async {
-15
View File
@@ -1,15 +0,0 @@
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, Clone)]
pub struct Author {
pub author_id: i32,
pub first_name: String,
pub last_name: String,
pub bio: Option<String>,
pub image: Option<String>,
}
#[derive(Deserialize, Serialize, Clone)]
pub struct AuthorGetOneParams {
pub id: i32,
}
-26
View File
@@ -1,26 +0,0 @@
use serde::{Serialize, Deserialize};
use chrono::Utc;
use crate::utils::datetime::*;
#[derive(Deserialize, Serialize)]
pub struct CommentPathParams {
pub id: i32,
}
#[derive(sqlx::FromRow, Deserialize, Serialize, Debug, Clone)]
pub struct Comment {
pub comment_id: i32,
pub name: String,
pub body: String,
#[serde(serialize_with = "serialize_datetime")]
#[serde(deserialize_with = "deserialize_datetime")]
pub created_at: Option<chrono::DateTime<Utc>>,
}
#[derive(Deserialize, Serialize, Debug)]
pub struct CommentInputPayload {
pub name: String,
pub body: String,
pub post_id: i32,
}
-4
View File
@@ -1,4 +0,0 @@
pub mod authors;
pub mod posts;
pub mod projects;
pub mod comments;
-44
View File
@@ -1,44 +0,0 @@
use serde::{Deserialize, Serialize};
use chrono::Utc;
use crate::utils::datetime::*;
#[derive(sqlx::FromRow, Deserialize, Serialize, Debug, Clone)]
pub struct Post {
pub post_id: i32,
pub author_id: Option<i32>,
pub first_name: Option<String>,
pub last_name: Option<String>,
pub title: String,
pub body: String,
pub body_gemtext: Option<String>,
#[serde(serialize_with = "serialize_datetime")]
#[serde(deserialize_with = "deserialize_datetime")]
pub created_at: Option<chrono::DateTime<Utc>>,
#[serde(serialize_with = "serialize_datetime")]
#[serde(deserialize_with = "deserialize_datetime")]
pub publish_date: Option<chrono::DateTime<Utc>>,
}
#[derive(sqlx::FromRow, Deserialize, Serialize, Debug, Clone)]
pub struct PostFeaturedVariant {
pub post_id: i32,
pub author_id: Option<i32>,
pub first_name: Option<String>,
pub last_name: Option<String>,
pub title: String,
pub body: String,
pub body_gemtext: Option<String>,
#[serde(serialize_with = "serialize_datetime")]
#[serde(deserialize_with = "deserialize_datetime")]
pub created_at: Option<chrono::DateTime<Utc>>,
#[serde(serialize_with = "serialize_datetime")]
#[serde(deserialize_with = "deserialize_datetime")]
pub publish_date: Option<chrono::DateTime<Utc>>,
pub is_featured: Option<bool>,
}
#[derive(Deserialize)]
pub struct PostGetOneParams {
pub id: i32,
}
-18
View File
@@ -1,18 +0,0 @@
use serde::{Serialize, Deserialize};
use crate::utils::datetime::*;
#[derive(sqlx::FromRow, Deserialize, Serialize, Debug, Clone)]
pub struct Project {
pub project_id: i32,
pub title: String,
pub repo: Option<String>,
pub summary: String,
pub tech: String,
pub wip: Option<bool>,
#[serde(serialize_with = "serialize_datetime")]
#[serde(deserialize_with = "deserialize_datetime")]
pub created_at: Option<chrono::DateTime<chrono::Utc>>,
}
@@ -10,18 +10,24 @@ use serde::{Deserialize, Serialize};
use crate::{
datasources::authors::AuthorsDatasource,
models::{
posts::Post,
authors::{
Author,
AuthorGetOneParams,
}
},
services::authors::*,
routes::posts::Post,
state::AppState,
utils::pagination::{Pagination, PaginationQuery},
};
#[derive(Deserialize, Serialize, Clone)]
pub struct Author {
pub author_id: i32,
pub first_name: String,
pub last_name: String,
pub bio: Option<String>,
pub image: Option<String>,
}
#[derive(Deserialize, Serialize, Clone)]
pub struct AuthorGetOneParams {
pub id: i32,
}
#[derive(Deserialize, Serialize)]
pub struct AuthorPostsResponse {
@@ -49,19 +55,39 @@ impl AuthorsRoute {
};
let mut state = app_state.lock().await;
let cached = authors_cache::<Vec<Author>>(&mut state, String::from("all")).await;
let cached: Option<Vec<Author>> = state
.cache
.get(String::from("authors:all"))
.await
.unwrap_or(None);
if let Some(authors) = cached {
tracing::info!("grabbing all authors from cache");
return Ok(Json(authors));
}
match AuthorsDatasource::get_all(&state.database, pagination).await {
Ok(authors) => {
set_authors_cache(
&app_state,
String::from("all"),
authors.clone(),
Expiration::EX(5),
);
tracing::info!("grabbing all authors from the database");
if let a = &authors {
let author_cloned = a.clone();
let state = app_state.clone();
tracing::info!("storing database data in cache");
tokio::spawn(async move {
let mut s = state.lock().await;
let _ = s
.cache
.set(
String::from("authors:all"),
&author_cloned,
Some(Expiration::EX(5)),
None,
false,
)
.await;
});
}
Ok(Json(authors))
}
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
@@ -73,21 +99,40 @@ impl AuthorsRoute {
Path(params): Path<AuthorGetOneParams>,
) -> impl IntoResponse {
let mut state = app_state.lock().await;
let cached = authors_cache::<Author>(&mut state, params.id.to_string()).await;
let cached: Option<Author> = state
.cache
.get(format!("authors:{}", params.id))
.await
.unwrap_or(None);
if let Some(author) = cached {
tracing::info!("grabbing one author from cache");
return Ok(Json(author));
}
match AuthorsDatasource::get_one(&state.database, params.id).await {
Ok(author) => {
set_authors_cache(
&app_state,
author.author_id.to_string(),
author.clone(),
Expiration::EX(5),
);
tracing::info!("grabbing all authors from the database");
if let a = &author {
let author_cloned = a.clone();
let state = app_state.clone();
tracing::info!("storing database data in cache");
tokio::spawn(async move {
let mut s = state.lock().await;
let _ = s
.cache
.set(
format!("authors:{}", author_cloned.author_id),
&author_cloned,
Some(Expiration::EX(5)),
None,
false,
)
.await;
});
}
Ok(Json(author))
}
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
@@ -1,8 +1,8 @@
use crate::{
datasources::comments::CommentsDatasource,
models::comments::*,
state::AppState,
utils::{
datetime::*,
pagination::{Pagination, PaginationQuery},
},
};
@@ -14,6 +14,29 @@ use axum::{
Json,
};
use cache::{Expiration, SetOptions};
use chrono::Utc;
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize, Debug)]
pub struct CommentInputPayload {
pub name: String,
pub body: String,
pub post_id: i32,
}
#[derive(Deserialize, Serialize)]
pub struct CommentPathParams {
id: i32,
}
#[derive(sqlx::FromRow, Deserialize, Serialize, Debug, Clone)]
pub struct Comment {
pub comment_id: i32,
pub name: String,
pub body: String,
#[serde(serialize_with = "serialize_datetime")]
#[serde(deserialize_with = "deserialize_datetime")]
pub created_at: Option<chrono::DateTime<Utc>>,
}
pub struct CommentsRoute;
impl CommentsRoute {
@@ -51,6 +74,7 @@ impl CommentsRoute {
let state = app_state.clone();
tokio::spawn(async move {
tracing::info!("update cache if key already exists!");
let mut s = state.lock().await;
let _ = s
.cache
@@ -1,93 +0,0 @@
use super::format::{self, line, page};
use crate::{datasources::authors::AuthorsDatasource, state::AppState};
use gemi::{GeminiRequest, GeminiResponse, GeminiRouter, Params, State};
pub struct AuthorsGeminiRoutes;
impl AuthorsGeminiRoutes {
pub fn routes() -> gemi::Result<GeminiRouter<AppState>> {
let mut router = GeminiRouter::default();
router.add_route("/", Self::all)?;
router.add_route("/{id}", Self::one)?;
router.add_route("/{id}/posts", Self::one)?;
Ok(router)
}
async fn all(State(state): State<AppState>, request: GeminiRequest) -> GeminiResponse {
let p = match format::pagination(&request) {
Ok(p) => p,
Err(e) => return e,
};
let pool = state.lock().await.database.clone();
let result = AuthorsDatasource::get_all(
&pool,
crate::utils::pagination::Pagination {
page: p.page,
limit: p.limit,
},
)
.await;
match result {
Ok(authors) => {
let mut body = String::new();
for author in &authors {
body += &format!(
"=> /authors/{} {} {}\n",
author.author_id,
line(&author.first_name),
line(&author.last_name)
);
}
if authors.is_empty() {
body += "No authors found.\n";
}
body += &format::navigation("/authors", &p, authors.len() as i64 == p.limit);
page("Authors", &body)
}
Err(e) => format::error(e),
}
}
async fn one(
State(state): State<AppState>,
params: Params,
request: GeminiRequest,
) -> GeminiResponse {
let id = match format::id(&params) {
Ok(id) => id,
Err(e) => return e,
};
let p = match format::pagination(&request) {
Ok(p) => p,
Err(e) => return e,
};
let pool = state.lock().await.database.clone();
let author = match AuthorsDatasource::get_one(&pool, id).await {
Ok(a) => a,
Err(e) => return format::error(e),
};
match AuthorsDatasource::get_authors_posts(
&pool,
id,
crate::utils::pagination::Pagination {
page: p.page,
limit: p.limit,
},
)
.await
{
Ok((posts, total)) => {
let body = format!(
"{}\n\n## Posts\n{}{}",
line(author.bio.as_deref().unwrap_or("")),
format::posts(&posts),
format::navigation(&format!("/authors/{id}"), &p, p.page * p.limit < total)
);
page(
&format!("{} {}", author.first_name, author.last_name),
&body,
)
}
Err(e) => format::error(e),
}
}
}
@@ -1,80 +0,0 @@
use super::format::{self, line, page};
use crate::{
datasources::comments::CommentsDatasource, models::comments::Comment, state::AppState,
};
use gemi::{GeminiRequest, GeminiResponse, GeminiRouter, Params, State};
pub struct CommentsGeminiRoutes;
impl CommentsGeminiRoutes {
pub fn routes() -> gemi::Result<GeminiRouter<AppState>> {
let mut router = GeminiRouter::default();
router.add_route("/post/{id}", Self::post)?;
router.add_route("/index", Self::index)?;
Ok(router)
}
async fn post(State(state): State<AppState>, params: Params) -> GeminiResponse {
let id = match format::id(&params) {
Ok(id) => id,
Err(e) => return e,
};
let pool = state.lock().await.database.clone();
match CommentsDatasource::get_posts_comments(&pool, id).await {
Ok(comments) => page(
"Comments",
&format!(
"{}\n=> /posts/{id} Back to post\n=> {} Leave a comment on the web",
render(&comments),
format::web_url(&format!("/posts/{id}"))
),
),
Err(e) => format::error(e),
}
}
async fn index(State(state): State<AppState>, request: GeminiRequest) -> GeminiResponse {
let p = match format::pagination(&request) {
Ok(p) => p,
Err(e) => return e,
};
let pool = state.lock().await.database.clone();
let result = CommentsDatasource::get_index_comments(
&pool,
crate::utils::pagination::Pagination {
page: p.page,
limit: p.limit,
},
)
.await;
match result {
Ok(comments) => page(
"Recent comments",
&format!(
"{}{}",
render(&comments),
format::navigation("/comments/index", &p, comments.len() as i64 == p.limit)
),
),
Err(e) => format::error(e),
}
}
}
fn render(comments: &[Comment]) -> String {
if comments.is_empty() {
return "No comments yet.\n".into();
}
comments
.iter()
.map(|c| {
format!(
"## {}\n{}\n{}\n\n",
line(&c.name),
c.created_at
.map(|d| d.format("%B %d, %Y").to_string())
.unwrap_or_default(),
line(&c.body)
)
})
.collect()
}
-156
View File
@@ -1,156 +0,0 @@
use crate::{models::posts::Post, utils::pagination::Pagination};
use gemi::{GeminiRequest, GeminiResponse, Params};
pub fn line(text: &str) -> String {
text.split_whitespace().collect::<Vec<_>>().join(" ")
}
pub fn web_url(path: &str) -> String {
format!(
"{}{}",
std::env::var("BASE_URI_WEB")
.unwrap_or_else(|_| "https://wyattjmiller.com".into())
.trim_end_matches('/'),
path
)
}
pub fn page(title: &str, body: &str) -> GeminiResponse {
format!("# {}\n\n=> / Home\n=> /posts Blog\n=> /projects Projects\n=> /contact Contact\n\n{}\n\n## Elsewhere\n=> /authors Authors\n=> {} RSS\n=> {} Sitemap\n=> mailto:wjmiller2016@gmail.com Email me\n\n© {} Miller Web Solutions. All Rights Reserved. Hosted by Akamai.\n",
line(title), body, web_url("/rss"), web_url("/sitemap"), chrono::Utc::now().format("%Y")).into()
}
pub fn posts(posts: &[Post]) -> String {
if posts.is_empty() {
return "No posts yet.\n".into();
}
posts
.iter()
.map(|p| {
let date = p
.publish_date
.or(p.created_at)
.map(|d| d.format("%B %d, %Y").to_string())
.unwrap_or_default();
format!(
"=> /posts/{} {}\n{} · {} {}\n\n",
p.post_id,
line(&p.title),
date,
line(p.first_name.as_deref().unwrap_or("")),
line(p.last_name.as_deref().unwrap_or(""))
)
})
.collect()
}
pub fn id(params: &Params) -> Result<i32, GeminiResponse> {
params
.0
.get("id")
.and_then(|s| s.parse::<i32>().ok())
.filter(|id| *id > 0)
.ok_or_else(|| GeminiResponse::bad_request("Expected a positive numeric ID"))
}
pub fn pagination(request: &GeminiRequest) -> Result<Pagination, GeminiResponse> {
let mut result = Pagination { page: 1, limit: 12 };
for (key, value) in request.url.query_pairs() {
let target = match key.as_ref() {
"page" => &mut result.page,
"limit" => &mut result.limit,
_ => continue,
};
*target = value
.parse::<i64>()
.ok()
.filter(|n| *n > 0)
.ok_or_else(|| {
GeminiResponse::bad_request("page and limit must be positive integers")
})?;
}
if result.limit > 100 || result.page.checked_mul(result.limit).is_none() {
return Err(GeminiResponse::bad_request(
"Pagination out of range (maximum limit: 100)",
));
}
Ok(result)
}
pub fn navigation(path: &str, p: &Pagination, has_next: bool) -> String {
let mut result = format!("\nPage {}\n", p.page);
if p.page > 1 {
result += &format!(
"=> {path}?page={}&limit={} Previous page\n",
p.page - 1,
p.limit
);
}
if has_next {
result += &format!(
"=> {path}?page={}&limit={} Next page\n",
p.page + 1,
p.limit
);
}
result
}
pub fn error(error: sqlx::Error) -> GeminiResponse {
match error {
sqlx::Error::RowNotFound => GeminiResponse::not_found("Not found"),
error => {
tracing::error!(%error, "Gemini database request failed");
GeminiResponse::temporary_failure("Unable to load this page. Please try again later.")
}
}
}
#[cfg(test)]
mod tests {
use super::*;
fn request(query: &str) -> GeminiRequest {
let url = format!("gemini://localhost/authors?{query}")
.parse()
.unwrap();
GeminiRequest {
url,
path: "/authors".into(),
query: Some(query.into()),
}
}
#[test]
fn pagination_rejects_invalid_and_overflowing_values() {
for query in [
"page=0",
"page=-1",
"limit=101",
"limit=no",
"page=9223372036854775807&limit=100",
] {
assert!(pagination(&request(query)).is_err(), "{query}");
}
let p = pagination(&request("page=2&limit=10")).ok().unwrap();
assert_eq!((p.page, p.limit), (2, 10));
let links = navigation("/authors/1", &p, true);
assert!(links.contains("/authors/1?page=1&limit=10"));
assert!(links.contains("/authors/1?page=3&limit=10"));
}
#[test]
fn metadata_cannot_inject_gemtext_lines() {
assert_eq!(line("Title\r\n=> /evil link"), "Title => /evil link");
let response = page("Title\n# Injected", "Article body");
let body = String::from_utf8(response.body).unwrap();
assert!(body.starts_with("# Title # Injected\n"));
assert!(body.contains("=> /posts Blog\n"));
}
#[test]
fn missing_rows_and_database_failures_have_distinct_statuses() {
assert_eq!(error(sqlx::Error::RowNotFound).status_code.to_u8(), 51);
assert_eq!(error(sqlx::Error::PoolClosed).status_code.to_u8(), 40);
}
}
-27
View File
@@ -1,27 +0,0 @@
pub mod authors;
pub mod comments;
mod format;
pub mod posts;
pub mod projects;
pub mod root;
use crate::state::AppState;
use gemi::GeminiRouter;
pub fn routes() -> gemi::Result<GeminiRouter<AppState>> {
let mut router = GeminiRouter::default();
router.nest("/", root::RootGeminiRoutes::routes()?)?;
router.nest("/posts", posts::PostsGeminiRoutes::routes()?)?;
router.nest("/authors", authors::AuthorsGeminiRoutes::routes()?)?;
router.nest("/projects", projects::ProjectsGeminiRoutes::routes()?)?;
router.nest("/comments", comments::CommentsGeminiRoutes::routes()?)?;
Ok(router)
}
#[cfg(test)]
mod tests {
#[test]
fn routers_compose_without_conflicts() {
assert!(super::routes().is_ok());
}
}
-110
View File
@@ -1,110 +0,0 @@
use super::format::{self, page, posts};
use crate::{datasources::posts::PostsDatasource, state::AppState};
use gemi::{GeminiResponse, GeminiRouter, Params, State};
pub struct PostsGeminiRoutes;
impl PostsGeminiRoutes {
pub fn routes() -> gemi::Result<GeminiRouter<AppState>> {
let mut router = GeminiRouter::default();
router.add_route("/", Self::index)?;
router.add_route("/{id}", Self::get_one)?;
router.add_route("/all", Self::all)?;
router.add_route("/recent", Self::recent)?;
router.add_route("/featured", Self::featured)?;
router.add_route("/popular", Self::popular)?;
router.add_route("/hot", Self::hot)?;
Ok(router)
}
async fn index(State(state): State<AppState>) -> GeminiResponse {
let pool = state.lock().await.database.clone();
let result = tokio::try_join!(
PostsDatasource::get_featured(&pool),
PostsDatasource::get_recent(&pool),
PostsDatasource::get_popular(&pool)
);
match result {
Ok((featured, recent, popular)) => page("Blog", &format!("## Featured Posts\nIgnite the impossible\n\n{}## Recent Posts\nNow with 100% fresh perspective\n\n{}## Popular Posts\nContent may cause uncontrollable reading\n\n{}=> /posts/all All posts\n=> /posts/hot Hot posts", posts(&featured), posts(&recent), posts(&popular))),
Err(e) => format::error(e),
}
}
async fn get_one(State(state): State<AppState>, params: Params) -> GeminiResponse {
let id = match format::id(&params) {
Ok(id) => id,
Err(e) => return e,
};
let pool = state.lock().await.database.clone();
match PostsDatasource::get_one(&pool, id).await {
Ok(post) => {
let name = format::line(&format!(
"{} {}",
post.first_name.as_deref().unwrap_or(""),
post.last_name.as_deref().unwrap_or("")
));
let mut body = String::new();
if let Some(author_id) = post.author_id {
body += &format!("=> /authors/{author_id} By {name}\n");
}
if let Some(date) = post.publish_date.or(post.created_at) {
body += &format!("Published {}\n", date.format("%B %d, %Y"));
}
if post.is_featured == Some(true) {
body += "Featured post\n";
}
body += "\n";
match post
.body_gemtext
.as_deref()
.filter(|s| !s.trim().is_empty())
{
Some(gemtext) => body += gemtext,
None => {
body += &format!(
"This post is available on the web.\n=> {} Read this post",
format::web_url(&format!("/posts/{id}"))
)
}
}
body += &format!("\n\n=> /comments/post/{id} Comments\n=> /posts Back to the blog");
page(&post.title, &body)
}
Err(e) => format::error(e),
}
}
async fn all(State(state): State<AppState>) -> GeminiResponse {
let pool = state.lock().await.database.clone();
match PostsDatasource::get_all(&pool).await {
Ok(items) => page("All posts", &posts(&items)),
Err(e) => format::error(e),
}
}
async fn recent(State(state): State<AppState>) -> GeminiResponse {
let pool = state.lock().await.database.clone();
match PostsDatasource::get_recent(&pool).await {
Ok(items) => page("Recent Posts", &posts(&items)),
Err(e) => format::error(e),
}
}
async fn featured(State(state): State<AppState>) -> GeminiResponse {
let pool = state.lock().await.database.clone();
match PostsDatasource::get_featured(&pool).await {
Ok(items) => page("Featured Posts", &posts(&items)),
Err(e) => format::error(e),
}
}
async fn popular(State(state): State<AppState>) -> GeminiResponse {
let pool = state.lock().await.database.clone();
match PostsDatasource::get_popular(&pool).await {
Ok(items) => page("Popular Posts", &posts(&items)),
Err(e) => format::error(e),
}
}
async fn hot(State(state): State<AppState>) -> GeminiResponse {
let pool = state.lock().await.database.clone();
match PostsDatasource::get_hot(&pool).await {
Ok(items) => page("Hot Posts", &posts(&items)),
Err(e) => format::error(e),
}
}
}
@@ -1,46 +0,0 @@
use super::format::{self, line, page};
use crate::{datasources::projects::ProjectsDatasource, state::AppState};
use gemi::{GeminiResponse, GeminiRouter, State};
pub struct ProjectsGeminiRoutes;
impl ProjectsGeminiRoutes {
pub fn routes() -> gemi::Result<GeminiRouter<AppState>> {
let mut router = GeminiRouter::default();
router.add_route("/", Self::all)?;
Ok(router)
}
async fn all(State(state): State<AppState>) -> GeminiResponse {
let pool = state.lock().await.database.clone();
match ProjectsDatasource::get_all(&pool).await {
Ok(projects) => {
let mut body = String::from("Here's a collection of software and electronics projects I've been tinkering with during my free time - some are ongoing adventures, others are finished experiments!\n\n");
if projects.is_empty() {
body += "No projects yet.\n";
}
for project in projects {
body += &format!(
"## {}\n{}\nTechnology: {}\nStatus: {}\n",
line(&project.title),
line(&project.summary),
line(&project.tech),
if project.wip.unwrap_or(true) {
"Work in progress"
} else {
"Complete"
}
);
if let Some(repo) = project
.repo
.filter(|r| !r.is_empty() && !r.chars().any(char::is_whitespace))
{
body += &format!("=> {repo} Repository\n");
}
body += "\n";
}
page("Projects", &body)
}
Err(e) => format::error(e),
}
}
}
-26
View File
@@ -1,26 +0,0 @@
use super::format::{page, web_url};
use crate::state::AppState;
use gemi::{GeminiResponse, GeminiRouter};
pub struct RootGeminiRoutes;
impl RootGeminiRoutes {
pub fn routes() -> gemi::Result<GeminiRouter<AppState>> {
let mut router = GeminiRouter::default();
router.add_route("/", Self::root)?;
router.add_route("/contact", Self::contact)?;
router.add_route("/health", Self::health)?;
Ok(router)
}
async fn root() -> GeminiResponse {
page("Heya! I'm Wyatt", "## Thanks for checking out this corner of the Internet!\n\nI design and develop software for developers, for end users, and everyone in between")
}
async fn contact() -> GeminiResponse {
page("Contact", &format!("Got a question? Here to yell at me? Send me something!\n\n=> mailto:wjmiller2016@gmail.com Email me\n=> {} Contact form on the web", web_url("/contact")))
}
async fn health() -> GeminiResponse {
GeminiResponse::text("OK")
}
}
-5
View File
@@ -1,5 +0,0 @@
pub mod authors;
pub mod comments;
pub mod posts;
pub mod projects;
pub mod root;
-253
View File
@@ -1,253 +0,0 @@
use crate::{
datasources::posts::PostsDatasource,
models::posts::*,
services::posts::*,
state::AppState,
utils::{
rss,
sitemap::{self, SitemapEntry},
},
};
use axum::http::{HeaderMap, HeaderValue};
use axum::{
extract::{Path, State},
http::{header, StatusCode},
response::IntoResponse,
routing::get,
Json, Router,
};
use cache::Expiration;
use std::collections::HashMap;
pub struct PostsRoute;
impl PostsRoute {
pub fn routes(app_state: &AppState) -> Router {
// add more post routes here!
Router::new()
.route("/posts/all", get(PostsRoute::get_all))
.route("/posts/{id}", get(PostsRoute::get_one))
.route("/posts/recent", get(PostsRoute::get_recent_posts))
.route("/posts/popular", get(PostsRoute::get_popular_posts))
.route("/posts/hot", get(PostsRoute::get_hot_posts))
.route("/posts/featured", get(PostsRoute::get_featured_posts))
.route("/posts/rss", get(PostsRoute::get_rss_posts))
.route("/posts/sitemap", get(PostsRoute::get_sitemap))
.with_state(app_state.clone())
}
// get all posts
async fn get_all(State(app_state): State<AppState>) -> impl IntoResponse {
let mut state = app_state.lock().await;
let cached = posts_cache::<Vec<Post>>(&mut state, String::from("all")).await;
if let Some(posts) = cached {
return Ok(Json(posts));
};
match PostsDatasource::get_all(&state.database).await {
Ok(posts) => {
set_posts_cache(
&app_state,
String::from("all"),
posts.clone(),
Expiration::EX(10),
);
Ok(Json(posts))
}
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
}
}
// get one post
async fn get_one(
State(app_state): State<AppState>,
Path(params): Path<PostGetOneParams>,
) -> impl IntoResponse {
let mut state = app_state.lock().await;
let cached = posts_cache::<PostFeaturedVariant>(&mut state, params.id.to_string()).await;
if let Some(post) = cached {
return Ok(Json(post));
};
match PostsDatasource::get_one(&state.database, params.id).await {
Ok(post) => {
set_posts_cache(
&app_state,
params.id.to_string(),
post.clone(),
Expiration::EX(10),
);
Ok(Json(post))
}
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
}
}
// get recent posts
async fn get_recent_posts(State(app_state): State<AppState>) -> impl IntoResponse {
let mut state = app_state.lock().await;
let cached = posts_cache::<Vec<Post>>(&mut state, String::from("recent")).await;
if let Some(posts) = cached {
return Ok(Json(posts));
};
match PostsDatasource::get_recent(&state.database).await {
Ok(posts) => {
set_posts_cache(
&app_state,
String::from("recent"),
posts.clone(),
Expiration::EX(5),
);
Ok(Json(posts))
}
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
}
}
// get the top three posts with the highest view count
async fn get_popular_posts(State(app_state): State<AppState>) -> impl IntoResponse {
let mut state = app_state.lock().await;
let cached = posts_cache::<Vec<Post>>(&mut state, String::from("popular")).await;
if let Some(posts) = cached {
return Ok(Json(posts));
};
match PostsDatasource::get_popular(&state.database).await {
Ok(posts) => {
set_posts_cache(
&app_state,
String::from("popular"),
posts.clone(),
Expiration::EX(5),
);
Ok(Json(posts))
}
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
}
}
// get the top three posts with the most comments
async fn get_hot_posts(State(app_state): State<AppState>) -> impl IntoResponse {
let mut state = app_state.lock().await;
let cached = posts_cache::<Vec<Post>>(&mut state, String::from("hot")).await;
if let Some(posts) = cached {
return Ok(Json(posts));
};
match PostsDatasource::get_hot(&state.database).await {
Ok(posts) => {
set_posts_cache(
&app_state,
String::from("hot"),
posts.clone(),
Expiration::EX(5),
);
Ok(Json(posts))
}
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
}
}
// get posts that are featured
async fn get_featured_posts(State(app_state): State<AppState>) -> impl IntoResponse {
let mut state = app_state.lock().await;
let cached = posts_cache::<Vec<Post>>(&mut state, String::from("featured")).await;
if let Some(posts) = cached {
return Ok(Json(posts));
};
match PostsDatasource::get_featured(&state.database).await {
Ok(posts) => {
set_posts_cache(
&app_state,
String::from("featured"),
posts.clone(),
Expiration::EX(5),
);
Ok(Json(posts))
}
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
}
}
// get rss posts
async fn get_rss_posts(State(app_state): State<AppState>) -> impl IntoResponse {
let state = app_state.lock().await;
match PostsDatasource::get_all(&state.database).await {
Ok(posts) => {
let web_url =
std::env::var("BASE_URI_WEB").expect("Environment BASE_URI_WEB variable found");
let mapped_posts: HashMap<String, Post> = posts
.into_iter()
.map(|post| (post.post_id.to_string(), post))
.collect();
let xml: String = rss::generate_rss(
"Wyatt's blog",
"Wyatt and friends",
web_url.as_str(),
&mapped_posts,
);
let mut headers = HeaderMap::new();
headers.insert(
header::CONTENT_TYPE,
HeaderValue::from_static("application/xml"),
);
(headers, xml)
}
Err(e) => {
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("text/plain"));
(headers, e.to_string())
}
}
}
async fn get_sitemap(State(app_state): State<AppState>) -> impl IntoResponse {
let state = app_state.lock().await;
// let cached: Option<Vec<Post>> = None; // TODO: maybe implement cache, later??
match PostsDatasource::get_all(&state.database).await {
Ok(posts) => {
let web_url =
std::env::var("BASE_URI_WEB").expect("Environment BASE_URI_WEB variable found");
let mut entries: HashMap<String, SitemapEntry> = posts
.into_iter()
.map(|p| {
(
p.post_id.to_string(),
SitemapEntry {
location: format!("{}/posts/{}", web_url, p.post_id.to_string()),
lastmod: p.created_at.unwrap_or_else(|| chrono::Utc::now()),
},
)
})
.collect();
sitemap::get_static_pages(&mut entries, &web_url);
let xml: String = sitemap::generate_sitemap(&entries);
let mut headers = HeaderMap::new();
headers.insert(
header::CONTENT_TYPE,
HeaderValue::from_static("application/xml"),
);
(headers, xml)
}
Err(e) => {
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("text/plain"));
(headers, e.to_string())
}
}
}
}
@@ -1,52 +0,0 @@
use crate::{
datasources::projects::ProjectsDatasource,
state::AppState,
services::projects::*,
models::projects::*
};
use axum::{
extract::State,
http::StatusCode,
response::IntoResponse,
routing::get,
Json,
Router
};
use cache::Expiration;
pub struct ProjectsRoute;
impl ProjectsRoute {
pub fn routes(app_state: &AppState) -> Router {
Router::new()
.route("/projects", get(ProjectsRoute::get_all))
.with_state(app_state.clone())
}
async fn get_all(State(app_state): State<AppState>) -> impl IntoResponse {
let mut state = app_state.lock().await;
let cached = projects_cache::<Vec<Project>>(&mut state, String::from("all")).await;
if let Some(projects) = cached {
return Ok(Json(projects));
};
match ProjectsDatasource::get_all(&state.database).await {
Ok(projects) => {
if let p = &projects {
let projects = p.clone();
set_projects_cache(
&app_state,
String::from("all"),
projects.clone(),
Expiration::EX(10),
);
};
Ok(Json(projects))
}
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
}
}
}
+5 -2
View File
@@ -1,2 +1,5 @@
pub mod http;
pub mod gemini;
pub mod authors;
pub mod comments;
pub mod posts;
pub mod projects;
pub mod root;
+407
View File
@@ -0,0 +1,407 @@
use crate::{
datasources::posts::PostsDatasource,
state::AppState,
utils::{
datetime::*,
rss,
sitemap::{self, SitemapEntry},
},
};
use axum::http::{HeaderMap, HeaderValue};
use axum::{
extract::{Path, State},
http::{header, StatusCode},
response::IntoResponse,
routing::get,
Json, Router,
};
use cache::Expiration;
use chrono::Utc;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(sqlx::FromRow, Deserialize, Serialize, Debug, Clone)]
pub struct Post {
pub post_id: i32,
pub author_id: Option<i32>,
pub first_name: Option<String>,
pub last_name: Option<String>,
pub title: String,
pub body: String,
#[serde(serialize_with = "serialize_datetime")]
#[serde(deserialize_with = "deserialize_datetime")]
pub created_at: Option<chrono::DateTime<Utc>>,
#[serde(serialize_with = "serialize_datetime")]
#[serde(deserialize_with = "deserialize_datetime")]
pub publish_date: Option<chrono::DateTime<Utc>>,
}
#[derive(sqlx::FromRow, Deserialize, Serialize, Debug, Clone)]
pub struct PostFeaturedVariant {
pub post_id: i32,
pub author_id: Option<i32>,
pub first_name: Option<String>,
pub last_name: Option<String>,
pub title: String,
pub body: String,
#[serde(serialize_with = "serialize_datetime")]
#[serde(deserialize_with = "deserialize_datetime")]
pub created_at: Option<chrono::DateTime<Utc>>,
#[serde(serialize_with = "serialize_datetime")]
#[serde(deserialize_with = "deserialize_datetime")]
pub publish_date: Option<chrono::DateTime<Utc>>,
pub is_featured: Option<bool>,
}
#[derive(Deserialize)]
pub struct PostGetOneParams {
pub id: i32,
}
pub struct PostsRoute;
impl PostsRoute {
pub fn routes(app_state: &AppState) -> Router {
// add more post routes here!
Router::new()
.route("/posts/all", get(PostsRoute::get_all))
.route("/posts/{id}", get(PostsRoute::get_one))
.route("/posts/recent", get(PostsRoute::get_recent_posts))
.route("/posts/popular", get(PostsRoute::get_popular_posts))
.route("/posts/hot", get(PostsRoute::get_hot_posts))
.route("/posts/featured", get(PostsRoute::get_featured_posts))
.route("/posts/rss", get(PostsRoute::get_rss_posts))
.route("/posts/sitemap", get(PostsRoute::get_sitemap))
.with_state(app_state.clone())
}
// get all posts
async fn get_all(State(app_state): State<AppState>) -> impl IntoResponse {
let mut state = app_state.lock().await;
let cached: Option<Vec<Post>> = state
.cache
.get(String::from("posts:all"))
.await
.unwrap_or(None);
if let Some(posts) = cached {
tracing::info!("grabbing all posts from cache");
return Ok(Json(posts));
};
match PostsDatasource::get_all(&state.database).await {
Ok(posts) => {
tracing::info!("grabbing all posts from database");
if let p = &posts {
let posts = p.clone();
let state = app_state.clone();
tracing::info!("storing database data in cache");
tokio::spawn(async move {
let mut s = state.lock().await;
let _ = s
.cache
.set(
String::from("posts:all"),
&posts,
Some(Expiration::EX(10)),
None,
false,
)
.await;
});
};
Ok(Json(posts))
}
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
}
}
// get one post
async fn get_one(
State(app_state): State<AppState>,
Path(params): Path<PostGetOneParams>,
) -> impl IntoResponse {
let mut state = app_state.lock().await;
let cached: Option<PostFeaturedVariant> = state
.cache
.get(format!("posts:{}", params.id))
.await
.unwrap_or(None);
if let Some(post) = cached {
tracing::info!("grabbing one post from cache");
return Ok(Json(post));
};
match PostsDatasource::get_one(&state.database, params.id).await {
Ok(post) => {
tracing::info!("grabbing one post from database");
if let p = &post {
let post = p.clone();
let state = app_state.clone();
tracing::info!("storing database data in cache");
tokio::spawn(async move {
let mut s = state.lock().await;
let _ = s
.cache
.set(
format!("posts:{}", params.id),
&post,
Some(Expiration::EX(10)),
None,
false,
)
.await;
});
};
Ok(Json(post))
}
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
}
}
// get recent posts
async fn get_recent_posts(State(app_state): State<AppState>) -> impl IntoResponse {
let mut state = app_state.lock().await;
let cached: Option<Vec<Post>> = state
.cache
.get(String::from("posts:recent"))
.await
.unwrap_or(None);
if let Some(posts) = cached {
tracing::info!("grabbing recent posts from cache");
return Ok(Json(posts));
};
match PostsDatasource::get_recent(&state.database).await {
Ok(posts) => {
tracing::info!("grabbing recent posts from database");
if let p = &posts {
let posts = p.clone();
let state = app_state.clone();
tracing::info!("storing database data in cache");
tokio::spawn(async move {
let mut s = state.lock().await;
let _ = s
.cache
.set(
String::from("posts:recent"),
&posts,
Some(Expiration::EX(5)),
None,
false,
)
.await;
});
};
Ok(Json(posts))
}
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
}
}
// get the top three posts with the highest view count
async fn get_popular_posts(State(app_state): State<AppState>) -> impl IntoResponse {
let mut state = app_state.lock().await;
let cached: Option<Vec<Post>> = state
.cache
.get(String::from("posts:popular"))
.await
.unwrap_or(None);
if let Some(posts) = cached {
tracing::info!("grabbing popular posts from cache");
return Ok(Json(posts));
};
match PostsDatasource::get_popular(&state.database).await {
Ok(posts) => {
tracing::info!("grabbing popular posts from database");
if let p = &posts {
let posts = p.clone();
let state = app_state.clone();
tracing::info!("storing database data in cache");
tokio::spawn(async move {
let mut s = state.lock().await;
let _ = s
.cache
.set(
String::from("posts:popular"),
&posts,
Some(Expiration::EX(5)),
None,
false,
)
.await;
});
};
Ok(Json(posts))
}
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
}
}
// get the top three posts with the most comments
async fn get_hot_posts(State(app_state): State<AppState>) -> impl IntoResponse {
let mut state = app_state.lock().await;
let cached: Option<Vec<Post>> = state
.cache
.get(String::from("posts:hot"))
.await
.unwrap_or(None);
if let Some(posts) = cached {
tracing::info!("grabbing hot posts from cache");
return Ok(Json(posts));
};
match PostsDatasource::get_hot(&state.database).await {
Ok(posts) => {
tracing::info!("grabbing hot posts from database");
if let p = &posts {
let posts = p.clone();
let state = app_state.clone();
tracing::info!("storing database data in cache");
tokio::spawn(async move {
let mut s = state.lock().await;
let _ = s
.cache
.set(
String::from("posts:hot"),
&posts,
Some(Expiration::EX(5)),
None,
false,
)
.await;
});
};
Ok(Json(posts))
}
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
}
}
// get posts that are featured
async fn get_featured_posts(State(app_state): State<AppState>) -> impl IntoResponse {
let mut state = app_state.lock().await;
let cached: Option<Vec<Post>> = state
.cache
.get(String::from("posts:featured"))
.await
.unwrap_or(None);
if let Some(posts) = cached {
tracing::info!("grabbing featured posts from cache");
return Ok(Json(posts));
};
match PostsDatasource::get_featured(&state.database).await {
Ok(posts) => {
tracing::info!("grabbing featured posts from database");
if let p = &posts {
let posts = p.clone();
let state = app_state.clone();
tracing::info!("storing database data in cache");
tokio::spawn(async move {
let mut s = state.lock().await;
let _ = s
.cache
.set(
String::from("posts:featured"),
&posts,
Some(Expiration::EX(5)),
None,
false,
)
.await;
});
};
Ok(Json(posts))
}
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
}
}
// get rss posts
async fn get_rss_posts(State(app_state): State<AppState>) -> impl IntoResponse {
let state = app_state.lock().await;
match PostsDatasource::get_all(&state.database).await {
Ok(posts) => {
let web_url =
std::env::var("BASE_URI_WEB").expect("Environment BASE_URI_WEB variable found");
let mapped_posts: HashMap<String, Post> = posts
.into_iter()
.map(|post| (post.post_id.to_string(), post))
.collect();
let xml: String = rss::generate_rss(
"Wyatt's blog",
"Wyatt and friends",
web_url.as_str(),
&mapped_posts,
);
let mut headers = HeaderMap::new();
headers.insert(
header::CONTENT_TYPE,
HeaderValue::from_static("application/xml"),
);
(headers, xml)
}
Err(e) => {
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("text/plain"));
(headers, e.to_string())
}
}
}
async fn get_sitemap(State(app_state): State<AppState>) -> impl IntoResponse {
let state = app_state.lock().await;
// let cached: Option<Vec<Post>> = None; // TODO: maybe implement cache, later??
match PostsDatasource::get_all(&state.database).await {
Ok(posts) => {
let web_url =
std::env::var("BASE_URI_WEB").expect("Environment BASE_URI_WEB variable found");
let mut entries: HashMap<String, SitemapEntry> = posts
.into_iter()
.map(|p| {
(
p.post_id.to_string(),
SitemapEntry {
location: format!("{}/posts/{}", web_url, p.post_id.to_string()),
lastmod: p.created_at.unwrap_or_else(|| chrono::Utc::now()),
},
)
})
.collect();
sitemap::get_static_pages(&mut entries, &web_url);
let xml: String = sitemap::generate_sitemap(&entries);
let mut headers = HeaderMap::new();
headers.insert(
header::CONTENT_TYPE,
HeaderValue::from_static("application/xml"),
);
(headers, xml)
}
Err(e) => {
let mut headers = HeaderMap::new();
headers.insert("Content-Type", HeaderValue::from_static("text/plain"));
(headers, e.to_string())
}
}
}
}
+70
View File
@@ -0,0 +1,70 @@
use crate::{datasources::projects::ProjectsDatasource, state::AppState, utils::datetime::*};
use axum::{extract::State, http::StatusCode, response::IntoResponse, routing::get, Json, Router};
use cache::Expiration;
use serde::{Deserialize, Serialize};
#[derive(sqlx::FromRow, Deserialize, Serialize, Debug, Clone)]
pub struct Project {
pub project_id: i32,
pub title: String,
pub repo: Option<String>,
pub summary: String,
pub tech: String,
pub wip: Option<bool>,
#[serde(serialize_with = "serialize_datetime")]
#[serde(deserialize_with = "deserialize_datetime")]
pub created_at: Option<chrono::DateTime<chrono::Utc>>,
}
pub struct ProjectsRoute;
impl ProjectsRoute {
pub fn routes(app_state: &AppState) -> Router {
Router::new()
.route("/projects", get(ProjectsRoute::get_all))
.with_state(app_state.clone())
}
async fn get_all(State(app_state): State<AppState>) -> impl IntoResponse {
let mut state = app_state.lock().await;
let cached: Option<Vec<Project>> = state
.cache
.get(String::from("projects:all"))
.await
.unwrap_or(None);
if let Some(projects) = cached {
tracing::info!("grabbing all projects from cache");
return Ok(Json(projects));
};
match ProjectsDatasource::get_all(&state.database).await {
Ok(projects) => {
tracing::info!("grabbing all projects from database");
if let p = &projects {
let projects = p.clone();
let state = app_state.clone();
tracing::info!("storing database data in cache");
tokio::spawn(async move {
let mut s = state.lock().await;
let _ = s
.cache
.set(
String::from("projects:all"),
&projects,
Some(Expiration::EX(10)),
None,
false,
)
.await;
});
};
Ok(Json(projects))
}
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
}
}
}
File renamed without changes.
-35
View File
@@ -1,35 +0,0 @@
use cache::Expiration;
use crate::state::{AppInternalState, AppState};
use serde::de::DeserializeOwned;
use serde::Serialize;
pub async fn authors_cache<T: DeserializeOwned>(
app_state: &mut AppInternalState,
key: String,
) -> Option<T> {
app_state
.cache
.get(format!("authors:{key}"))
.await
.unwrap_or(None)
}
pub fn set_authors_cache<T>(app_state: &AppState, key: String, value: T, expiration: Expiration)
where
T: Serialize + DeserializeOwned + Send + Sync + 'static,
{
let app_state = app_state.clone();
tokio::spawn(async move {
let mut s = app_state.lock().await;
let _ = s
.cache
.set(
format!("authors:{key}"),
&value,
Some(expiration),
None,
false,
)
.await;
});
}
-3
View File
@@ -1,3 +0,0 @@
pub mod authors;
pub mod posts;
pub mod projects;
-34
View File
@@ -1,34 +0,0 @@
use crate::state::{AppInternalState, AppState};
use cache::Expiration;
use serde::{de::DeserializeOwned, Serialize};
pub async fn posts_cache<T: DeserializeOwned>(
app_state: &mut AppInternalState,
key: String,
) -> Option<T> {
app_state
.cache
.get(format!("posts:{key}"))
.await
.unwrap_or(None)
}
pub fn set_posts_cache<T>(app_state: &AppState, key: String, value: T, expiration: Expiration)
where
T: Serialize + DeserializeOwned + Send + Sync + 'static,
{
let app_state = app_state.clone();
tokio::spawn(async move {
let mut s = app_state.lock().await;
let _ = s
.cache
.set(
format!("posts:{key}"),
&value,
Some(expiration),
None,
false,
)
.await;
});
}
-35
View File
@@ -1,35 +0,0 @@
use cache::Expiration;
use crate::state::{AppInternalState, AppState};
use serde::de::DeserializeOwned;
use serde::Serialize;
pub async fn projects_cache<T: DeserializeOwned>(
app_state: &mut AppInternalState,
key: String,
) -> Option<T> {
app_state
.cache
.get(format!("projects:{key}"))
.await
.unwrap_or(None)
}
pub fn set_projects_cache<T>(app_state: &AppState, key: String, value: T, expiration: Expiration)
where
T: Serialize + DeserializeOwned + Send + Sync + 'static,
{
let app_state = app_state.clone();
tokio::spawn(async move {
let mut s = app_state.lock().await;
let _ = s
.cache
.set(
format!("projects:{key}"),
&value,
Some(expiration),
None,
false,
)
.await;
});
}
+1 -1
View File
@@ -1,4 +1,4 @@
use crate::models::posts;
use crate::routes::posts;
use std::collections::HashMap;
use xml::escape::escape_str_pcdata;
+14 -54
View File
@@ -727,7 +727,7 @@ version = "0.69.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088"
dependencies = [
"bitflags 2.9.1",
"bitflags",
"cexpr",
"clang-sys",
"itertools",
@@ -744,12 +744,6 @@ dependencies = [
"which",
]
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.9.1"
@@ -1462,12 +1456,6 @@ dependencies = [
"slab",
]
[[package]]
name = "gemtext"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2eb76a04b598440b386caa0893dd7b8228a4b555692d2e4f04636a238b5c4b5b"
[[package]]
name = "generic-array"
version = "0.14.7"
@@ -2006,7 +1994,7 @@ version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b86e202f00093dcba4275d4636b93ef9dd75d025ae560d2521b45ea28ab49013"
dependencies = [
"bitflags 2.9.1",
"bitflags",
"cfg-if",
"libc",
]
@@ -2207,16 +2195,6 @@ dependencies = [
"digest",
]
[[package]]
name = "md2gemtext"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ad2427c485f47550ea77fe0b17cb83d0ad26cee4311be1f42e7e676077e7ef0"
dependencies = [
"gemtext",
"pulldown-cmark",
]
[[package]]
name = "memchr"
version = "2.7.5"
@@ -2375,7 +2353,7 @@ version = "0.10.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8505734d46c8ab1e19a1dce3aef597ad87dcb4c37e7188231769bd6bd51cebf8"
dependencies = [
"bitflags 2.9.1",
"bitflags",
"cfg-if",
"foreign-types",
"libc",
@@ -2598,17 +2576,6 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "pulldown-cmark"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffade02495f22453cd593159ea2f59827aae7f53fa8323f756799b670881dcf8"
dependencies = [
"bitflags 1.3.2",
"memchr",
"unicase",
]
[[package]]
name = "quick-xml"
version = "0.31.0"
@@ -2809,7 +2776,7 @@ version = "0.5.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d04b7d0ee6b4a0207a0a7adb104d23ecb0b47d6beae7152d0fa34b692b29fd6"
dependencies = [
"bitflags 2.9.1",
"bitflags",
]
[[package]]
@@ -2988,7 +2955,7 @@ version = "0.38.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154"
dependencies = [
"bitflags 2.9.1",
"bitflags",
"errno",
"libc",
"linux-raw-sys 0.4.15",
@@ -3001,7 +2968,7 @@ version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8"
dependencies = [
"bitflags 2.9.1",
"bitflags",
"errno",
"libc",
"linux-raw-sys 0.9.4",
@@ -3157,7 +3124,7 @@ version = "2.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02"
dependencies = [
"bitflags 2.9.1",
"bitflags",
"core-foundation 0.9.4",
"core-foundation-sys",
"libc",
@@ -3170,7 +3137,7 @@ version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "271720403f46ca04f7ba6f55d438f8bd878d6b8ca0a1046e8228c4145bcbb316"
dependencies = [
"bitflags 2.9.1",
"bitflags",
"core-foundation 0.10.1",
"core-foundation-sys",
"libc",
@@ -3479,7 +3446,7 @@ checksum = "aa003f0038df784eb8fecbbac13affe3da23b45194bd57dba231c8f48199c526"
dependencies = [
"atoi",
"base64 0.22.1",
"bitflags 2.9.1",
"bitflags",
"byteorder",
"bytes",
"chrono",
@@ -3522,7 +3489,7 @@ checksum = "db58fcd5a53cf07c184b154801ff91347e4c30d17a3562a635ff028ad5deda46"
dependencies = [
"atoi",
"base64 0.22.1",
"bitflags 2.9.1",
"bitflags",
"byteorder",
"chrono",
"crc",
@@ -3651,7 +3618,7 @@ version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b"
dependencies = [
"bitflags 2.9.1",
"bitflags",
"core-foundation 0.9.4",
"system-configuration-sys",
]
@@ -3668,7 +3635,7 @@ dependencies = [
[[package]]
name = "task"
version = "0.2.0"
version = "0.1.0"
dependencies = [
"cache",
"chrono",
@@ -3676,7 +3643,6 @@ dependencies = [
"futures",
"job_scheduler",
"markdown",
"md2gemtext",
"once_cell",
"reqwest",
"serde",
@@ -3913,7 +3879,7 @@ version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2"
dependencies = [
"bitflags 2.9.1",
"bitflags",
"bytes",
"futures-util",
"http 1.3.1",
@@ -4061,12 +4027,6 @@ dependencies = [
"syn",
]
[[package]]
name = "unicase"
version = "2.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "357cc3acc6a036009fd6c973ed009037c732d60d0b4f6c673e9041497482a28f"
[[package]]
name = "unicode-bidi"
version = "0.3.18"
@@ -4680,7 +4640,7 @@ version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
dependencies = [
"bitflags 2.9.1",
"bitflags",
]
[[package]]
+1 -2
View File
@@ -1,6 +1,6 @@
[package]
name = "task"
version = "0.2.0"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -25,4 +25,3 @@ serde = { version = "*", features = ["derive"] }
serde_yml = "*"
tracing = "0.1"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
md2gemtext = "0.1.0"
+8 -9
View File
@@ -1,15 +1,14 @@
use std::fs;
use std::io::Read;
use crate::utils::task_log;
use chrono::DateTime;
use chrono::{DateTime, FixedOffset, Utc};
use serde::{Deserialize, Deserializer};
pub fn register(pool: &sqlx::Pool<sqlx::Postgres>) {
let p = pool.clone();
tokio::spawn(async move {
if let Err(error) = import_posts("/app/posts", &p).await {
tracing::error!(%error, "Post import failed");
}
let _ = import_posts("/app/posts", &p).await;
});
}
@@ -21,6 +20,9 @@ async fn import_posts(
// Start task logging
let task = task_log::start(1, pool).await?;
let options = MarkdownOptions {
options: markdown::Constructs::gfm(),
};
let entries = fs::read_dir(dir_path)?;
for entry_result in entries {
@@ -64,7 +66,6 @@ async fn import_posts(
let content =
markdown::to_html_with_options(&document.content, &markdown::Options::default());
let gemtext = md2gemtext::convert(&document.content).to_string();
let title = document.metadata.title;
let pub_date =
@@ -72,12 +73,11 @@ async fn import_posts(
let content_final = content.unwrap();
// Insert into database
let _ = sqlx::query_as::<_, InsertPosts>(
"INSERT INTO posts (title, body, body_gemtext, filename, publish_date, author_id) VALUES ($1, $2, $3, $4, $5, $6) RETURNING title, body, body_gemtext, filename, author_id"
let results = sqlx::query_as::<_, InsertPosts>(
"INSERT INTO posts (title, body, filename, publish_date, author_id) VALUES ($1, $2, $3, $4, $5) RETURNING title, body, filename, author_id"
)
.bind(title)
.bind(content_final)
.bind(gemtext)
.bind(file_name_str)
.bind(pub_date)
.bind(1) // Consider making author_id a parameter
@@ -111,7 +111,6 @@ struct FilenameExists {
struct InsertPosts {
title: String,
body: String,
body_gemtext: String,
filename: String,
author_id: i32,
}
Generated
+8 -8
View File
@@ -36,12 +36,12 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1793410479,
"narHash": "sha256-HzgjxrLY4AEc0044ZuM5CHbLSWLZgDlay1idmzvvpJs=",
"rev": "fa1373130d5a21c040a47c5dbe1913d59ed91808",
"revCount": 1017588,
"lastModified": 1794552581,
"narHash": "sha256-qXFIqA6FCcx7XeDzw0ZNlkDT9UiCzrNDwK8RuU8RcHM=",
"rev": "f1e5c356f35d07e7b71a6b5e6c9338e0b029e0c0",
"revCount": 1018525,
"type": "tarball",
"url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2605.1017588%2Brev-fa1373130d5a21c040a47c5dbe1913d59ed91808/01a1959c-245a-7673-9ea9-ccd89a1f8489/source.tar.gz"
"url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2605.1018525%2Brev-f1e5c356f35d07e7b71a6b5e6c9338e0b029e0c0/01a1d88e-e5f6-7ec2-a6ed-04208e104093/source.tar.gz"
},
"original": {
"type": "tarball",
@@ -63,11 +63,11 @@
]
},
"locked": {
"lastModified": 1793434469,
"narHash": "sha256-+sgVNI2c67di+XIeMaz5KSei4T65kX68s5Nl0E5Gzbc=",
"lastModified": 1794646145,
"narHash": "sha256-rpqDyUM/d5fACYB8W+wKxxO57ICWjjalzb2X25oFFkY=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "6ecf534a7c16e7c969f26838fdd8c93597ae93f3",
"rev": "5b87ee0513c29127a01ad06e9cb362ea5ce91e78",
"type": "github"
},
"original": {