images: add port configuration

main
Elnu 1 year ago
parent 71ff7a6cdc
commit 68028e700e

1
Cargo.lock generated

@ -894,6 +894,7 @@ name = "images"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"actix-web", "actix-web",
"clap",
"lazy_static", "lazy_static",
"mime", "mime",
"rand", "rand",

@ -14,3 +14,4 @@ scraper = "0.17.1"
lazy_static = "1.4.0" lazy_static = "1.4.0"
rand = "0.8.5" rand = "0.8.5"
serde_json = "1.0.104" serde_json = "1.0.104"
clap = { version = "4.3.21", features = ["derive"] }

@ -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
} }

Loading…
Cancel
Save