Compare commits

..

No commits in common. "7128b9e3046653a6175c234a70fe7887476dc084" and "391f9cfa0189fe70d96eebe9fa0ae22e5ee9b61f" have entirely different histories.

6 changed files with 37 additions and 86 deletions

View File

@ -1 +0,0 @@
edition = "2021"

View File

@ -1,2 +0,0 @@
[attr_values]
class = "Tailwind" # "Tailwind" is the only attribute value formatter available for now

View File

@ -1,2 +0,0 @@
[rustfmt]
overrideCommand = ["leptosfmt", "--stdin", "--rustfmt"]

View File

@ -32,7 +32,6 @@ mod cache;
mod nyazoom_headers; mod nyazoom_headers;
pub mod ssr; pub mod ssr;
mod state; mod state;
mod sweeper;
mod util; mod util;
mod views; mod views;
@ -65,7 +64,25 @@ async fn main() -> io::Result<()> {
let state = cache::fetch_cache().await; let state = cache::fetch_cache().await;
let _ = sweeper::spawn_sweeper(); // Spawn a repeating task that will clean files periodically
tokio::spawn({
let state = state.clone();
async move {
loop {
tokio::time::sleep(Duration::from_secs(15 * 60)).await;
tracing::info!("Cleaning Sweep!");
let mut records = state.records.lock().await;
for (key, record) in records.clone().into_iter() {
if !record.can_be_downloaded() {
tracing::info!("culling: {:?}", record);
records.remove_record(&key).await.unwrap();
}
}
}
}
});
// Router Setup // Router Setup
let app = Router::new() let app = Router::new()
@ -120,7 +137,9 @@ async fn remaining(
async fn welcome() -> impl IntoResponse { async fn welcome() -> impl IntoResponse {
let cat_fact = views::get_cat_fact().await; let cat_fact = views::get_cat_fact().await;
Html(ssr::render(move || { Html(ssr::render(move || {
leptos::view! { <Welcome fact=cat_fact /> } leptos::view! {
<Welcome fact=cat_fact />
}
})) }))
} }
@ -138,22 +157,14 @@ async fn records_links(State(state): State<AppState>) -> impl IntoResponse {
<div class="form-wrapper"> <div class="form-wrapper">
<div class="column-container"> <div class="column-container">
<ul> <ul>
{records {records.keys().map(|key| leptos::view! {
.keys()
.map(|key| {
leptos::view! {
<li class="link-wrapper"> <li class="link-wrapper">
<a href="/link/{key}">{key}</a> <a href="/link/{key}">{key}</a>
<button <button style="margin-left: 1em;"
style="margin-left: 1em;"
hx-target="closest .link-wrapper" hx-target="closest .link-wrapper"
hx-swap="outerHTML" hx-swap="outerHTML"
hx-delete="/link/{key}" hx-delete="/link/{key}">X</button>
>
X
</button>
</li> </li>
}
}) })
.collect::<Vec<_>>()} .collect::<Vec<_>>()}
</ul> </ul>

View File

@ -1,23 +0,0 @@
use tokio::task::JoinHandle;
pub fn spawn_sweeper() -> JoinHandle<!> {
// Spawn a repeating task that will clean files periodically
tokio::spawn({
let state = state.clone();
async move {
loop {
tokio::time::sleep(Duration::from_secs(15 * 60)).await;
tracing::info!("Cleaning Sweep!");
let mut records = state.records.lock().await;
for (key, record) in records.clone().into_iter() {
if !record.can_be_downloaded() {
tracing::info!("culling: {:?}", record);
records.remove_record(&key).await.unwrap();
}
}
}
}
})
}

View File

@ -33,26 +33,11 @@ pub fn Welcome(fact: String) -> impl IntoView {
#[component] #[component]
pub fn WelcomeView(fact: String) -> impl IntoView { pub fn WelcomeView(fact: String) -> impl IntoView {
view! { view! {
<form <form id="form" hx-swap="outerHTML" hx-post="/upload" hx-encoding="multipart/form-data" class="column-container">
id="form"
hx-swap="outerHTML"
hx-post="/upload"
hx-encoding="multipart/form-data"
class="column-container"
>
<div class="cat-img-wrapper"> <div class="cat-img-wrapper">
<img <img class="cat-img" src="https://api.thecatapi.com/v1/images/search?size=small&format=src" />
class="cat-img"
src="https://api.thecatapi.com/v1/images/search?size=small&format=src"
/>
</div> </div>
<input <input type="file" id="file" name="file" data-multiple-caption="{{count}} files selected" multiple />
type="file"
id="file"
name="file"
data-multiple-caption="{{count}} files selected"
multiple
/>
<label for="file">Select Files</label> <label for="file">Select Files</label>
<input type="submit" value="Get Link~" /> <input type="submit" value="Get Link~" />
@ -87,11 +72,7 @@ pub fn HtmxPage(children: Children) -> impl IntoView {
<link href="/css/link.css" rel="stylesheet" /> <link href="/css/link.css" rel="stylesheet" />
<script src="/scripts/file_label.js" /> <script src="/scripts/file_label.js" />
<script src="/scripts/link.js" /> <script src="/scripts/link.js" />
<script <script src="https://unpkg.com/htmx.org@1.9.4" integrity="sha384-zUfuhFKKZCbHTY6aRR46gxiqszMk5tcHjsVFxnUo8VMus4kHGVdIYVbOYYNlKmHV" crossorigin="anonymous"></script>
src="https://unpkg.com/htmx.org@1.9.4"
integrity="sha384-zUfuhFKKZCbHTY6aRR46gxiqszMk5tcHjsVFxnUo8VMus4kHGVdIYVbOYYNlKmHV"
crossorigin="anonymous"
></script>
</head> </head>
<body> <body>
@ -108,29 +89,16 @@ pub fn LinkView(id: String, record: UploadRecord) -> impl IntoView {
view! { view! {
<div class="column-container"> <div class="column-container">
<div class="link-wrapper"> <div class="link-wrapper">
<a id="link" href="/download/{id}"> <a id="link" href="/download/{id}">Download Now!</a>
Download Now!
</a>
</div> </div>
<div <div class="link-wrapper" hx-get="/link/{id}/remaining" hx-trigger="click from:#link delay:0.2s, every 10s" >
class="link-wrapper" You have {record.downloads_remaining()} download{plural} remaining!
hx-get="/link/{id}/remaining"
hx-trigger="click from:#link delay:0.2s, every 10s"
>
You have
{record.downloads_remaining()}
download
{plural}
remaining!
</div> </div>
<button class="return-button" onclick="clipboard()"> <button class="return-button" onclick="clipboard()">Copy to Clipboard</button>
Copy to Clipboard
</button>
<a href="/" class="return-button">
Return to home <a href="/" class="return-button">Return to home</a>
</a>
</div> </div>
} }
} }