initial version

This commit is contained in:
Robin Appelman 2020-07-25 15:38:37 +02:00
commit 342b10f15a
7 changed files with 1276 additions and 4 deletions

6
.dockerignore Normal file
View file

@ -0,0 +1,6 @@
target
.git
.idea
Dockerfile
.dockerignore
.env

2
.env Normal file
View file

@ -0,0 +1,2 @@
DEMOSTF_KEY=aJBXYwG8AdWcsrgVgeGG4IMRdxgtcezIa27WH9S9YujmW
DEMOS_ROOT=/

1
.gitignore vendored
View file

@ -1 +1,2 @@
/target /target
.env

1206
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -4,6 +4,9 @@ version = "0.1.0"
authors = ["Robin Appelman <robin@icewind.nl>"] authors = ["Robin Appelman <robin@icewind.nl>"]
edition = "2018" edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [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
View 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"]

View file

@ -1,3 +1,45 @@
fn main() { use chrono::{Duration, Utc};
println!("Hello, world!"); 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(())
} }