Cargo fmt

This commit is contained in:
Gabriel Simmer 2023-08-27 22:07:35 +01:00
parent 1916ea0efe
commit 00a5192d02
Signed by: arch
SSH key fingerprint: SHA256:m3OEcdtrnBpMX+2BDGh/byv3hrCekCLzDYMdvGEKPPQ
2 changed files with 20 additions and 17 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
use flake

View file

@ -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<RssError> for CustomError {
}
#[event(fetch)]
pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> worker::Result<Response>{
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<Response> {
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<String, CustomError> {
@ -53,7 +55,7 @@ async fn fetch_modified_rss() -> Result<String, CustomError> {
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()),
};