call check() on add-installation + make check async

This commit is contained in:
Miraty 2024-02-24 16:55:52 +01:00
parent f564e4f366
commit 2f06c4ec1f
4 changed files with 13 additions and 11 deletions

View File

@ -16,7 +16,6 @@ texting_robots = "0.2.2"
version = "0.11.24"
default-features = false
features = [
"blocking",
"rustls-tls",
"socks",
]

View File

@ -2,8 +2,8 @@ use texting_robots::{get_robots_url, Robot};
const USER_AGENT: &str = "ServiceLister";
pub fn check() {
let client = reqwest::blocking::Client::builder()
pub async fn check(url: &str) {
let client = reqwest::Client::builder()
.http1_only()
.https_only(true)
.min_tls_version(reqwest::tls::Version::TLS_1_3)
@ -11,12 +11,11 @@ pub fn check() {
.build()
.unwrap();
let url = "https://code.antopie.org/";
let robots_txt = get(&client, &get_robots_url(url).unwrap());
let robots_url = &get_robots_url(url).unwrap();
let robots_txt = get(&client, robots_url).await;
if robots_txt.status() == 200 {
let r = Robot::new(USER_AGENT, robots_txt.text().unwrap().as_bytes()).unwrap();
let r = Robot::new(USER_AGENT, robots_txt.text().await.unwrap().as_bytes()).unwrap();
if r.allowed("/") {
//let res = get(&client, &url);
@ -31,10 +30,11 @@ pub fn check() {
}
}
fn get(client: &reqwest::blocking::Client, url: &str) -> reqwest::blocking::Response {
async fn get(client: &reqwest::Client, url: &str) -> reqwest::Response {
return client
.get(url.to_owned())
.header("User-Agent", USER_AGENT)
.send()
.await
.unwrap();
}

View File

@ -1,6 +1,9 @@
#[macro_use]
extern crate rocket;
mod check;
use crate::check::check;
use ::services::establish_connection;
use diesel::prelude::*;
use rocket_dyn_templates::Template;
@ -54,7 +57,7 @@ struct Submission<'r> {
}
#[post("/add-installation", data = "<submission>")]
fn add_installation_post(submission: Form<Strict<Submission<'_>>>) -> Template {
println!("{}", submission.url);
async fn add_installation_post(submission: Form<Strict<Submission<'_>>>) -> Template {
check(submission.url).await;
Template::render("add-installation", rocket_dyn_templates::context! {})
}

View File

@ -2,5 +2,5 @@ mod check;
use crate::check::check;
fn main() {
check();
check("https://code.antopie.org/");
}