Compare commits

...

6 commits

Author SHA1 Message Date
7825f38e7a fixup! feat: deny non hx-requests on fragment 2024-11-21 16:50:19 -08:00
122643c630 feat: use data file as db in .cache 2024-11-21 16:47:05 -08:00
1ccaab9578 chore: cleanup unused imports
I commented the thing that uses this out
2024-11-21 16:40:05 -08:00
91cbca6b15 feat: cache names no longer include .zip 2024-11-21 16:39:23 -08:00
814aaad260 fixup! feat: begone memory map 2024-11-21 16:25:29 -08:00
1dc9f4c877 chore: update .sqlx 2024-11-21 16:17:05 -08:00
9 changed files with 82 additions and 18 deletions

View file

@ -0,0 +1,38 @@
{
"db_name": "SQLite",
"query": "INSERT INTO records (cache_name, max_downloads)\nVALUES (?, ?)\nRETURNING\n cache_name,\n uploaded AS \"uploaded: _\",\n downloads AS \"downloads: i32\",\n max_downloads AS \"max_downloads: i32\";\n",
"describe": {
"columns": [
{
"name": "cache_name",
"ordinal": 0,
"type_info": "Text"
},
{
"name": "uploaded: _",
"ordinal": 1,
"type_info": "Text"
},
{
"name": "downloads: i32",
"ordinal": 2,
"type_info": "Integer"
},
{
"name": "max_downloads: i32",
"ordinal": 3,
"type_info": "Integer"
}
],
"parameters": {
"Right": 2
},
"nullable": [
false,
false,
false,
false
]
},
"hash": "7364fac4efc7b1872f8298bb007191caed687d5c6a0770486a329a24085b2ab2"
}

View file

@ -1,12 +0,0 @@
{
"db_name": "SQLite",
"query": "INSERT INTO records (cache_name, max_downloads)\nVALUES (?, ?);\n",
"describe": {
"columns": [],
"parameters": {
"Right": 2
},
"nullable": []
},
"hash": "dcad7587b9bd5d84025db4e22c90d2ba0210edeaff5235a877e92235384f2c57"
}

View file

@ -0,0 +1,38 @@
{
"db_name": "SQLite",
"query": "SELECT\n cache_name,\n uploaded AS \"uploaded: _\",\n downloads AS \"downloads: i32\",\n max_downloads AS \"max_downloads: i32\"\nFROM records\nWHERE cache_name = ?;\n",
"describe": {
"columns": [
{
"name": "cache_name",
"ordinal": 0,
"type_info": "Text"
},
{
"name": "uploaded: _",
"ordinal": 1,
"type_info": "Text"
},
{
"name": "downloads: i32",
"ordinal": 2,
"type_info": "Integer"
},
{
"name": "max_downloads: i32",
"ordinal": 3,
"type_info": "Integer"
}
],
"parameters": {
"Right": 1
},
"nullable": [
false,
false,
false,
false
]
},
"hash": "f910a524c457442564a8d484fc00a277ae5cb73444e5748af0bf0d629048fa17"
}

View file

@ -3,4 +3,4 @@ SET downloads = downloads + 1
WHERE WHERE
cache_name = ? cache_name = ?
AND downloads < max_downloads AND downloads < max_downloads
AND julianday('now') - julianday(uploaded) > 5; AND julianday('now') - julianday(uploaded) < 5;

View file

@ -16,5 +16,5 @@ mkShell rec {
sqlite sqlite
] ++ additionalBuildInputs; ] ++ additionalBuildInputs;
LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs; LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs;
DATABASE_URL = "sqlite:testing.db"; DATABASE_URL = "sqlite://.cache/data";
} }

View file

@ -1,4 +1,4 @@
use axum::{extract::State, response::IntoResponse, routing::get, Json, Router}; use axum::{extract::State, response::IntoResponse, routing::get, Router};
use reqwest::StatusCode; use reqwest::StatusCode;
use crate::{db::CacheRecordName, templates::LinkListTemplate, AppState}; use crate::{db::CacheRecordName, templates::LinkListTemplate, AppState};

View file

@ -32,7 +32,7 @@ async fn upload_to_zip(
) -> Result<Response, (StatusCode, String)> { ) -> Result<Response, (StatusCode, String)> {
let cache_name = util::get_random_name(10); let cache_name = util::get_random_name(10);
let archive_path = Path::new(".cache/serve").join(format!("{}.zip", &cache_name)); let archive_path = Path::new(".cache/serve").join(&cache_name);
tracing::debug!("Zipping: {:?}", &archive_path); tracing::debug!("Zipping: {:?}", &archive_path);

View file

@ -55,7 +55,7 @@ impl AppState {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
pool: SqlitePool::connect_lazy_with( pool: SqlitePool::connect_lazy_with(
SqliteConnectOptions::from_str("sqlite:testing.db") SqliteConnectOptions::from_str("sqlite://.cache/data")
.expect("Invalid Database String"), .expect("Invalid Database String"),
), ),
} }

View file

@ -41,7 +41,7 @@ pub static HXR_NAME: HeaderName = HeaderName::from_static(HXR_TEXT);
impl Header for HxRequest { impl Header for HxRequest {
fn name() -> &'static HeaderName { fn name() -> &'static HeaderName {
&FF_NAME &HXR_NAME
} }
fn decode<'i, I>(values: &mut I) -> Result<Self, headers::Error> fn decode<'i, I>(values: &mut I) -> Result<Self, headers::Error>