Compare commits

..

No commits in common. "ec6b1b6477cfc947061e717d80821db3118a1bde" and "10cf09ee762e581f9d6ab86cd1fafcde249f387d" have entirely different histories.

8 changed files with 9 additions and 92 deletions

View file

@ -1,5 +0,0 @@
DELETE FROM records
WHERE
downloads >= max_downloads
OR julianday('now') - julianday(uploaded) > 3
RETURNING cache_name;

View file

@ -1,7 +0,0 @@
SELECT
cache_name,
downloads,
max_downloads,
julianday('now') - julianday(uploaded) AS age
FROM records
WHERE downloads >= max_downloads OR age > 5;

View file

@ -1,6 +0,0 @@
SELECT
cache_name,
uploaded,
downloads,
max_downloads
FROM records;

View file

@ -1,7 +0,0 @@
SELECT
cache_name,
uploaded,
downloads,
max_downloads
FROM records
LIMIT ? OFFSET ?;

View file

@ -4,14 +4,9 @@ use axum::{
routing::get, routing::get,
Router, Router,
}; };
use axum_extra::TypedHeader;
use reqwest::StatusCode; use reqwest::StatusCode;
use crate::{ use crate::{templates::DownloadLinkTemplate, AppState, AsyncRemoveRecord};
templates::{self, DownloadLinkTemplate},
util::headers::HxRequest,
AppState, AsyncRemoveRecord,
};
pub fn get_link_router() -> Router<AppState> { pub fn get_link_router() -> Router<AppState> {
// Link pages // Link pages
@ -67,22 +62,12 @@ async fn link_delete(
async fn remaining( async fn remaining(
State(state): State<AppState>, State(state): State<AppState>,
hx_request: Option<TypedHeader<HxRequest>>,
axum::extract::Path(id): axum::extract::Path<String>, axum::extract::Path(id): axum::extract::Path<String>,
) -> Result<impl IntoResponse, (StatusCode, String)> { ) -> impl IntoResponse {
if hx_request.is_none() {
return Err((
StatusCode::BAD_REQUEST,
"Attempt to fetch html fragment from non-htmx request".to_string(),
));
}
let records = state.records.lock().await; let records = state.records.lock().await;
if let Some(record) = records.get(&id) {
Ok(Html( Html(crate::templates::get_downloads_remaining_text(record))
records } else {
.get(&id) Html("?".to_string())
.map(templates::get_downloads_remaining_text) }
.unwrap_or_else(|| "?".to_string()),
))
} }

View file

@ -31,38 +31,3 @@ impl Header for ForwardedFor {
values.extend(std::iter::once(HeaderValue::from_str(&self.0).unwrap())); values.extend(std::iter::once(HeaderValue::from_str(&self.0).unwrap()));
} }
} }
#[derive(Debug)]
pub struct HxRequest;
pub static HXR_TEXT: &str = "hx-request";
pub static HXR_NAME: HeaderName = HeaderName::from_static(HXR_TEXT);
impl Header for HxRequest {
fn name() -> &'static HeaderName {
&FF_NAME
}
fn decode<'i, I>(values: &mut I) -> Result<Self, headers::Error>
where
Self: Sized,
I: Iterator<Item = &'i headers::HeaderValue>,
{
let value = values
.next()
.ok_or_else(headers::Error::invalid)?
.to_str()
.map_err(|_| headers::Error::invalid())?
.to_owned();
match &value[..] {
"true" => Ok(HxRequest),
_ => Err(headers::Error::invalid()),
}
}
fn encode<E: Extend<headers::HeaderValue>>(&self, values: &mut E) {
values.extend(std::iter::once(HeaderValue::from_static("true")));
}
}

View file

@ -39,12 +39,6 @@ pub struct DownloadLinkFragment {
pub record: UploadRecord, pub record: UploadRecord,
} }
#[derive(Template)]
#[template(path = "link.html", block = "downloads_remaining")]
pub struct DownloadsRemainingFragment {
pub record: UploadRecord,
}
#[derive(Template)] #[derive(Template)]
#[template(path = "linklist.html")] #[template(path = "linklist.html")]
pub struct LinkListTemplate { pub struct LinkListTemplate {

View file

@ -10,11 +10,9 @@
<div <div
class="link-wrapper" class="link-wrapper"
hx-get="/link/{{ id }}/remaining" hx-get="/link/{{ id }}/remaining"
hx-trigger="click from:#link delay:0.2s, every 60s" hx-trigger="click from:#link delay:0.2s, every 10s"
> >
{% block downloads_remaining %} {{ self::get_downloads_remaining_text(record) }}
{{ self::get_downloads_remaining_text(record) }}
{% endblock downloads_remaining %}
</div> </div>
<button class="return-button" onclick="clipboard()"> <button class="return-button" onclick="clipboard()">
Copy to Clipboard Copy to Clipboard