diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/src/lib.rs b/src/lib.rs index 3e3b551..e65f82f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,9 +1,9 @@ +use regex::Regex; use reqwest::{Error as ReqwestError, StatusCode}; use rss::{Channel, Error as RssError}; -use regex::Regex; use std::io::Cursor; -use worker::{Request, Env, Response, Router, event, Headers}; +use worker::{event, Env, Headers, Request, Response, Router}; #[derive(Debug)] enum CustomError { @@ -24,21 +24,23 @@ impl From for CustomError { } #[event(fetch)] -pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> worker::Result{ - let router = Router::new(); - router - .get_async("/", |_, ctx| async move { - let rss = match fetch_modified_rss().await { - Ok(r) => r, - Err(e) => "".to_owned(), - }; +pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> worker::Result { + let router = Router::new(); + router + .get_async("/", |_, ctx| async move { + let rss = match fetch_modified_rss().await { + Ok(r) => r, + Err(e) => "".to_owned(), + }; - let res = Response::from_bytes(rss.into()).unwrap(); - let mut headers = Headers::new(); - headers.set("content-type", "application/rss+xml"); - - Ok(res.with_headers(headers)) - }).run(req, env).await + let res = Response::from_bytes(rss.into()).unwrap(); + let mut headers = Headers::new(); + headers.set("content-type", "application/rss+xml"); + + Ok(res.with_headers(headers)) + }) + .run(req, env) + .await } async fn fetch_modified_rss() -> Result { @@ -53,7 +55,7 @@ async fn fetch_modified_rss() -> Result { Err(RssError::InvalidStartTag) => { eprintln!("Invalid start tag found in the feed. Please check the feed URL or try again later."); return Ok(String::new()); - }, + } Err(err) => return Err(err.into()), };