Skip to content
Snippets Groups Projects
Commit 0765b8ec authored by DeathwingTheBoss's avatar DeathwingTheBoss
Browse files

add "method == "call"" support

parent 5dd48bab
No related branches found
No related tags found
No related merge requests found
...@@ -260,6 +260,17 @@ dependencies = [ ...@@ -260,6 +260,17 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "async-recursion"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fd55a5ba1179988837d24ab4c7cc8ed6efdeff578ede0416b4225a5fca35bd0"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.2",
]
[[package]] [[package]]
name = "async-trait" name = "async-trait"
version = "0.1.67" version = "0.1.67"
...@@ -574,10 +585,11 @@ checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257" ...@@ -574,10 +585,11 @@ checksum = "0688c2a7f92e427f44895cd63841bff7b29f8d7a1648b9e7e07a4a365b2e1257"
[[package]] [[package]]
name = "drone" name = "drone"
version = "0.2.3" version = "0.2.4"
dependencies = [ dependencies = [
"actix-cors", "actix-cors",
"actix-web", "actix-web",
"async-recursion",
"config", "config",
"humantime", "humantime",
"lru_time_cache", "lru_time_cache",
......
[package] [package]
name = "drone" name = "drone"
version = "0.2.3" version = "0.2.4"
edition = "2021" edition = "2021"
authors = ["Deathwing <hi@deathwing.me>"] authors = ["Deathwing <hi@deathwing.me>"]
description = "A caching reverse-proxy application for the Hive blockchain." description = "A caching reverse-proxy application for the Hive blockchain."
...@@ -17,3 +17,4 @@ humantime = "2.1.0" ...@@ -17,3 +17,4 @@ humantime = "2.1.0"
config = "0.13.3" config = "0.13.3"
serde_with = "2.3.1" serde_with = "2.3.1"
actix-cors = "0.6.4" actix-cors = "0.6.4"
async-recursion = "1.0.5"
\ No newline at end of file
use actix_cors::Cors; use actix_cors::Cors;
use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, Responder}; use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, Responder};
use async_recursion::async_recursion;
use config::Config; use config::Config;
use lru_time_cache::LruCache; use lru_time_cache::LruCache;
use reqwest::{Client, ClientBuilder}; use reqwest::{Client, ClientBuilder};
...@@ -113,6 +114,7 @@ impl Endpoints { ...@@ -113,6 +114,7 @@ impl Endpoints {
} }
} }
#[async_recursion]
async fn handle_request( async fn handle_request(
request: &APIRequest, request: &APIRequest,
data: &web::Data<AppData>, data: &web::Data<AppData>,
...@@ -120,7 +122,25 @@ async fn handle_request( ...@@ -120,7 +122,25 @@ async fn handle_request(
) -> Result<APICallResponse, ErrorStructure> { ) -> Result<APICallResponse, ErrorStructure> {
// Convert the call to a struct. // Convert the call to a struct.
let client = data.webclient.clone(); let client = data.webclient.clone();
// If there's a single call, just forward it. let method = request.method.as_str();
if method == "call" {
if let Some(params) = request.params.as_array() {
if params.len() > 2 {
if let Some(method) = params[0].as_str() {
let format_new_method = format!("{}.{}", method, params[1].as_str().unwrap());
let new_params = params[2].clone();
let new_request = APIRequest {
jsonrpc: "2.0".to_string(),
id: request.id,
method: format_new_method,
params: new_params,
};
return handle_request(&new_request, data, client_ip).await;
}
}
}
}
// Get humantime for logging. // Get humantime for logging.
let human_timestamp = humantime::format_rfc3339_seconds(std::time::SystemTime::now()); let human_timestamp = humantime::format_rfc3339_seconds(std::time::SystemTime::now());
...@@ -129,7 +149,8 @@ async fn handle_request( ...@@ -129,7 +149,8 @@ async fn handle_request(
human_timestamp, client_ip, request.method, request.params, human_timestamp, client_ip, request.method, request.params,
); );
println!("{}", formatted_log); println!("{}", formatted_log);
let method = request.method.as_str();
// Pick the endpoints depending on the method. // Pick the endpoints depending on the method.
let endpoints = match method { let endpoints = match method {
// HAF // HAF
...@@ -167,6 +188,7 @@ async fn handle_request( ...@@ -167,6 +188,7 @@ async fn handle_request(
"condenser_api.get_comment_discussions_by_payout" => Endpoints::HIVEMIND, "condenser_api.get_comment_discussions_by_payout" => Endpoints::HIVEMIND,
"condenser_api.get_replies_by_last_update" => Endpoints::HIVEMIND, "condenser_api.get_replies_by_last_update" => Endpoints::HIVEMIND,
"condenser_api.get_reblogged_by" => Endpoints::HIVEMIND, "condenser_api.get_reblogged_by" => Endpoints::HIVEMIND,
"database_api.find_comments" => Endpoints::HIVEMIND,
_bridge_endpoint if method.starts_with("bridge.") => Endpoints::HIVEMIND, _bridge_endpoint if method.starts_with("bridge.") => Endpoints::HIVEMIND,
_follow_api_endpoint if method.starts_with("follow_api.") => Endpoints::HIVEMIND, // Remove when beem is updated. (Deprecated) _follow_api_endpoint if method.starts_with("follow_api.") => Endpoints::HIVEMIND, // Remove when beem is updated. (Deprecated)
_tags_api_endpoint if method.starts_with("tags_api.") => Endpoints::HIVEMIND, // Remove when beem is updated. (Deprecated) _tags_api_endpoint if method.starts_with("tags_api.") => Endpoints::HIVEMIND, // Remove when beem is updated. (Deprecated)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment