mirror of
https://codeberg.org/demostf/cleanup.git
synced 2026-06-03 18:14:09 +02:00
initial version
This commit is contained in:
parent
7c30512ae6
commit
342b10f15a
7 changed files with 1276 additions and 4 deletions
46
src/main.rs
46
src/main.rs
|
|
@ -1,3 +1,45 @@
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
use chrono::{Duration, Utc};
|
||||
use demostf_client::{ApiClient, ListOrder, ListParams};
|
||||
use main_error::MainError;
|
||||
use std::fs::remove_file;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), MainError> {
|
||||
let key = dotenv::var("DEMOSTF_KEY").expect("DEMOSTF_KEY not set");
|
||||
let root = PathBuf::from(dotenv::var("DEMOS_ROOT").expect("DEMOS_ROOT not set"));
|
||||
|
||||
let client = ApiClient::new();
|
||||
|
||||
let demos = client
|
||||
.list(
|
||||
ListParams::default()
|
||||
.with_order(ListOrder::Ascending)
|
||||
.with_backend("freezer"),
|
||||
1,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let cutoff_time = Utc::now() - Duration::days(3 * 365);
|
||||
|
||||
for demo in demos {
|
||||
if demo.time > cutoff_time {
|
||||
break;
|
||||
}
|
||||
|
||||
let path = root.join(&demo.path.trim_start_matches('/'));
|
||||
|
||||
if !path.exists() {
|
||||
eprintln!("Demo not found: {}", path.to_str().unwrap());
|
||||
break;
|
||||
}
|
||||
|
||||
client
|
||||
.set_url(demo.id, "deleted", "", "", demo.hash, &key)
|
||||
.await?;
|
||||
remove_file(&path)?;
|
||||
println!("{} {}", demo.id, demo.name);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue