Compare commits
No commits in common. "54280087dc33f8de05330b61d78375757213f0df" and "66a59df6abad55be8277a5b357812229778b8d9f" have entirely different histories.
54280087dc
...
66a59df6ab
8 changed files with 7 additions and 54 deletions
|
@ -1,6 +1,5 @@
|
||||||
[sqlfluff]
|
[sqlfluff]
|
||||||
dialect = sqlite
|
dialect = sqlite
|
||||||
exclude_rules = references.special_chars
|
|
||||||
|
|
||||||
[sqlfluff:rules:capitalisation.keywords]
|
[sqlfluff:rules:capitalisation.keywords]
|
||||||
# Keywords
|
# Keywords
|
||||||
|
@ -13,6 +12,3 @@ align_within = create_table_statement
|
||||||
[sqlfluff:layout:type:data_type]
|
[sqlfluff:layout:type:data_type]
|
||||||
spacing_before = align
|
spacing_before = align
|
||||||
align_within = create_table_statement
|
align_within = create_table_statement
|
||||||
|
|
||||||
[sqlfluff:rules:layout.long_lines]
|
|
||||||
ignore_comment_lines = True
|
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
-- The funny alias used here is to allow sqlx to do type inference on columns
|
|
||||||
-- See: https://docs.rs/sqlx/latest/sqlx/macro.query_as.html#column-type-override-infer-from-struct-field
|
|
||||||
SELECT cache_name AS "cache_name: _"
|
|
||||||
FROM records;
|
|
|
@ -1,5 +0,0 @@
|
||||||
-- The funny alias used here is to allow sqlx to do type inference on columns
|
|
||||||
-- See: https://docs.rs/sqlx/latest/sqlx/macro.query_as.html#column-type-override-infer-from-struct-field
|
|
||||||
SELECT cache_name AS "cache_name: _"
|
|
||||||
FROM records
|
|
||||||
LIMIT ? OFFSET ?
|
|
21
src/db.rs
21
src/db.rs
|
@ -1,21 +0,0 @@
|
||||||
use chrono::{DateTime, Utc};
|
|
||||||
|
|
||||||
#[derive(sqlx::Type)]
|
|
||||||
pub struct CacheRecord {
|
|
||||||
pub cache_name: String,
|
|
||||||
pub uploaded: DateTime<Utc>,
|
|
||||||
// This uses i32 because of how sqlx decodes unsigned integers to sqlite
|
|
||||||
// See: https://docs.rs/sqlx/latest/sqlx/sqlite/types/index.html
|
|
||||||
pub downloads: i32,
|
|
||||||
pub max_downloads: i32,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct CacheRecordName {
|
|
||||||
pub cache_name: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<CacheRecordName> for String {
|
|
||||||
fn from(value: CacheRecordName) -> Self {
|
|
||||||
value.cache_name
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,4 @@
|
||||||
pub mod cache;
|
pub mod cache;
|
||||||
pub mod db;
|
|
||||||
pub mod router;
|
pub mod router;
|
||||||
pub mod state;
|
pub mod state;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use axum::{extract::State, response::IntoResponse, routing::get, Json, Router};
|
use axum::{extract::State, response::IntoResponse, routing::get, Json, Router};
|
||||||
use reqwest::StatusCode;
|
|
||||||
|
|
||||||
use crate::{db::CacheRecordName, templates::LinkListTemplate, AppState};
|
use crate::{templates::LinkListTemplate, AppState};
|
||||||
|
|
||||||
pub fn get_records_router() -> Router<AppState> {
|
pub fn get_records_router() -> Router<AppState> {
|
||||||
// Records views
|
// Records views
|
||||||
|
@ -16,20 +15,9 @@ pub(crate) async fn records(State(state): State<AppState>) -> impl IntoResponse
|
||||||
|
|
||||||
// This function is to remain ugly until that time in which I properly hide
|
// This function is to remain ugly until that time in which I properly hide
|
||||||
// this behind some kind of authentication
|
// this behind some kind of authentication
|
||||||
pub async fn records_links(
|
pub async fn records_links(State(state): State<AppState>) -> impl IntoResponse {
|
||||||
State(state): State<AppState>,
|
let records = state.records.lock().await.clone();
|
||||||
) -> Result<impl IntoResponse, (StatusCode, String)> {
|
|
||||||
let cache_names = {
|
|
||||||
let mut conn = state.pool.acquire().await.unwrap();
|
|
||||||
|
|
||||||
sqlx::query_file_as!(CacheRecordName, "queries/records/get_cache_names.sql")
|
let record_keys: Vec<String> = records.keys().cloned().collect();
|
||||||
.fetch_all(&mut *conn)
|
LinkListTemplate { record_keys }
|
||||||
.await
|
|
||||||
.map_err(|err| (StatusCode::INTERNAL_SERVER_ERROR, err.to_string()))?
|
|
||||||
.into_iter()
|
|
||||||
.map(|name| name.into())
|
|
||||||
.collect()
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(LinkListTemplate { cache_names })
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,5 +45,5 @@ impl DownloadLinkFragment {
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
#[template(path = "linklist.html")]
|
#[template(path = "linklist.html")]
|
||||||
pub struct LinkListTemplate {
|
pub struct LinkListTemplate {
|
||||||
pub cache_names: Vec<String>,
|
pub record_keys: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<div class="form-wrapper">
|
<div class="form-wrapper">
|
||||||
<div class="column-container">
|
<div class="column-container">
|
||||||
<ul>
|
<ul>
|
||||||
{% for key in cache_names %}
|
{% for key in record_keys %}
|
||||||
<li class="link-wrapper">
|
<li class="link-wrapper">
|
||||||
<a href="/link/{{ key }}">{{ key }}</a>
|
<a href="/link/{{ key }}">{{ key }}</a>
|
||||||
<button
|
<button
|
||||||
|
|
Loading…
Reference in a new issue