mirror of
https://github.com/13hannes11/ics-proxy.git
synced 2024-09-06 08:01:41 +02:00
implement ics-proxy to use database entries
This commit is contained in:
32
src/main.rs
32
src/main.rs
@@ -1,6 +1,7 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
use actix_web::http::StatusCode;
|
||||||
use actix_web::{error, web, App, Error, HttpRequest, HttpResponse, HttpServer, Responder, Result};
|
use actix_web::{error, web, App, Error, HttpRequest, HttpResponse, HttpServer, Responder, Result};
|
||||||
use sqlx::{Pool, Sqlite, SqlitePool};
|
use sqlx::{Pool, Sqlite, SqlitePool};
|
||||||
use tera::Tera;
|
use tera::Tera;
|
||||||
@@ -20,25 +21,26 @@ struct CONFIG {
|
|||||||
root: String,
|
root: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn make_ics_request(req: HttpRequest) -> impl Responder {
|
async fn make_ics_request(req: HttpRequest, db_pool: web::Data<Pool<Sqlite>>) -> impl Responder {
|
||||||
let id = req.match_info().get("id").unwrap_or("");
|
let id = req.match_info().get("id").unwrap_or("");
|
||||||
|
|
||||||
let body = match id {
|
match Uuid::parse_str(id) {
|
||||||
"1" => {
|
Ok(uuid) => match Link::find_by_uuid(uuid.to_string(), db_pool).await {
|
||||||
// TODO: load url based on id from database and make request
|
Ok(link) => match reqwest::blocking::get(link.destination) {
|
||||||
let res = match reqwest::blocking::get("https://cloud.timeedit.net/uu/web/schema/ri6QX6089X8061QQ88Z4758Z08y37424838828461554904Y684XX09894Q8721784ZnX6503.ics") {
|
|
||||||
Ok(r) => match r.text() {
|
Ok(r) => match r.text() {
|
||||||
Ok(res) => res,
|
Ok(res) => HttpResponse::Ok().content_type("text/calendar").body(res),
|
||||||
Err(_) => "".to_string(),
|
Err(_) => HttpResponse::Ok()
|
||||||
|
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
||||||
|
.finish(),
|
||||||
},
|
},
|
||||||
Err(_) => "".to_string(),
|
Err(_) => HttpResponse::Ok()
|
||||||
};
|
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
||||||
|
.finish(),
|
||||||
res
|
},
|
||||||
}
|
Err(_) => HttpResponse::Ok().status(StatusCode::NOT_FOUND).finish(),
|
||||||
_ => "".to_string(),
|
},
|
||||||
};
|
Err(_) => HttpResponse::Ok().status(StatusCode::BAD_REQUEST).finish(),
|
||||||
HttpResponse::Ok().content_type("text/calendar").body(body)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn error_page(tmpl: web::Data<tera::Tera>, msg: String) -> Result<HttpResponse, Error> {
|
fn error_page(tmpl: web::Data<tera::Tera>, msg: String) -> Result<HttpResponse, Error> {
|
||||||
|
|||||||
Reference in New Issue
Block a user