mirror of
https://codeberg.org/demostf/cleanup.git
synced 2026-06-03 10:04:10 +02:00
initial version
This commit is contained in:
parent
7c30512ae6
commit
342b10f15a
7 changed files with 1276 additions and 4 deletions
6
.dockerignore
Normal file
6
.dockerignore
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
target
|
||||
.git
|
||||
.idea
|
||||
Dockerfile
|
||||
.dockerignore
|
||||
.env
|
||||
2
.env
Normal file
2
.env
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
DEMOSTF_KEY=aJBXYwG8AdWcsrgVgeGG4IMRdxgtcezIa27WH9S9YujmW
|
||||
DEMOS_ROOT=/
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1 +1,2 @@
|
|||
/target
|
||||
.env
|
||||
1206
Cargo.lock
generated
Normal file
1206
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -4,6 +4,9 @@ version = "0.1.0"
|
|||
authors = ["Robin Appelman <robin@icewind.nl>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
demostf-client = "0.1"
|
||||
tokio = { version = "0.2", features = ["macros"] }
|
||||
chrono = "0.4"
|
||||
main_error = "0.1"
|
||||
dotenv = "0.15"
|
||||
12
Dockerfile
Normal file
12
Dockerfile
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
FROM ekidd/rust-musl-builder AS build
|
||||
|
||||
ADD . ./
|
||||
RUN sudo chown -R rust:rust .
|
||||
|
||||
RUN cargo build --release
|
||||
|
||||
FROM alpine:latest
|
||||
|
||||
COPY --from=build /home/rust/src/target/x86_64-unknown-linux-musl/release/cleanup /
|
||||
|
||||
CMD ["/cleanup"]
|
||||
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