Cargo fmt
This commit is contained in:
parent
1916ea0efe
commit
00a5192d02
34
src/lib.rs
34
src/lib.rs
|
@ -1,9 +1,9 @@
|
||||||
|
use regex::Regex;
|
||||||
use reqwest::{Error as ReqwestError, StatusCode};
|
use reqwest::{Error as ReqwestError, StatusCode};
|
||||||
use rss::{Channel, Error as RssError};
|
use rss::{Channel, Error as RssError};
|
||||||
use regex::Regex;
|
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
|
||||||
use worker::{Request, Env, Response, Router, event, Headers};
|
use worker::{event, Env, Headers, Request, Response, Router};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum CustomError {
|
enum CustomError {
|
||||||
|
@ -24,21 +24,23 @@ impl From<RssError> for CustomError {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[event(fetch)]
|
#[event(fetch)]
|
||||||
pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> worker::Result<Response>{
|
pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> worker::Result<Response> {
|
||||||
let router = Router::new();
|
let router = Router::new();
|
||||||
router
|
router
|
||||||
.get_async("/", |_, ctx| async move {
|
.get_async("/", |_, ctx| async move {
|
||||||
let rss = match fetch_modified_rss().await {
|
let rss = match fetch_modified_rss().await {
|
||||||
Ok(r) => r,
|
Ok(r) => r,
|
||||||
Err(e) => "".to_owned(),
|
Err(e) => "".to_owned(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = Response::from_bytes(rss.into()).unwrap();
|
let res = Response::from_bytes(rss.into()).unwrap();
|
||||||
let mut headers = Headers::new();
|
let mut headers = Headers::new();
|
||||||
headers.set("content-type", "application/rss+xml");
|
headers.set("content-type", "application/rss+xml");
|
||||||
|
|
||||||
Ok(res.with_headers(headers))
|
Ok(res.with_headers(headers))
|
||||||
}).run(req, env).await
|
})
|
||||||
|
.run(req, env)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fetch_modified_rss() -> Result<String, CustomError> {
|
async fn fetch_modified_rss() -> Result<String, CustomError> {
|
||||||
|
@ -53,7 +55,7 @@ async fn fetch_modified_rss() -> Result<String, CustomError> {
|
||||||
Err(RssError::InvalidStartTag) => {
|
Err(RssError::InvalidStartTag) => {
|
||||||
eprintln!("Invalid start tag found in the feed. Please check the feed URL or try again later.");
|
eprintln!("Invalid start tag found in the feed. Please check the feed URL or try again later.");
|
||||||
return Ok(String::new());
|
return Ok(String::new());
|
||||||
},
|
}
|
||||||
Err(err) => return Err(err.into()),
|
Err(err) => return Err(err.into()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue