Compare commits
No commits in common. "7128b9e3046653a6175c234a70fe7887476dc084" and "391f9cfa0189fe70d96eebe9fa0ae22e5ee9b61f" have entirely different histories.
7128b9e304
...
391f9cfa01
|
@ -1 +0,0 @@
|
|||
edition = "2021"
|
|
@ -1,2 +0,0 @@
|
|||
[attr_values]
|
||||
class = "Tailwind" # "Tailwind" is the only attribute value formatter available for now
|
|
@ -1,2 +0,0 @@
|
|||
[rustfmt]
|
||||
overrideCommand = ["leptosfmt", "--stdin", "--rustfmt"]
|
43
src/main.rs
43
src/main.rs
|
@ -32,7 +32,6 @@ mod cache;
|
|||
mod nyazoom_headers;
|
||||
pub mod ssr;
|
||||
mod state;
|
||||
mod sweeper;
|
||||
mod util;
|
||||
mod views;
|
||||
|
||||
|
@ -65,7 +64,25 @@ async fn main() -> io::Result<()> {
|
|||
|
||||
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
|
||||
let app = Router::new()
|
||||
|
@ -120,7 +137,9 @@ async fn remaining(
|
|||
async fn welcome() -> impl IntoResponse {
|
||||
let cat_fact = views::get_cat_fact().await;
|
||||
Html(ssr::render(move || {
|
||||
leptos::view! { <Welcome fact=cat_fact /> }
|
||||
leptos::view! {
|
||||
<Welcome fact=cat_fact />
|
||||
}
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -138,23 +157,15 @@ async fn records_links(State(state): State<AppState>) -> impl IntoResponse {
|
|||
<div class="form-wrapper">
|
||||
<div class="column-container">
|
||||
<ul>
|
||||
{records
|
||||
.keys()
|
||||
.map(|key| {
|
||||
leptos::view! {
|
||||
{records.keys().map(|key| leptos::view! {
|
||||
<li class="link-wrapper">
|
||||
<a href="/link/{key}">{key}</a>
|
||||
<button
|
||||
style="margin-left: 1em;"
|
||||
<button style="margin-left: 1em;"
|
||||
hx-target="closest .link-wrapper"
|
||||
hx-swap="outerHTML"
|
||||
hx-delete="/link/{key}"
|
||||
>
|
||||
X
|
||||
</button>
|
||||
hx-delete="/link/{key}">X</button>
|
||||
</li>
|
||||
}
|
||||
})
|
||||
})
|
||||
.collect::<Vec<_>>()}
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -179,7 +190,7 @@ async fn link(
|
|||
return Ok(Html(ssr::render({
|
||||
let record = record.clone();
|
||||
|| {
|
||||
leptos::view! { <DownloadLinkPage id=id record=record /> }
|
||||
leptos::view! { <DownloadLinkPage id=id record=record /> }
|
||||
}
|
||||
})));
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
52
src/views.rs
52
src/views.rs
|
@ -33,26 +33,11 @@ pub fn Welcome(fact: String) -> impl IntoView {
|
|||
#[component]
|
||||
pub fn WelcomeView(fact: String) -> impl IntoView {
|
||||
view! {
|
||||
<form
|
||||
id="form"
|
||||
hx-swap="outerHTML"
|
||||
hx-post="/upload"
|
||||
hx-encoding="multipart/form-data"
|
||||
class="column-container"
|
||||
>
|
||||
<form id="form" hx-swap="outerHTML" hx-post="/upload" hx-encoding="multipart/form-data" class="column-container">
|
||||
<div class="cat-img-wrapper">
|
||||
<img
|
||||
class="cat-img"
|
||||
src="https://api.thecatapi.com/v1/images/search?size=small&format=src"
|
||||
/>
|
||||
<img class="cat-img" src="https://api.thecatapi.com/v1/images/search?size=small&format=src" />
|
||||
</div>
|
||||
<input
|
||||
type="file"
|
||||
id="file"
|
||||
name="file"
|
||||
data-multiple-caption="{{count}} files selected"
|
||||
multiple
|
||||
/>
|
||||
<input type="file" id="file" name="file" data-multiple-caption="{{count}} files selected" multiple />
|
||||
<label for="file">Select Files</label>
|
||||
|
||||
<input type="submit" value="Get Link~" />
|
||||
|
@ -87,11 +72,7 @@ pub fn HtmxPage(children: Children) -> impl IntoView {
|
|||
<link href="/css/link.css" rel="stylesheet" />
|
||||
<script src="/scripts/file_label.js" />
|
||||
<script src="/scripts/link.js" />
|
||||
<script
|
||||
src="https://unpkg.com/htmx.org@1.9.4"
|
||||
integrity="sha384-zUfuhFKKZCbHTY6aRR46gxiqszMk5tcHjsVFxnUo8VMus4kHGVdIYVbOYYNlKmHV"
|
||||
crossorigin="anonymous"
|
||||
></script>
|
||||
<script src="https://unpkg.com/htmx.org@1.9.4" integrity="sha384-zUfuhFKKZCbHTY6aRR46gxiqszMk5tcHjsVFxnUo8VMus4kHGVdIYVbOYYNlKmHV" crossorigin="anonymous"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
@ -108,29 +89,16 @@ pub fn LinkView(id: String, record: UploadRecord) -> impl IntoView {
|
|||
view! {
|
||||
<div class="column-container">
|
||||
<div class="link-wrapper">
|
||||
<a id="link" href="/download/{id}">
|
||||
Download Now!
|
||||
</a>
|
||||
<a id="link" href="/download/{id}">Download Now!</a>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="link-wrapper"
|
||||
hx-get="/link/{id}/remaining"
|
||||
hx-trigger="click from:#link delay:0.2s, every 10s"
|
||||
>
|
||||
You have
|
||||
{record.downloads_remaining()}
|
||||
download
|
||||
{plural}
|
||||
remaining!
|
||||
<div class="link-wrapper" hx-get="/link/{id}/remaining" hx-trigger="click from:#link delay:0.2s, every 10s" >
|
||||
You have {record.downloads_remaining()} download{plural} remaining!
|
||||
</div>
|
||||
<button class="return-button" onclick="clipboard()">
|
||||
Copy to Clipboard
|
||||
</button>
|
||||
<button class="return-button" onclick="clipboard()">Copy to Clipboard</button>
|
||||
|
||||
<a href="/" class="return-button">
|
||||
Return to home
|
||||
</a>
|
||||
|
||||
<a href="/" class="return-button">Return to home</a>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue