mirror of
https://github.com/stoatchat/stoatchat.git
synced 2026-07-06 03:06:04 +00:00
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",
|
||||
"tokio 1.47.1",
|
||||
"tracing",
|
||||
"urlencoding",
|
||||
"utoipa",
|
||||
"utoipa-scalar",
|
||||
]
|
||||
|
||||
@@ -45,4 +45,3 @@ tracing = "0.1"
|
||||
|
||||
# Utils
|
||||
lru_time_cache = "0.11.11"
|
||||
urlencoding = "2.1.3"
|
||||
|
||||
@@ -4,8 +4,6 @@ FROM ghcr.io/revoltchat/base:latest AS builder
|
||||
# Bundle Stage
|
||||
FROM gcr.io/distroless/cc-debian12:nonroot
|
||||
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
|
||||
USER nonroot
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//! Interal Tenor API wrapper
|
||||
//! Internal Tenor API wrapper
|
||||
|
||||
use std::{sync::Arc, time::Duration};
|
||||
|
||||
@@ -7,7 +7,6 @@ use reqwest::Client;
|
||||
use revolt_coalesced::{CoalescionService, CoalescionServiceConfig};
|
||||
use serde::de::DeserializeOwned;
|
||||
use tokio::sync::RwLock;
|
||||
use urlencoding::encode as url_encode;
|
||||
|
||||
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
|
||||
.client
|
||||
.get(format!("{TENOR_API_BASE_URL}{path}"))
|
||||
.query(query)
|
||||
.send()
|
||||
.await
|
||||
.inspect_err(|e| {
|
||||
@@ -72,7 +72,7 @@ impl Tenor {
|
||||
.map_err(|_| TenorError::HttpError)?;
|
||||
|
||||
let text = response.text().await.map_err(|e| {
|
||||
println!("{e:?}");
|
||||
revolt_config::capture_error(&e);
|
||||
TenorError::HttpError
|
||||
})?;
|
||||
|
||||
@@ -95,24 +95,21 @@ impl Tenor {
|
||||
}
|
||||
}
|
||||
|
||||
let res = self.coalescion.execute(unique_key.clone(), || {
|
||||
let mut path = format!(
|
||||
"/search?key={}&q={}&client_key=Gifbox&media_filter=webm,tinywebm&locale={}&contentfilter=high&limit={limit}",
|
||||
&self.key,
|
||||
url_encode(query),
|
||||
url_encode(locale),
|
||||
);
|
||||
|
||||
if !position.is_empty() {
|
||||
path.push_str("&pos=");
|
||||
path.push_str(position);
|
||||
};
|
||||
|
||||
if is_category {
|
||||
path.push_str("&component=categories");
|
||||
}
|
||||
|
||||
self.request::<types::PaginatedMediaResponse>(path)
|
||||
let res = self.coalescion.execute(unique_key.clone(), || async move {
|
||||
self.request::<types::PaginatedMediaResponse>(
|
||||
"/search",
|
||||
&[
|
||||
Some(("key", &self.key)),
|
||||
Some(("q", query)),
|
||||
Some(("client_key", "Gifbox")),
|
||||
Some(("media_filter", "webm,tinywebm")),
|
||||
Some(("locale", locale)),
|
||||
Some(("contentfilter", "high")),
|
||||
Some(("limit", &limit.to_string())),
|
||||
position.is_empty().then_some(("pos", position)),
|
||||
is_category.then_some(("component", "categories"))
|
||||
]
|
||||
).await
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -138,14 +135,16 @@ impl Tenor {
|
||||
|
||||
let res = self
|
||||
.coalescion
|
||||
.execute(unique_key.clone(), || {
|
||||
let path = format!(
|
||||
"/categories?key={}&client_key=Gifbox&locale={}&contentfilter=high",
|
||||
&self.key,
|
||||
url_encode(locale),
|
||||
);
|
||||
|
||||
self.request::<types::CategoriesResponse>(path)
|
||||
.execute(unique_key.clone(), || async move {
|
||||
self.request::<types::CategoriesResponse>(
|
||||
"/categories",
|
||||
&[
|
||||
Some(("key", &self.key)),
|
||||
Some(("client_key", "Gifbox")),
|
||||
Some(("locale", locale)),
|
||||
Some(("contentfilter", "high")),
|
||||
]
|
||||
).await
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
@@ -174,19 +173,19 @@ impl Tenor {
|
||||
}
|
||||
}
|
||||
|
||||
let res = self.coalescion.execute(unique_key.clone(), || {
|
||||
let mut path = format!(
|
||||
"/featured?key={}&client_key=Gifbox&media_filter=webm,tinywebm&locale={}&contentfilter=high&limit={limit}",
|
||||
&self.key,
|
||||
url_encode(locale),
|
||||
);
|
||||
|
||||
if !position.is_empty() {
|
||||
path.push_str("&pos=");
|
||||
path.push_str(position);
|
||||
};
|
||||
|
||||
self.request::<types::PaginatedMediaResponse>(path)
|
||||
let res = self.coalescion.execute(unique_key.clone(), || async move {
|
||||
self.request::<types::PaginatedMediaResponse>(
|
||||
"/featured",
|
||||
&[
|
||||
Some(("key", &self.key)),
|
||||
Some(("client_key", "Gifbox")),
|
||||
Some(("media_filter", "webm,tinywebm")),
|
||||
Some(("locale", locale)),
|
||||
Some(("contentfilter", "high")),
|
||||
Some(("limit", &limit.to_string())),
|
||||
position.is_empty().then_some(("pos", position)),
|
||||
]
|
||||
).await
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
Reference in New Issue
Block a user