tidy, buff the readme

This commit is contained in:
Joe Ardent 2024-03-17 15:54:03 -07:00
parent a0a5f8a575
commit 369915854c
2 changed files with 17 additions and 6 deletions

View File

@ -10,10 +10,21 @@ SQL checking macros, so your DB needs to have the tables to allow the SQL checks
## How does it work?
If you wish to use this on your webpage, just add the following lines to the page you want a counter
on:
If you wish to use this on your webpage, you need to add a couple lines. First, a "tracking pixel"
that registers the current page's view:
``` html
<img src=http://localhost:5000/hit style="visibility:hidden">
```
Then, some javascript to retrieve the hit counts:
``` html
help I don't know how to javascript, we need to get http://localhost:5000/hits/all (or 'day' or
'week'), and that will return the number of recorded hits for this page for that time period.
```
TODO!!!
It uses the `referer` header to get the page it was called from, and uses that as the key for
counting the hit.

View File

@ -22,7 +22,7 @@ async fn main() {
let pool = db().await;
let app = Router::new()
.route("/hit", get(count_hit))
.route("/hit", get(register_hit))
.route("/hits/:period", get(get_hits))
.with_state(pool.clone())
.into_make_service();
@ -35,7 +35,7 @@ async fn main() {
pool.close().await;
}
async fn count_hit(State(db): State<SqlitePool>, headers: HeaderMap) -> String {
async fn register_hit(State(db): State<SqlitePool>, headers: HeaderMap) -> String {
let now = chrono::Utc::now();
let referer = headers.get(REFERER);
let page = if let Some(referer) = referer {
@ -109,7 +109,7 @@ async fn get_period_hits(db: &SqlitePool, page: &str, when: &str) -> i32 {
)
.fetch_one(db)
.await
.unwrap_or(1)
.unwrap_or(0)
}
//-************************************************************************