fix: swap to using reqwest for query building
This commit is contained in:
committed by
Angelo Kontaxis
parent
154204742d
commit
38dd4d1079
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -6525,7 +6525,6 @@ dependencies = [
|
|||||||
"serde_json",
|
"serde_json",
|
||||||
"tokio 1.47.1",
|
"tokio 1.47.1",
|
||||||
"tracing",
|
"tracing",
|
||||||
"urlencoding",
|
|
||||||
"utoipa",
|
"utoipa",
|
||||||
"utoipa-scalar",
|
"utoipa-scalar",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -45,4 +45,3 @@ tracing = "0.1"
|
|||||||
|
|
||||||
# Utils
|
# Utils
|
||||||
lru_time_cache = "0.11.11"
|
lru_time_cache = "0.11.11"
|
||||||
urlencoding = "2.1.3"
|
|
||||||
|
|||||||
@@ -4,8 +4,6 @@ FROM ghcr.io/revoltchat/base:latest AS builder
|
|||||||
# Bundle Stage
|
# Bundle Stage
|
||||||
FROM gcr.io/distroless/cc-debian12:nonroot
|
FROM gcr.io/distroless/cc-debian12:nonroot
|
||||||
COPY --from=builder /home/rust/src/target/release/revolt-gifbox ./
|
COPY --from=builder /home/rust/src/target/release/revolt-gifbox ./
|
||||||
COPY --from=mwader/static-ffmpeg:7.0.2 /ffmpeg /usr/local/bin/
|
|
||||||
COPY --from=mwader/static-ffmpeg:7.0.2 /ffprobe /usr/local/bin/
|
|
||||||
|
|
||||||
EXPOSE 14706
|
EXPOSE 14706
|
||||||
USER nonroot
|
USER nonroot
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//! Interal Tenor API wrapper
|
//! Internal Tenor API wrapper
|
||||||
|
|
||||||
use std::{sync::Arc, time::Duration};
|
use std::{sync::Arc, time::Duration};
|
||||||
|
|
||||||
@@ -7,7 +7,6 @@ use reqwest::Client;
|
|||||||
use revolt_coalesced::{CoalescionService, CoalescionServiceConfig};
|
use revolt_coalesced::{CoalescionService, CoalescionServiceConfig};
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
use urlencoding::encode as url_encode;
|
|
||||||
|
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
@@ -60,10 +59,11 @@ impl Tenor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn request<T: DeserializeOwned>(&self, path: String) -> Result<Arc<T>, TenorError> {
|
pub async fn request<T: DeserializeOwned>(&self, path: &str, query: &[Option<(&str, &str)>]) -> Result<Arc<T>, TenorError> {
|
||||||
let response = self
|
let response = self
|
||||||
.client
|
.client
|
||||||
.get(format!("{TENOR_API_BASE_URL}{path}"))
|
.get(format!("{TENOR_API_BASE_URL}{path}"))
|
||||||
|
.query(query)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
.inspect_err(|e| {
|
.inspect_err(|e| {
|
||||||
@@ -72,7 +72,7 @@ impl Tenor {
|
|||||||
.map_err(|_| TenorError::HttpError)?;
|
.map_err(|_| TenorError::HttpError)?;
|
||||||
|
|
||||||
let text = response.text().await.map_err(|e| {
|
let text = response.text().await.map_err(|e| {
|
||||||
println!("{e:?}");
|
revolt_config::capture_error(&e);
|
||||||
TenorError::HttpError
|
TenorError::HttpError
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
@@ -95,24 +95,21 @@ impl Tenor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = self.coalescion.execute(unique_key.clone(), || {
|
let res = self.coalescion.execute(unique_key.clone(), || async move {
|
||||||
let mut path = format!(
|
self.request::<types::PaginatedMediaResponse>(
|
||||||
"/search?key={}&q={}&client_key=Gifbox&media_filter=webm,tinywebm&locale={}&contentfilter=high&limit={limit}",
|
"/search",
|
||||||
&self.key,
|
&[
|
||||||
url_encode(query),
|
Some(("key", &self.key)),
|
||||||
url_encode(locale),
|
Some(("q", query)),
|
||||||
);
|
Some(("client_key", "Gifbox")),
|
||||||
|
Some(("media_filter", "webm,tinywebm")),
|
||||||
if !position.is_empty() {
|
Some(("locale", locale)),
|
||||||
path.push_str("&pos=");
|
Some(("contentfilter", "high")),
|
||||||
path.push_str(position);
|
Some(("limit", &limit.to_string())),
|
||||||
};
|
position.is_empty().then_some(("pos", position)),
|
||||||
|
is_category.then_some(("component", "categories"))
|
||||||
if is_category {
|
]
|
||||||
path.push_str("&component=categories");
|
).await
|
||||||
}
|
|
||||||
|
|
||||||
self.request::<types::PaginatedMediaResponse>(path)
|
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -138,14 +135,16 @@ impl Tenor {
|
|||||||
|
|
||||||
let res = self
|
let res = self
|
||||||
.coalescion
|
.coalescion
|
||||||
.execute(unique_key.clone(), || {
|
.execute(unique_key.clone(), || async move {
|
||||||
let path = format!(
|
self.request::<types::CategoriesResponse>(
|
||||||
"/categories?key={}&client_key=Gifbox&locale={}&contentfilter=high",
|
"/categories",
|
||||||
&self.key,
|
&[
|
||||||
url_encode(locale),
|
Some(("key", &self.key)),
|
||||||
);
|
Some(("client_key", "Gifbox")),
|
||||||
|
Some(("locale", locale)),
|
||||||
self.request::<types::CategoriesResponse>(path)
|
Some(("contentfilter", "high")),
|
||||||
|
]
|
||||||
|
).await
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@@ -174,19 +173,19 @@ impl Tenor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let res = self.coalescion.execute(unique_key.clone(), || {
|
let res = self.coalescion.execute(unique_key.clone(), || async move {
|
||||||
let mut path = format!(
|
self.request::<types::PaginatedMediaResponse>(
|
||||||
"/featured?key={}&client_key=Gifbox&media_filter=webm,tinywebm&locale={}&contentfilter=high&limit={limit}",
|
"/featured",
|
||||||
&self.key,
|
&[
|
||||||
url_encode(locale),
|
Some(("key", &self.key)),
|
||||||
);
|
Some(("client_key", "Gifbox")),
|
||||||
|
Some(("media_filter", "webm,tinywebm")),
|
||||||
if !position.is_empty() {
|
Some(("locale", locale)),
|
||||||
path.push_str("&pos=");
|
Some(("contentfilter", "high")),
|
||||||
path.push_str(position);
|
Some(("limit", &limit.to_string())),
|
||||||
};
|
position.is_empty().then_some(("pos", position)),
|
||||||
|
]
|
||||||
self.request::<types::PaginatedMediaResponse>(path)
|
).await
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user