|
|
@ -1,10 +1,20 @@
|
|
|
|
use utils::error::Result;
|
|
|
|
use utils::error::Result;
|
|
|
|
|
|
|
|
|
|
|
|
use actix_web::{get, http::header, web, App, HttpResponse, HttpServer, Responder};
|
|
|
|
use actix_web::{get, http::header, web, App, HttpResponse, HttpServer, Responder};
|
|
|
|
|
|
|
|
use clap::Parser;
|
|
|
|
use rand::seq::SliceRandom;
|
|
|
|
use rand::seq::SliceRandom;
|
|
|
|
|
|
|
|
|
|
|
|
pub const BING: &str = "https://www.bing.com/images/search";
|
|
|
|
pub const BING: &str = "https://www.bing.com/images/search";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// An API for fetching images of a query, sourced from Microsoft Bing.
|
|
|
|
|
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
|
|
|
|
#[command(author, version, about, long_about = None)]
|
|
|
|
|
|
|
|
struct Args {
|
|
|
|
|
|
|
|
/// The port at which to run.
|
|
|
|
|
|
|
|
#[arg(short, long, default_value_t=3002)]
|
|
|
|
|
|
|
|
port: u16,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async fn get_images(query: &str) -> reqwest::Result<Vec<String>> {
|
|
|
|
async fn get_images(query: &str) -> reqwest::Result<Vec<String>> {
|
|
|
|
use lazy_static::lazy_static;
|
|
|
|
use lazy_static::lazy_static;
|
|
|
|
use scraper::{Html, Selector};
|
|
|
|
use scraper::{Html, Selector};
|
|
|
@ -70,7 +80,7 @@ async fn main() -> std::io::Result<()> {
|
|
|
|
.service(route_query_random)
|
|
|
|
.service(route_query_random)
|
|
|
|
.service(route_query_index)
|
|
|
|
.service(route_query_index)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.bind(("127.0.0.1", 3002))?
|
|
|
|
.bind(("127.0.0.1", Args::parse().port))?
|
|
|
|
.run()
|
|
|
|
.run()
|
|
|
|
.await
|
|
|
|
.await
|
|
|
|
}
|
|
|
|
}
|
|
|
|