49 changed files with 1856 additions and 912 deletions

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
name: Update flake lock
on:
schedule:
# Gitea cron schedules use UTC. 07:00 UTC is 03:00 EDT.
- cron: "0 7 * * 0"
workflow_dispatch:
permissions:
contents: write
jobs:
update-flake-lock:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Install upstream Nix
uses: cachix/install-nix-action@v31
- name: Update flake lock
run: nix flake update
- name: Commit and push changes
shell: bash
run: |
set -euo pipefail
if git diff --quiet -- flake.lock; then
echo "flake.lock is already up to date"
exit 0
fi
git config user.name "gitea-actions[bot]"
git config user.email "gitea-actions[bot]@noreply.localhost"
git add flake.lock
git commit -m "chore: update flake lock"
git push
@@ -1,6 +1,6 @@
{ {
"db_name": "PostgreSQL", "db_name": "PostgreSQL",
"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", "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",
"describe": { "describe": {
"columns": [ "columns": [
{ {
@@ -30,16 +30,21 @@
}, },
{ {
"ordinal": 5, "ordinal": 5,
"name": "body_gemtext",
"type_info": "Text"
},
{
"ordinal": 6,
"name": "created_at", "name": "created_at",
"type_info": "Timestamptz" "type_info": "Timestamptz"
}, },
{ {
"ordinal": 6, "ordinal": 7,
"name": "publish_date", "name": "publish_date",
"type_info": "Timestamptz" "type_info": "Timestamptz"
}, },
{ {
"ordinal": 7, "ordinal": 8,
"name": "author_id", "name": "author_id",
"type_info": "Int4" "type_info": "Int4"
} }
@@ -59,8 +64,9 @@
false, false,
true, true,
true, true,
true,
false false
] ]
}, },
"hash": "3831b52c2db3d1114c4b01a761c74168b66904bacff847844d463454b7fcde43" "hash": "1ae4bbbfd835587ea4389b3b4500d1b0f549d682f892a10586815014519bb8c4"
} }
@@ -0,0 +1,68 @@
{
"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",
"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": "24f4b8dd651c57a8cab3ffc2fae9bfe4cb276521854b2a0a0fba2e7081093421"
}
@@ -1,6 +1,6 @@
{ {
"db_name": "PostgreSQL", "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 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", "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",
"describe": { "describe": {
"columns": [ "columns": [
{ {
@@ -35,11 +35,16 @@
}, },
{ {
"ordinal": 6, "ordinal": 6,
"name": "body_gemtext",
"type_info": "Text"
},
{
"ordinal": 7,
"name": "created_at", "name": "created_at",
"type_info": "Timestamptz" "type_info": "Timestamptz"
}, },
{ {
"ordinal": 7, "ordinal": 8,
"name": "publish_date", "name": "publish_date",
"type_info": "Timestamptz" "type_info": "Timestamptz"
} }
@@ -55,8 +60,9 @@
false, false,
false, false,
true, true,
true,
true true
] ]
}, },
"hash": "49768c8b986078bdfaad191b3ea1f07ca033b2a734162a3f8fcf0ef0a44c1e7f" "hash": "4557c49e323c6b7c3246903e63e1c61c0f008e80308f65066bff7f4b70a8c7dd"
} }
@@ -0,0 +1,68 @@
{
"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", "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.created_at DESC LIMIT 10", "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",
"describe": { "describe": {
"columns": [ "columns": [
{ {
@@ -35,11 +35,16 @@
}, },
{ {
"ordinal": 6, "ordinal": 6,
"name": "body_gemtext",
"type_info": "Text"
},
{
"ordinal": 7,
"name": "created_at", "name": "created_at",
"type_info": "Timestamptz" "type_info": "Timestamptz"
}, },
{ {
"ordinal": 7, "ordinal": 8,
"name": "publish_date", "name": "publish_date",
"type_info": "Timestamptz" "type_info": "Timestamptz"
} }
@@ -55,8 +60,9 @@
false, false,
false, false,
true, true,
true,
true true
] ]
}, },
"hash": "053f5b53a743065aa0105903cdd0ec803861a2477c38a02754d2d350a34aaa68" "hash": "7998c2354eacb1cfbeece7dc001f57e0ce4d3ca15b28940a631cd249b72d6dc3"
} }
@@ -1,6 +1,6 @@
{ {
"db_name": "PostgreSQL", "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 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.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",
"describe": { "describe": {
"columns": [ "columns": [
{ {
@@ -35,11 +35,16 @@
}, },
{ {
"ordinal": 6, "ordinal": 6,
"name": "body_gemtext",
"type_info": "Text"
},
{
"ordinal": 7,
"name": "created_at", "name": "created_at",
"type_info": "Timestamptz" "type_info": "Timestamptz"
}, },
{ {
"ordinal": 7, "ordinal": 8,
"name": "publish_date", "name": "publish_date",
"type_info": "Timestamptz" "type_info": "Timestamptz"
} }
@@ -55,8 +60,9 @@
false, false,
false, false,
true, true,
true,
true true
] ]
}, },
"hash": "0ec6c9d94fceba56112e78c82acc56ae01bc3c641e28ee21e331c06e2fd9e551" "hash": "9cc954af48cf92abaa30a8d26499fded1ce30609c29b34d10cf98573d40bdbb6"
} }
@@ -1,62 +0,0 @@
{
"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 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": [
{
"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": "9d93a8a7c0a2442a511108af36d4adfb1ef8a2fac82448205654742f43dc4e75"
}
@@ -1,62 +0,0 @@
{
"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"
}
@@ -1,6 +1,6 @@
{ {
"db_name": "PostgreSQL", "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, 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.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",
"describe": { "describe": {
"columns": [ "columns": [
{ {
@@ -35,16 +35,21 @@
}, },
{ {
"ordinal": 6, "ordinal": 6,
"name": "body_gemtext",
"type_info": "Text"
},
{
"ordinal": 7,
"name": "created_at", "name": "created_at",
"type_info": "Timestamptz" "type_info": "Timestamptz"
}, },
{ {
"ordinal": 7, "ordinal": 8,
"name": "publish_date", "name": "publish_date",
"type_info": "Timestamptz" "type_info": "Timestamptz"
}, },
{ {
"ordinal": 8, "ordinal": 9,
"name": "is_featured", "name": "is_featured",
"type_info": "Bool" "type_info": "Bool"
} }
@@ -63,8 +68,9 @@
false, false,
true, true,
true, true,
true,
false false
] ]
}, },
"hash": "0891ec97ff1d5d5ab7fbc848ceb4e7ea4f46e2f6282170dfdf90ebc6ab6d5fd9" "hash": "fb4bcc2eb710ceb4bb50ec1c62326b7d709cd53d44944acc2da2e371642bfe1a"
} }
+376 -136
View File
@@ -2,21 +2,6 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 4 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]] [[package]]
name = "aho-corasick" name = "aho-corasick"
version = "1.1.3" version = "1.1.3"
@@ -53,6 +38,45 @@ version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" 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]] [[package]]
name = "async-trait" name = "async-trait"
version = "0.1.88" version = "0.1.88"
@@ -61,7 +85,7 @@ checksum = "e539d3fca749fcee5236ab05e93a52867dd549cc157c8cb7f99595f3cedffdb5"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.104",
] ]
[[package]] [[package]]
@@ -85,6 +109,29 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" 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]] [[package]]
name = "axum" name = "axum"
version = "0.7.9" version = "0.7.9"
@@ -194,21 +241,6 @@ dependencies = [
"tracing", "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]] [[package]]
name = "base64" name = "base64"
version = "0.22.1" version = "0.22.1"
@@ -278,10 +310,13 @@ dependencies = [
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.2.29" version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c1599538de2394445747c8cf7935946e3cc27e9625f889d979bfb2aaf569362" checksum = "375989decec1a0fa424442bed520fa12ede43a48475ce8c7417d2c69b32b5f6b"
dependencies = [ dependencies = [
"find-msvc-tools",
"jobserver",
"libc",
"shlex", "shlex",
] ]
@@ -302,7 +337,16 @@ dependencies = [
"js-sys", "js-sys",
"num-traits", "num-traits",
"wasm-bindgen", "wasm-bindgen",
"windows-link", "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",
] ]
[[package]] [[package]]
@@ -400,6 +444,12 @@ dependencies = [
"parking_lot_core", "parking_lot_core",
] ]
[[package]]
name = "data-encoding"
version = "2.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4583a4551df46e2792f82ceeac45e850d2e2d5debba0b91f102385cda5b11f06"
[[package]] [[package]]
name = "der" name = "der"
version = "0.7.10" version = "0.7.10"
@@ -411,6 +461,29 @@ dependencies = [
"zeroize", "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]] [[package]]
name = "digest" name = "digest"
version = "0.10.7" version = "0.10.7"
@@ -431,7 +504,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.104",
] ]
[[package]] [[package]]
@@ -440,6 +513,12 @@ version = "0.15.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b" checksum = "1aaf95b3e5c8f23aa320147307562d361db0ae0d51242340f558153b4eb2439b"
[[package]]
name = "dunce"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813"
[[package]] [[package]]
name = "either" name = "either"
version = "1.15.0" version = "1.15.0"
@@ -477,6 +556,12 @@ dependencies = [
"pin-project-lite", "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]] [[package]]
name = "float-cmp" name = "float-cmp"
version = "0.10.0" version = "0.10.0"
@@ -511,9 +596,9 @@ checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"
[[package]] [[package]]
name = "form_urlencoded" name = "form_urlencoded"
version = "1.2.1" version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf"
dependencies = [ dependencies = [
"percent-encoding", "percent-encoding",
] ]
@@ -546,7 +631,7 @@ dependencies = [
"rand", "rand",
"redis-protocol", "redis-protocol",
"semver", "semver",
"socket2", "socket2 0.5.10",
"tokio", "tokio",
"tokio-stream", "tokio-stream",
"tokio-util", "tokio-util",
@@ -562,9 +647,15 @@ checksum = "1458c6e22d36d61507034d5afecc64f105c1d39712b7ac6ec3b352c423f715cc"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.104",
] ]
[[package]]
name = "fs_extra"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
[[package]] [[package]]
name = "futures" name = "futures"
version = "0.3.31" version = "0.3.31"
@@ -632,7 +723,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.104",
] ]
[[package]] [[package]]
@@ -671,6 +762,26 @@ dependencies = [
"slab", "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]] [[package]]
name = "generic-array" name = "generic-array"
version = "0.14.7" version = "0.14.7"
@@ -693,10 +804,15 @@ dependencies = [
] ]
[[package]] [[package]]
name = "gimli" name = "getrandom"
version = "0.31.1" version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
dependencies = [
"cfg-if",
"libc",
"r-efi",
]
[[package]] [[package]]
name = "governor" name = "governor"
@@ -996,9 +1112,9 @@ dependencies = [
[[package]] [[package]]
name = "idna" name = "idna"
version = "1.0.3" version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de"
dependencies = [ dependencies = [
"idna_adapter", "idna_adapter",
"smallvec", "smallvec",
@@ -1025,23 +1141,22 @@ dependencies = [
"hashbrown 0.15.4", "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]] [[package]]
name = "itoa" name = "itoa"
version = "1.0.15" version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" 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]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.77" version = "0.3.77"
@@ -1063,9 +1178,9 @@ dependencies = [
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.174" version = "0.2.191"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
[[package]] [[package]]
name = "libm" name = "libm"
@@ -1126,6 +1241,12 @@ version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3"
[[package]]
name = "matchit"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8863b587001c1b9a8a4e36008cebc6b3612cb1226fe2de94858e06092687b608"
[[package]] [[package]]
name = "md-5" name = "md-5"
version = "0.10.6" version = "0.10.6"
@@ -1154,24 +1275,15 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "miniz_oxide"
version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316"
dependencies = [
"adler2",
]
[[package]] [[package]]
name = "mio" name = "mio"
version = "1.0.4" version = "1.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78bed444cc8a2160f01cbcf811ef18cac863ad68ae8ca62092e8db51d51c761c" checksum = "1788edb87fdc09c7e26304471e2f5be8cdefb1b6930d6e3985fc02ff53bf86ee"
dependencies = [ dependencies = [
"libc", "libc",
"wasi", "wasi",
"windows-sys 0.59.0", "windows-sys 0.61.2",
] ]
[[package]] [[package]]
@@ -1212,6 +1324,16 @@ dependencies = [
"winapi", "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]] [[package]]
name = "num-bigint-dig" name = "num-bigint-dig"
version = "0.8.4" version = "0.8.4"
@@ -1229,6 +1351,12 @@ dependencies = [
"zeroize", "zeroize",
] ]
[[package]]
name = "num-conv"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
[[package]] [[package]]
name = "num-integer" name = "num-integer"
version = "0.1.46" version = "0.1.46"
@@ -1260,12 +1388,12 @@ dependencies = [
] ]
[[package]] [[package]]
name = "object" name = "oid-registry"
version = "0.36.7" version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87" checksum = "12f40cff3dde1b6087cc5d5f5d4d65712f34016a03ed60e9c08dcc392736b5b7"
dependencies = [ dependencies = [
"memchr", "asn1-rs",
] ]
[[package]] [[package]]
@@ -1320,9 +1448,9 @@ dependencies = [
[[package]] [[package]]
name = "percent-encoding" name = "percent-encoding"
version = "2.3.1" version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"
[[package]] [[package]]
name = "pin-project" name = "pin-project"
@@ -1341,7 +1469,7 @@ checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.104",
] ]
[[package]] [[package]]
@@ -1398,6 +1526,12 @@ dependencies = [
"zerovec", "zerovec",
] ]
[[package]]
name = "powerfmt"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a6394b9e965e73d0a289ee54f589087e2c676aedf60885baf52c76b771e4958"
[[package]] [[package]]
name = "ppv-lite86" name = "ppv-lite86"
version = "0.2.21" version = "0.2.21"
@@ -1418,13 +1552,15 @@ dependencies = [
[[package]] [[package]]
name = "public" name = "public"
version = "0.1.0" version = "0.2.0"
dependencies = [ dependencies = [
"axum 0.8.4", "axum 0.8.4",
"cache", "cache",
"chrono", "chrono",
"dotenvy", "dotenvy",
"fred", "fred",
"gemi",
"rustls",
"serde", "serde",
"serde_json", "serde_json",
"sqlx", "sqlx",
@@ -1460,6 +1596,12 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "r-efi"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"
[[package]] [[package]]
name = "rand" name = "rand"
version = "0.8.5" version = "0.8.5"
@@ -1487,7 +1629,7 @@ version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [ dependencies = [
"getrandom", "getrandom 0.2.16",
] ]
[[package]] [[package]]
@@ -1574,7 +1716,7 @@ checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7"
dependencies = [ dependencies = [
"cc", "cc",
"cfg-if", "cfg-if",
"getrandom", "getrandom 0.2.16",
"libc", "libc",
"untrusted", "untrusted",
"windows-sys 0.52.0", "windows-sys 0.52.0",
@@ -1601,17 +1743,22 @@ dependencies = [
] ]
[[package]] [[package]]
name = "rustc-demangle" name = "rusticata-macros"
version = "0.1.25" version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "989e6739f80c4ad5b13e0fd7fe89531180375b18520cc8c82080e4dc4035b84f" checksum = "faf0c4a6ece9950b9abdb62b1cfcf2a68b3b67a10ba445b3bb85be2a293d0632"
dependencies = [
"nom",
]
[[package]] [[package]]
name = "rustls" name = "rustls"
version = "0.23.29" version = "0.23.46"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2491382039b29b9b11ff08b76ff6c97cf287671dbb74f0be44bda389fffe9bd1" checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf"
dependencies = [ dependencies = [
"aws-lc-rs",
"log",
"once_cell", "once_cell",
"ring", "ring",
"rustls-pki-types", "rustls-pki-types",
@@ -1622,19 +1769,20 @@ dependencies = [
[[package]] [[package]]
name = "rustls-pki-types" name = "rustls-pki-types"
version = "1.12.0" version = "1.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "229a4a4c221013e7e1f1a043678c5cc39fe5171437c88fb47151a21e6f5b5c79" checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96"
dependencies = [ dependencies = [
"zeroize", "zeroize",
] ]
[[package]] [[package]]
name = "rustls-webpki" name = "rustls-webpki"
version = "0.103.4" version = "0.103.16"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a17884ae0c1b773f1ccd2bd4a8c72f16da897310a98b0e84bf349ad5ead92fc" checksum = "4443b1b6d39d7c663139942cc4558262562d2c84123bb6282ef177009ca8b281"
dependencies = [ dependencies = [
"aws-lc-rs",
"ring", "ring",
"rustls-pki-types", "rustls-pki-types",
"untrusted", "untrusted",
@@ -1681,7 +1829,7 @@ checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.104",
] ]
[[package]] [[package]]
@@ -1751,9 +1899,9 @@ dependencies = [
[[package]] [[package]]
name = "shlex" name = "shlex"
version = "1.3.0" version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
[[package]] [[package]]
name = "signal-hook-registry" name = "signal-hook-registry"
@@ -1799,6 +1947,16 @@ dependencies = [
"windows-sys 0.52.0", "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]] [[package]]
name = "spin" name = "spin"
version = "0.9.8" version = "0.9.8"
@@ -1869,7 +2027,7 @@ dependencies = [
"serde_json", "serde_json",
"sha2", "sha2",
"smallvec", "smallvec",
"thiserror 2.0.12", "thiserror 2.0.21",
"tokio", "tokio",
"tokio-stream", "tokio-stream",
"tracing", "tracing",
@@ -1887,7 +2045,7 @@ dependencies = [
"quote", "quote",
"sqlx-core", "sqlx-core",
"sqlx-macros-core", "sqlx-macros-core",
"syn", "syn 2.0.104",
] ]
[[package]] [[package]]
@@ -1910,7 +2068,7 @@ dependencies = [
"sqlx-mysql", "sqlx-mysql",
"sqlx-postgres", "sqlx-postgres",
"sqlx-sqlite", "sqlx-sqlite",
"syn", "syn 2.0.104",
"tokio", "tokio",
"url", "url",
] ]
@@ -1953,7 +2111,7 @@ dependencies = [
"smallvec", "smallvec",
"sqlx-core", "sqlx-core",
"stringprep", "stringprep",
"thiserror 2.0.12", "thiserror 2.0.21",
"tracing", "tracing",
"whoami", "whoami",
] ]
@@ -1991,7 +2149,7 @@ dependencies = [
"smallvec", "smallvec",
"sqlx-core", "sqlx-core",
"stringprep", "stringprep",
"thiserror 2.0.12", "thiserror 2.0.21",
"tracing", "tracing",
"whoami", "whoami",
] ]
@@ -2016,7 +2174,7 @@ dependencies = [
"serde", "serde",
"serde_urlencoded", "serde_urlencoded",
"sqlx-core", "sqlx-core",
"thiserror 2.0.12", "thiserror 2.0.21",
"tracing", "tracing",
"url", "url",
] ]
@@ -2055,6 +2213,17 @@ dependencies = [
"unicode-ident", "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]] [[package]]
name = "sync_wrapper" name = "sync_wrapper"
version = "1.0.2" version = "1.0.2"
@@ -2069,7 +2238,7 @@ checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.104",
] ]
[[package]] [[package]]
@@ -2083,11 +2252,11 @@ dependencies = [
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "2.0.12" version = "2.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e"
dependencies = [ dependencies = [
"thiserror-impl 2.0.12", "thiserror-impl 2.0.21",
] ]
[[package]] [[package]]
@@ -2098,18 +2267,18 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.104",
] ]
[[package]] [[package]]
name = "thiserror-impl" name = "thiserror-impl"
version = "2.0.12" version = "2.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 3.0.9",
] ]
[[package]] [[package]]
@@ -2121,6 +2290,37 @@ dependencies = [
"cfg-if", "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]] [[package]]
name = "tinystr" name = "tinystr"
version = "0.8.1" version = "0.8.1"
@@ -2148,33 +2348,40 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.46.1" version = "1.54.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0cc3a2344dafbe23a245241fe8b09735b521110d30fcefbbd5feb1797ca35d17" checksum = "b52fd3255258d26fac7264ab5a76b53c13367136dc011d3d6ad4f8ed070396a3"
dependencies = [ dependencies = [
"backtrace",
"bytes", "bytes",
"io-uring",
"libc", "libc",
"mio", "mio",
"parking_lot", "parking_lot",
"pin-project-lite", "pin-project-lite",
"signal-hook-registry", "signal-hook-registry",
"slab", "socket2 0.6.5",
"socket2",
"tokio-macros", "tokio-macros",
"windows-sys 0.52.0", "windows-sys 0.61.2",
] ]
[[package]] [[package]]
name = "tokio-macros" name = "tokio-macros"
version = "2.5.0" version = "2.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "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",
] ]
[[package]] [[package]]
@@ -2263,9 +2470,9 @@ dependencies = [
[[package]] [[package]]
name = "tracing" name = "tracing"
version = "0.1.41" version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
dependencies = [ dependencies = [
"log", "log",
"pin-project-lite", "pin-project-lite",
@@ -2275,20 +2482,20 @@ dependencies = [
[[package]] [[package]]
name = "tracing-attributes" name = "tracing-attributes"
version = "0.1.30" version = "0.1.31"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81383ab64e72a7a8b8e13130c49e3dab29def6d0c7d76a03087b3cf71c5c6903" checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.104",
] ]
[[package]] [[package]]
name = "tracing-core" name = "tracing-core"
version = "0.1.34" version = "0.1.36"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678" checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"valuable", "valuable",
@@ -2364,13 +2571,14 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
[[package]] [[package]]
name = "url" name = "url"
version = "2.5.4" version = "2.5.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed"
dependencies = [ dependencies = [
"form_urlencoded", "form_urlencoded",
"idna", "idna",
"percent-encoding", "percent-encoding",
"serde",
] ]
[[package]] [[package]]
@@ -2437,7 +2645,7 @@ dependencies = [
"log", "log",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.104",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@@ -2459,7 +2667,7 @@ checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.104",
"wasm-bindgen-backend", "wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@@ -2541,7 +2749,7 @@ checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3"
dependencies = [ dependencies = [
"windows-implement", "windows-implement",
"windows-interface", "windows-interface",
"windows-link", "windows-link 0.1.3",
"windows-result", "windows-result",
"windows-strings", "windows-strings",
] ]
@@ -2554,7 +2762,7 @@ checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.104",
] ]
[[package]] [[package]]
@@ -2565,7 +2773,7 @@ checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.104",
] ]
[[package]] [[package]]
@@ -2574,13 +2782,19 @@ version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
[[package]]
name = "windows-link"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
[[package]] [[package]]
name = "windows-result" name = "windows-result"
version = "0.3.4" version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6"
dependencies = [ dependencies = [
"windows-link", "windows-link 0.1.3",
] ]
[[package]] [[package]]
@@ -2589,7 +2803,7 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57"
dependencies = [ dependencies = [
"windows-link", "windows-link 0.1.3",
] ]
[[package]] [[package]]
@@ -2619,6 +2833,15 @@ dependencies = [
"windows-targets 0.52.6", "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]] [[package]]
name = "windows-targets" name = "windows-targets"
version = "0.48.5" version = "0.48.5"
@@ -2746,6 +2969,23 @@ version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea2f10b9bb0928dfb1b42b65e1f9e36f7f54dbdf08457afefb38afcdec4fa2bb" 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]] [[package]]
name = "xml" name = "xml"
version = "0.8.20" version = "0.8.20"
@@ -2781,7 +3021,7 @@ checksum = "38da3c9736e16c5d3c8c597a9aaa5d1fa565d0532ae05e27c24aa62fb32c0ab6"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.104",
"synstructure", "synstructure",
] ]
@@ -2802,7 +3042,7 @@ checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.104",
] ]
[[package]] [[package]]
@@ -2822,7 +3062,7 @@ checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.104",
"synstructure", "synstructure",
] ]
@@ -2862,5 +3102,5 @@ checksum = "5b96237efa0c878c64bd89c436f661be4e46b2f3eff1ebb976f7ef2321d2f58f"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.104",
] ]
+3 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "public" name = "public"
version = "0.1.0" version = "0.2.0"
edition = "2021" edition = "2021"
authors = ["Wyatt J. Miller <wyatt@wyattjmiller.com"] authors = ["Wyatt J. Miller <wyatt@wyattjmiller.com"]
@@ -8,6 +8,7 @@ authors = ["Wyatt J. Miller <wyatt@wyattjmiller.com"]
[dependencies] [dependencies]
axum = { version = "0.8.4", features = ["http2", "tokio"] } axum = { version = "0.8.4", features = ["http2", "tokio"] }
gemi = "0.1.0"
tower-http = { version = "0.6.1", features = ["trace", "cors"] } tower-http = { version = "0.6.1", features = ["trace", "cors"] }
tower_governor = "0.4.2" tower_governor = "0.4.2"
tokio = { version = "1.40.0", features = ["full"] } tokio = { version = "1.40.0", features = ["full"] }
@@ -17,6 +18,7 @@ sqlx = { version = "0.8.2", features = [
"chrono", "chrono",
"json", "json",
] } ] }
rustls = { version = "0.23", default-features = false, features = ["ring", "std", "tls12"] }
tracing = "0.1" tracing = "0.1"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
dotenvy = "0.15.7" dotenvy = "0.15.7"
+22
View File
@@ -18,3 +18,25 @@ For `public` to work properly, please make sure to first create the `.env` file,
- `DATABASE_URL` - needed for connecting to Postgres - `DATABASE_URL` - needed for connecting to Postgres
- `REDIS_URL` - needed for connecting to the cache (Redis or Valkey) - `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 - `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,5 +1,22 @@
use std::path::PathBuf; 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 { pub fn config() -> Configuration {
Configuration { Configuration {
env: dotenvy::dotenv(), env: dotenvy::dotenv(),
+3 -3
View File
@@ -1,7 +1,7 @@
use sqlx::{Pool, Postgres}; use sqlx::{Pool, Postgres};
use crate::{ use crate::{
routes::{authors::Author, posts::Post}, models::{authors::Author, posts::Post},
utils::pagination::Pagination, utils::pagination::Pagination,
}; };
@@ -15,7 +15,7 @@ impl AuthorsDatasource {
sqlx::query_as!( sqlx::query_as!(
Author, Author,
"SELECT author_id, first_name, last_name, bio, image FROM authors ORDER BY created_at DESC LIMIT $1 OFFSET $2", "SELECT author_id, first_name, last_name, bio, image FROM authors ORDER BY created_at DESC LIMIT $1 OFFSET $2",
pagination.page, pagination.limit,
offset, offset,
) )
.fetch_all(pool) .fetch_all(pool)
@@ -53,7 +53,7 @@ impl AuthorsDatasource {
let posts_query = sqlx::query_as!( let posts_query = sqlx::query_as!(
Post, Post,
"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", "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",
author_id, author_id,
pagination.limit, pagination.limit,
offset, offset,
+2 -2
View File
@@ -1,5 +1,5 @@
use crate::{ use crate::{
routes::comments::{Comment, CommentInputPayload}, models::comments::{Comment, CommentInputPayload},
utils::pagination::Pagination, utils::pagination::Pagination,
}; };
use sqlx::{Pool, Postgres}; use sqlx::{Pool, Postgres};
@@ -29,7 +29,7 @@ impl CommentsDatasource {
pagination: Pagination, pagination: Pagination,
) -> Result<Vec<Comment>, sqlx::Error> { ) -> Result<Vec<Comment>, sqlx::Error> {
let offset: i64 = (pagination.page - 1) * pagination.limit; 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.page, offset) 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)
.fetch_all(pool) .fetch_all(pool)
.await .await
} }
+7 -7
View File
@@ -1,11 +1,11 @@
use sqlx::{Pool, Postgres}; use sqlx::{Pool, Postgres};
use crate::routes::posts::{Post, PostFeaturedVariant}; use crate::models::posts::{Post, PostFeaturedVariant};
pub struct PostsDatasource; pub struct PostsDatasource;
impl PostsDatasource { impl PostsDatasource {
pub async fn get_all(pool: &Pool<Postgres>) -> Result<Vec<Post>, sqlx::Error> { 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.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.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")
.fetch_all(pool) .fetch_all(pool)
.await .await
} }
@@ -19,31 +19,31 @@ impl PostsDatasource {
.execute(pool) .execute(pool)
.await; .await;
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) 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)
.fetch_one(pool) .fetch_one(pool)
.await .await
} }
pub async fn get_recent(pool: &Pool<Postgres>) -> Result<Vec<Post>, sqlx::Error> { 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.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.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")
.fetch_all(pool) .fetch_all(pool)
.await .await
} }
pub async fn get_popular(pool: &Pool<Postgres>) -> Result<Vec<Post>, sqlx::Error> { 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.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.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")
.fetch_all(pool) .fetch_all(pool)
.await .await
} }
pub async fn get_hot(pool: &Pool<Postgres>) -> Result<Vec<Post>, sqlx::Error> { 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.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.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")
.fetch_all(pool) .fetch_all(pool)
.await .await
} }
pub async fn get_featured(pool: &Pool<Postgres>) -> Result<Vec<Post>, sqlx::Error> { 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.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.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")
.fetch_all(pool) .fetch_all(pool)
.await .await
} }
+2 -2
View File
@@ -1,6 +1,6 @@
use sqlx::{FromRow, Pool, Postgres, Row}; use sqlx::{Pool, Postgres};
use crate::routes::projects::Project; use crate::models::projects::Project;
pub struct ProjectsDatasource; pub struct ProjectsDatasource;
impl ProjectsDatasource { impl ProjectsDatasource {
+35 -9
View File
@@ -1,4 +1,5 @@
use axum::Router; use axum::Router;
use gemi::{EndpointExt, GeminiConfig, GeminiServer};
use cache::ClientLike; use cache::ClientLike;
use config::config; use config::config;
use sqlx::postgres::PgPoolOptions; use sqlx::postgres::PgPoolOptions;
@@ -17,7 +18,9 @@ use tracing_subscriber::{filter, layer::SubscriberExt, prelude::*, util::Subscri
mod config; mod config;
mod datasources; mod datasources;
mod models;
mod routes; mod routes;
mod services;
mod state; mod state;
mod utils; mod utils;
@@ -115,22 +118,27 @@ async fn main() {
let app_state = Arc::new(Mutex::new(state::AppInternalState::new(pool, redis_pool))); let app_state = Arc::new(Mutex::new(state::AppInternalState::new(pool, redis_pool)));
// build our application with some routes // 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() let app = Router::new()
.merge(routes::root::RootRoute::routes()) .merge(routes::http::root::RootRoute::routes())
.merge(routes::posts::PostsRoute::routes(&app_state)) .merge(routes::http::posts::PostsRoute::routes(&state))
.merge(routes::comments::CommentsRoute::routes(&app_state)) .merge(routes::http::comments::CommentsRoute::routes(&state))
.merge(routes::authors::AuthorsRoute::routes(&app_state)) .merge(routes::http::authors::AuthorsRoute::routes(&state))
.merge(routes::projects::ProjectsRoute::routes(&app_state)) .merge(routes::http::projects::ProjectsRoute::routes(&state))
.layer(CorsLayer::permissive()) .layer(CorsLayer::permissive())
.layer( .layer(
TraceLayer::new_for_http() TraceLayer::new_for_http()
.make_span_with(trace::DefaultMakeSpan::new().level(tracing::Level::INFO)) .make_span_with(trace::DefaultMakeSpan::new().level(tracing::Level::INFO))
.on_response(trace::DefaultOnResponse::new().level(tracing::Level::INFO)), .on_response(trace::DefaultOnResponse::new().level(tracing::Level::INFO)),
) )
.fallback(routes::root::RootRoute::not_found); .fallback(routes::http::root::RootRoute::not_found);
//.layer(GovernorLayer {
// config: governor_conf,
//});
// run it with hyper // run it with hyper
let listener = TcpListener::bind("0.0.0.0:3000").await.unwrap(); let listener = TcpListener::bind("0.0.0.0:3000").await.unwrap();
@@ -139,6 +147,24 @@ async fn main() {
.with_graceful_shutdown(shutdown_signal()) .with_graceful_shutdown(shutdown_signal())
.await .await
.unwrap(); .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() { async fn shutdown_signal() {
+15
View File
@@ -0,0 +1,15 @@
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
@@ -0,0 +1,26 @@
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
@@ -0,0 +1,4 @@
pub mod authors;
pub mod posts;
pub mod projects;
pub mod comments;
+44
View File
@@ -0,0 +1,44 @@
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
@@ -0,0 +1,18 @@
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>>,
}
@@ -0,0 +1,93 @@
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),
}
}
}
@@ -0,0 +1,80 @@
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
@@ -0,0 +1,156 @@
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
@@ -0,0 +1,27 @@
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
@@ -0,0 +1,110 @@
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),
}
}
}
@@ -0,0 +1,46 @@
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
@@ -0,0 +1,26 @@
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")
}
}
@@ -10,24 +10,18 @@ use serde::{Deserialize, Serialize};
use crate::{ use crate::{
datasources::authors::AuthorsDatasource, datasources::authors::AuthorsDatasource,
routes::posts::Post, models::{
posts::Post,
authors::{
Author,
AuthorGetOneParams,
}
},
services::authors::*,
state::AppState, state::AppState,
utils::pagination::{Pagination, PaginationQuery}, 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)] #[derive(Deserialize, Serialize)]
pub struct AuthorPostsResponse { pub struct AuthorPostsResponse {
@@ -55,39 +49,19 @@ impl AuthorsRoute {
}; };
let mut state = app_state.lock().await; let mut state = app_state.lock().await;
let cached: Option<Vec<Author>> = state let cached = authors_cache::<Vec<Author>>(&mut state, String::from("all")).await;
.cache
.get(String::from("authors:all"))
.await
.unwrap_or(None);
if let Some(authors) = cached { if let Some(authors) = cached {
tracing::info!("grabbing all authors from cache");
return Ok(Json(authors)); return Ok(Json(authors));
} }
match AuthorsDatasource::get_all(&state.database, pagination).await { match AuthorsDatasource::get_all(&state.database, pagination).await {
Ok(authors) => { Ok(authors) => {
tracing::info!("grabbing all authors from the database"); set_authors_cache(
if let a = &authors { &app_state,
let author_cloned = a.clone(); String::from("all"),
let state = app_state.clone(); authors.clone(),
Expiration::EX(5),
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)) Ok(Json(authors))
} }
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())), Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
@@ -99,40 +73,21 @@ impl AuthorsRoute {
Path(params): Path<AuthorGetOneParams>, Path(params): Path<AuthorGetOneParams>,
) -> impl IntoResponse { ) -> impl IntoResponse {
let mut state = app_state.lock().await; let mut state = app_state.lock().await;
let cached: Option<Author> = state let cached = authors_cache::<Author>(&mut state, params.id.to_string()).await;
.cache
.get(format!("authors:{}", params.id))
.await
.unwrap_or(None);
if let Some(author) = cached { if let Some(author) = cached {
tracing::info!("grabbing one author from cache");
return Ok(Json(author)); return Ok(Json(author));
} }
match AuthorsDatasource::get_one(&state.database, params.id).await { match AuthorsDatasource::get_one(&state.database, params.id).await {
Ok(author) => { Ok(author) => {
tracing::info!("grabbing all authors from the database"); set_authors_cache(
if let a = &author { &app_state,
let author_cloned = a.clone(); author.author_id.to_string(),
let state = app_state.clone(); author.clone(),
Expiration::EX(5),
);
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)) Ok(Json(author))
} }
Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())), Err(e) => Err((StatusCode::INTERNAL_SERVER_ERROR, e.to_string())),
@@ -1,8 +1,8 @@
use crate::{ use crate::{
datasources::comments::CommentsDatasource, datasources::comments::CommentsDatasource,
models::comments::*,
state::AppState, state::AppState,
utils::{ utils::{
datetime::*,
pagination::{Pagination, PaginationQuery}, pagination::{Pagination, PaginationQuery},
}, },
}; };
@@ -14,29 +14,6 @@ use axum::{
Json, Json,
}; };
use cache::{Expiration, SetOptions}; 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; pub struct CommentsRoute;
impl CommentsRoute { impl CommentsRoute {
@@ -74,7 +51,6 @@ impl CommentsRoute {
let state = app_state.clone(); let state = app_state.clone();
tokio::spawn(async move { tokio::spawn(async move {
tracing::info!("update cache if key already exists!");
let mut s = state.lock().await; let mut s = state.lock().await;
let _ = s let _ = s
.cache .cache
+5
View File
@@ -0,0 +1,5 @@
pub mod authors;
pub mod comments;
pub mod posts;
pub mod projects;
pub mod root;
+253
View File
@@ -0,0 +1,253 @@
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())
}
}
}
}
@@ -0,0 +1,52 @@
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())),
}
}
}
File renamed without changes.
+2 -5
View File
@@ -1,5 +1,2 @@
pub mod authors; pub mod http;
pub mod comments; pub mod gemini;
pub mod posts;
pub mod projects;
pub mod root;
-407
View File
@@ -1,407 +0,0 @@
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
@@ -1,70 +0,0 @@
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())),
}
}
}
+35
View File
@@ -0,0 +1,35 @@
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
@@ -0,0 +1,3 @@
pub mod authors;
pub mod posts;
pub mod projects;
+34
View File
@@ -0,0 +1,34 @@
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
@@ -0,0 +1,35 @@
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::routes::posts; use crate::models::posts;
use std::collections::HashMap; use std::collections::HashMap;
use xml::escape::escape_str_pcdata; use xml::escape::escape_str_pcdata;
+54 -14
View File
@@ -727,7 +727,7 @@ version = "0.69.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088" checksum = "271383c67ccabffb7381723dea0672a673f292304fcb45c01cc648c7a8d58088"
dependencies = [ dependencies = [
"bitflags", "bitflags 2.9.1",
"cexpr", "cexpr",
"clang-sys", "clang-sys",
"itertools", "itertools",
@@ -744,6 +744,12 @@ dependencies = [
"which", "which",
] ]
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]] [[package]]
name = "bitflags" name = "bitflags"
version = "2.9.1" version = "2.9.1"
@@ -1456,6 +1462,12 @@ dependencies = [
"slab", "slab",
] ]
[[package]]
name = "gemtext"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2eb76a04b598440b386caa0893dd7b8228a4b555692d2e4f04636a238b5c4b5b"
[[package]] [[package]]
name = "generic-array" name = "generic-array"
version = "0.14.7" version = "0.14.7"
@@ -1994,7 +2006,7 @@ version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b86e202f00093dcba4275d4636b93ef9dd75d025ae560d2521b45ea28ab49013" checksum = "b86e202f00093dcba4275d4636b93ef9dd75d025ae560d2521b45ea28ab49013"
dependencies = [ dependencies = [
"bitflags", "bitflags 2.9.1",
"cfg-if", "cfg-if",
"libc", "libc",
] ]
@@ -2195,6 +2207,16 @@ dependencies = [
"digest", "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]] [[package]]
name = "memchr" name = "memchr"
version = "2.7.5" version = "2.7.5"
@@ -2353,7 +2375,7 @@ version = "0.10.73"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8505734d46c8ab1e19a1dce3aef597ad87dcb4c37e7188231769bd6bd51cebf8" checksum = "8505734d46c8ab1e19a1dce3aef597ad87dcb4c37e7188231769bd6bd51cebf8"
dependencies = [ dependencies = [
"bitflags", "bitflags 2.9.1",
"cfg-if", "cfg-if",
"foreign-types", "foreign-types",
"libc", "libc",
@@ -2576,6 +2598,17 @@ dependencies = [
"unicode-ident", "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]] [[package]]
name = "quick-xml" name = "quick-xml"
version = "0.31.0" version = "0.31.0"
@@ -2776,7 +2809,7 @@ version = "0.5.13"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d04b7d0ee6b4a0207a0a7adb104d23ecb0b47d6beae7152d0fa34b692b29fd6" checksum = "0d04b7d0ee6b4a0207a0a7adb104d23ecb0b47d6beae7152d0fa34b692b29fd6"
dependencies = [ dependencies = [
"bitflags", "bitflags 2.9.1",
] ]
[[package]] [[package]]
@@ -2955,7 +2988,7 @@ version = "0.38.44"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154"
dependencies = [ dependencies = [
"bitflags", "bitflags 2.9.1",
"errno", "errno",
"libc", "libc",
"linux-raw-sys 0.4.15", "linux-raw-sys 0.4.15",
@@ -2968,7 +3001,7 @@ version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8" checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8"
dependencies = [ dependencies = [
"bitflags", "bitflags 2.9.1",
"errno", "errno",
"libc", "libc",
"linux-raw-sys 0.9.4", "linux-raw-sys 0.9.4",
@@ -3124,7 +3157,7 @@ version = "2.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02"
dependencies = [ dependencies = [
"bitflags", "bitflags 2.9.1",
"core-foundation 0.9.4", "core-foundation 0.9.4",
"core-foundation-sys", "core-foundation-sys",
"libc", "libc",
@@ -3137,7 +3170,7 @@ version = "3.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "271720403f46ca04f7ba6f55d438f8bd878d6b8ca0a1046e8228c4145bcbb316" checksum = "271720403f46ca04f7ba6f55d438f8bd878d6b8ca0a1046e8228c4145bcbb316"
dependencies = [ dependencies = [
"bitflags", "bitflags 2.9.1",
"core-foundation 0.10.1", "core-foundation 0.10.1",
"core-foundation-sys", "core-foundation-sys",
"libc", "libc",
@@ -3446,7 +3479,7 @@ checksum = "aa003f0038df784eb8fecbbac13affe3da23b45194bd57dba231c8f48199c526"
dependencies = [ dependencies = [
"atoi", "atoi",
"base64 0.22.1", "base64 0.22.1",
"bitflags", "bitflags 2.9.1",
"byteorder", "byteorder",
"bytes", "bytes",
"chrono", "chrono",
@@ -3489,7 +3522,7 @@ checksum = "db58fcd5a53cf07c184b154801ff91347e4c30d17a3562a635ff028ad5deda46"
dependencies = [ dependencies = [
"atoi", "atoi",
"base64 0.22.1", "base64 0.22.1",
"bitflags", "bitflags 2.9.1",
"byteorder", "byteorder",
"chrono", "chrono",
"crc", "crc",
@@ -3618,7 +3651,7 @@ version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b"
dependencies = [ dependencies = [
"bitflags", "bitflags 2.9.1",
"core-foundation 0.9.4", "core-foundation 0.9.4",
"system-configuration-sys", "system-configuration-sys",
] ]
@@ -3635,7 +3668,7 @@ dependencies = [
[[package]] [[package]]
name = "task" name = "task"
version = "0.1.0" version = "0.2.0"
dependencies = [ dependencies = [
"cache", "cache",
"chrono", "chrono",
@@ -3643,6 +3676,7 @@ dependencies = [
"futures", "futures",
"job_scheduler", "job_scheduler",
"markdown", "markdown",
"md2gemtext",
"once_cell", "once_cell",
"reqwest", "reqwest",
"serde", "serde",
@@ -3879,7 +3913,7 @@ version = "0.6.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2" checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2"
dependencies = [ dependencies = [
"bitflags", "bitflags 2.9.1",
"bytes", "bytes",
"futures-util", "futures-util",
"http 1.3.1", "http 1.3.1",
@@ -4027,6 +4061,12 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "unicase"
version = "2.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "357cc3acc6a036009fd6c973ed009037c732d60d0b4f6c673e9041497482a28f"
[[package]] [[package]]
name = "unicode-bidi" name = "unicode-bidi"
version = "0.3.18" version = "0.3.18"
@@ -4640,7 +4680,7 @@ version = "0.39.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
dependencies = [ dependencies = [
"bitflags", "bitflags 2.9.1",
] ]
[[package]] [[package]]
+2 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "task" name = "task"
version = "0.1.0" version = "0.2.0"
edition = "2021" edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -25,3 +25,4 @@ serde = { version = "*", features = ["derive"] }
serde_yml = "*" serde_yml = "*"
tracing = "0.1" tracing = "0.1"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
md2gemtext = "0.1.0"
+9 -8
View File
@@ -1,14 +1,15 @@
use std::fs; use std::fs;
use std::io::Read;
use crate::utils::task_log; use crate::utils::task_log;
use chrono::{DateTime, FixedOffset, Utc}; use chrono::DateTime;
use serde::{Deserialize, Deserializer}; use serde::{Deserialize, Deserializer};
pub fn register(pool: &sqlx::Pool<sqlx::Postgres>) { pub fn register(pool: &sqlx::Pool<sqlx::Postgres>) {
let p = pool.clone(); let p = pool.clone();
tokio::spawn(async move { tokio::spawn(async move {
let _ = import_posts("/app/posts", &p).await; if let Err(error) = import_posts("/app/posts", &p).await {
tracing::error!(%error, "Post import failed");
}
}); });
} }
@@ -20,9 +21,6 @@ async fn import_posts(
// Start task logging // Start task logging
let task = task_log::start(1, pool).await?; let task = task_log::start(1, pool).await?;
let options = MarkdownOptions {
options: markdown::Constructs::gfm(),
};
let entries = fs::read_dir(dir_path)?; let entries = fs::read_dir(dir_path)?;
for entry_result in entries { for entry_result in entries {
@@ -66,6 +64,7 @@ async fn import_posts(
let content = let content =
markdown::to_html_with_options(&document.content, &markdown::Options::default()); markdown::to_html_with_options(&document.content, &markdown::Options::default());
let gemtext = md2gemtext::convert(&document.content).to_string();
let title = document.metadata.title; let title = document.metadata.title;
let pub_date = let pub_date =
@@ -73,11 +72,12 @@ async fn import_posts(
let content_final = content.unwrap(); let content_final = content.unwrap();
// Insert into database // Insert into database
let results = sqlx::query_as::<_, InsertPosts>( let _ = 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" "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"
) )
.bind(title) .bind(title)
.bind(content_final) .bind(content_final)
.bind(gemtext)
.bind(file_name_str) .bind(file_name_str)
.bind(pub_date) .bind(pub_date)
.bind(1) // Consider making author_id a parameter .bind(1) // Consider making author_id a parameter
@@ -111,6 +111,7 @@ struct FilenameExists {
struct InsertPosts { struct InsertPosts {
title: String, title: String,
body: String, body: String,
body_gemtext: String,
filename: String, filename: String,
author_id: i32, author_id: i32,
} }
Generated
+13 -13
View File
@@ -2,12 +2,12 @@
"nodes": { "nodes": {
"flake-schemas": { "flake-schemas": {
"locked": { "locked": {
"lastModified": 1721999734, "lastModified": 1780327564,
"narHash": "sha256-G5CxYeJVm4lcEtaO87LKzOsVnWeTcHGKbKxNamNWgOw=", "narHash": "sha256-HiRPtA0spK+Dkgbhz/1zW9glXxNVB+L4Rj2VYmdawb8=",
"rev": "0a5c42297d870156d9c57d8f99e476b738dcd982", "rev": "6cc9bd98891b1fc6bb2b8cb3277df8bc72799ca6",
"revCount": 75, "revCount": 149,
"type": "tarball", "type": "tarball",
"url": "https://api.flakehub.com/f/pinned/DeterminateSystems/flake-schemas/0.1.5/0190ef2f-61e0-794b-ba14-e82f225e55e6/source.tar.gz" "url": "https://api.flakehub.com/f/pinned/DeterminateSystems/flake-schemas/0.5.0/019e83cf-9af3-78b1-ac5b-70e68ad1efe1/source.tar.gz"
}, },
"original": { "original": {
"type": "tarball", "type": "tarball",
@@ -36,12 +36,12 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1752436162, "lastModified": 1793410479,
"narHash": "sha256-Kt1UIPi7kZqkSc5HVj6UY5YLHHEzPBkgpNUByuyxtlw=", "narHash": "sha256-HzgjxrLY4AEc0044ZuM5CHbLSWLZgDlay1idmzvvpJs=",
"rev": "dfcd5b901dbab46c9c6e80b265648481aafb01f8", "rev": "fa1373130d5a21c040a47c5dbe1913d59ed91808",
"revCount": 806304, "revCount": 1017588,
"type": "tarball", "type": "tarball",
"url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2505.806304%2Brev-dfcd5b901dbab46c9c6e80b265648481aafb01f8/01980f2c-e7f3-7efc-b369-7ebec7be6e59/source.tar.gz" "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2605.1017588%2Brev-fa1373130d5a21c040a47c5dbe1913d59ed91808/01a1959c-245a-7673-9ea9-ccd89a1f8489/source.tar.gz"
}, },
"original": { "original": {
"type": "tarball", "type": "tarball",
@@ -63,11 +63,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1752633862, "lastModified": 1793434469,
"narHash": "sha256-Bj7ozT1+5P7NmvDcuAXJvj56txcXuAhk3Vd9FdWFQzk=", "narHash": "sha256-+sgVNI2c67di+XIeMaz5KSei4T65kX68s5Nl0E5Gzbc=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "8668ca94858206ac3db0860a9dec471de0d995f8", "rev": "6ecf534a7c16e7c969f26838fdd8c93597ae93f3",
"type": "github" "type": "github"
}, },
"original": { "original": {