call check() on add-installation + make check async
This commit is contained in:
parent
f564e4f366
commit
2f06c4ec1f
|
@ -16,7 +16,6 @@ texting_robots = "0.2.2"
|
|||
version = "0.11.24"
|
||||
default-features = false
|
||||
features = [
|
||||
"blocking",
|
||||
"rustls-tls",
|
||||
"socks",
|
||||
]
|
||||
|
|
14
src/check.rs
14
src/check.rs
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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! {})
|
||||
}
|
||||
|
|
|
@ -2,5 +2,5 @@ mod check;
|
|||
use crate::check::check;
|
||||
|
||||
fn main() {
|
||||
check();
|
||||
check("https://code.antopie.org/");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue