From 6089cfb42843097b48827262094792c6d18732bf Mon Sep 17 00:00:00 2001 From: Piyush Mishra Date: Wed, 12 May 2021 16:09:09 +0530 Subject: [PATCH] git support --- Cargo.lock | 18 ++++++++++++++++++ Cargo.toml | 3 ++- src/main.rs | 29 +++++++++++++++++++++++++++-- static/css/style.css | 19 +++++++++++++++++-- static/img/gif.svg | 37 +++++++++++++++++++++++++++++++++++++ static/index.html | 16 ++++++++++------ static/js/app.js | 36 ++++++++++++++++++++++++++++++++---- static/js/message.js | 3 --- static/js/state.js | 2 ++ 9 files changed, 145 insertions(+), 18 deletions(-) create mode 100644 static/img/gif.svg diff --git a/Cargo.lock b/Cargo.lock index 1fab63e..3c8cc76 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -67,6 +67,8 @@ dependencies = [ "futures-util", "http", "log", + "openssl", + "tokio-openssl", "trust-dns-proto", "trust-dns-resolver", ] @@ -103,6 +105,7 @@ dependencies = [ "actix-rt", "actix-service", "actix-threadpool", + "actix-tls", "actix-utils", "base64", "bitflags", @@ -264,6 +267,8 @@ dependencies = [ "actix-service", "actix-utils", "futures-util", + "openssl", + "tokio-openssl", ] [[package]] @@ -314,6 +319,7 @@ dependencies = [ "fxhash", "log", "mime", + "openssl", "pin-project 1.0.5", "regex", "serde", @@ -447,6 +453,7 @@ dependencies = [ "futures-core", "log", "mime", + "openssl", "percent-encoding", "rand 0.7.3", "serde", @@ -1199,6 +1206,7 @@ dependencies = [ "clap", "env_logger", "futures", + "openssl", "rand 0.8.3", "serde", "serde_json", @@ -2042,6 +2050,16 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "tokio-openssl" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c4b08c5f4208e699ede3df2520aca2e82401b2de33f45e96696a074480be594" +dependencies = [ + "openssl", + "tokio", +] + [[package]] name = "tokio-util" version = "0.2.0" diff --git a/Cargo.toml b/Cargo.toml index 88fa857..014eff3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,12 +9,13 @@ edition = "2018" [dependencies] actix = "0.10" -actix-web = "3" +actix-web = { version = "3", features = ["openssl"] } actix-web-actors = "3" actix-broker = "0.3.1" actix-files = "0.5.0" actix-ratelimit = "0.3.1" env_logger = "0.8.3" +openssl = "0.10.28" clap = "2.33.3" serde = "1.0.123" diff --git a/src/main.rs b/src/main.rs index 978f542..40f75fd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,11 +8,14 @@ //! |--> ws_sansad3 <---- / //! |--> ws_sansad4 <----/ //! - -use actix_web::{App, Error, HttpRequest, HttpResponse, HttpServer, middleware::Logger, web}; +use actix_web::{ + App, Error, HttpRequest, HttpResponse, HttpServer, middleware::Logger, web, + client::{Client, Connector} +}; use actix_files as fs; use actix_web_actors::ws; use actix_ratelimit::{RateLimiter, MemoryStore, MemoryStoreActor}; +use openssl::ssl::{SslConnector, SslMethod}; use ws_sansad::WsSansad; mod config; @@ -38,6 +41,8 @@ async fn main() -> std::io::Result<()> { ) .wrap(Logger::new("%t [%{x-forwarded-for}i] %s %{User-Agent}i %r")) .service(web::resource("/ws/").route(web::get().to(ws_index))) + .service(web::resource("/gif/").route(web::get().to(gif))) + .service(web::resource("/gif/{query}").route(web::get().to(gif))) .service(fs::Files::new("/", &static_path).index_file("index.html")) }) .bind(config.bind_address)? @@ -48,3 +53,23 @@ async fn main() -> std::io::Result<()> { async fn ws_index(req: HttpRequest, stream: web::Payload) -> Result { ws::start(WsSansad::new(), &req, stream) } + +async fn gif(req: HttpRequest) -> Result { + let name = req.match_info().get("query").unwrap_or(""); + let builder = SslConnector::builder(SslMethod::tls()).unwrap(); + + let client = Client::builder() + .connector(Connector::new().ssl(builder.build()).finish()) + .finish(); + + + let url = format!("https://g.tenor.com/v1/search?q={}&key=LIVDSRZULELA&limit=20&media_filter=tinygif", name); + let response = client.get(url) + .header("User-Agent", "actix-web/3.0") + .send() + .await? + .body() + .await?; + + Ok(HttpResponse::Ok().content_type("application/json").body(response)) +} \ No newline at end of file diff --git a/static/css/style.css b/static/css/style.css index cf907f3..ce60af9 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -289,8 +289,23 @@ input { margin-bottom: 0.5rem; } -.clip-win.camera-clip { - width: 314px; +.clip-win.gif-clip { + width: calc(100% - 2*8px - 3*5px); + max-width: 720px; + /* max-height: 70%; */ +} + +.gif-clip .button { + max-width: 120px; + padding: 0.5rem; + margin: 0.5rem; + display: inline-flex; +} + +.gif-clip > #gif_area { + overflow-y: auto; + max-height: 350px; + padding: 1rem; } #dialog { diff --git a/static/img/gif.svg b/static/img/gif.svg new file mode 100644 index 0000000..d9059bd --- /dev/null +++ b/static/img/gif.svg @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/static/index.html b/static/index.html index 552c06f..e0c79a5 100644 --- a/static/index.html +++ b/static/index.html @@ -178,10 +178,15 @@ - -