diff --git a/backend/src/cdn.rs b/backend/src/cdn.rs index 68a1552..39a0623 100644 --- a/backend/src/cdn.rs +++ b/backend/src/cdn.rs @@ -2,7 +2,7 @@ use crate::{ service::Service, statics::{self, CF_ZONE_IDENT}, }; -use actix_web::{http::header, Error}; +use actix_web::{http::header, Error, HttpResponse}; use awc::Client; use futures::Future; @@ -13,6 +13,24 @@ impl Cloudflare { &CF_ZONE_IDENT } + pub(crate) fn dbg( + client: &Client, + file: &str, + ) -> impl Future { + client + .post(format!( + "https://api.cloudflare.com/client/v4/zones/{}/purge_cache", + Self::identifier() + )) + .header(header::USER_AGENT, statics::USER_AGENT.as_str()) + .header("X-Auth-Email", Self::auth_email()) + .header("X-Auth-Key", Self::auth_key()) + .content_type("application/json") + .send_json(&CfPurgeRequest::singleton::(file)) + .from_err() + .and_then(|response| HttpResponse::build(response.status()).streaming(response)) + } + pub(crate) fn purge_cache( client: &Client, file: &str, diff --git a/backend/src/main.rs b/backend/src/main.rs index 25d67bd..6fc3d79 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -104,6 +104,13 @@ fn purge_cache( .map(|success| HttpResponse::Ok().body(success.to_string())) } +fn dbg( + client: web::Data, + file: web::Path, +) -> impl Future { + Cloudflare::dbg::(&client, &file) +} + fn main() -> Result<()> { std::env::set_var("RUST_LOG", "actix_server=info,actix_web=trace"); pretty_env_logger::init(); @@ -118,26 +125,20 @@ fn main() -> Result<()> { "/github/{user}/{repo}/{commit}/{file:.*}", web::get().to_async(handle_request::), ) - .route( - "/github/{file:.*}", - web::delete().to_async(purge_cache::), - ) + .route("/github/{file:.*}", web::delete().to_async(dbg::)) .route( "/bitbucket/{user}/{repo}/{commit}/{file:.*}", web::get().to_async(handle_request::), ) .route( "/bitbucket//{file:.*}", - web::delete().to_async(purge_cache::), + web::delete().to_async(dbg::), ) .route( "/gitlab/{user}/{repo}/{commit}/{file:.*}", web::get().to_async(handle_request::), ) - .route( - "/gitlab/{file:.*}", - web::delete().to_async(purge_cache::), - ) + .route("/gitlab/{file:.*}", web::delete().to_async(dbg::)) .service(actix_files::Files::new("/", "public").index_file("index.html")) }) .workers(OPT.workers)