feat: replace tenor with gifbox

Signed-off-by: IAmTomahawkx <iamtomahawkx@gmail.com>
This commit is contained in:
IAmTomahawkx
2026-06-30 11:46:32 -07:00
parent 7937179db7
commit 3768ee6c57

View File

@@ -10,7 +10,7 @@ use tokio::sync::RwLock;
pub mod types; pub mod types;
const TENOR_API_BASE_URL: &str = "https://tenor.googleapis.com/v2"; const TENOR_API_BASE_URL: &str = "https://compat.gifbox.me/v2";
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub enum TenorError { pub enum TenorError {
@@ -59,7 +59,11 @@ impl Tenor {
} }
} }
pub async fn request<T: DeserializeOwned>(&self, path: &str, query: &[Option<(&str, &str)>]) -> 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}"))
@@ -95,24 +99,27 @@ impl Tenor {
} }
} }
let res = self.coalescion.execute(unique_key.clone(), || async move { let res = self
self.request::<types::PaginatedMediaResponse>( .coalescion
"/search", .execute(unique_key.clone(), || async move {
&[ self.request::<types::PaginatedMediaResponse>(
Some(("key", &self.key)), "/search",
Some(("q", query)), &[
Some(("client_key", "Gifbox")), Some(("key", &self.key)),
Some(("media_filter", "webm,tinywebm")), Some(("q", query)),
Some(("locale", locale)), Some(("client_key", "Gifbox")),
Some(("contentfilter", "high")), Some(("media_filter", "webm,tinywebm")),
Some(("limit", &limit.to_string())), Some(("locale", locale)),
position.is_empty().then_some(("pos", position)), Some(("contentfilter", "high")),
is_category.then_some(("component", "categories")) Some(("limit", &limit.to_string())),
] position.is_empty().then_some(("pos", position)),
).await is_category.then_some(("component", "categories")),
}) ],
.await )
.unwrap(); .await
})
.await
.unwrap();
if let Ok(resp) = &*res { if let Ok(resp) = &*res {
self.cache.write().await.insert(unique_key, resp.clone()); self.cache.write().await.insert(unique_key, resp.clone());
@@ -143,8 +150,9 @@ impl Tenor {
Some(("client_key", "Gifbox")), Some(("client_key", "Gifbox")),
Some(("locale", locale)), Some(("locale", locale)),
Some(("contentfilter", "high")), Some(("contentfilter", "high")),
] ],
).await )
.await
}) })
.await .await
.unwrap(); .unwrap();
@@ -173,22 +181,25 @@ impl Tenor {
} }
} }
let res = self.coalescion.execute(unique_key.clone(), || async move { let res = self
self.request::<types::PaginatedMediaResponse>( .coalescion
"/featured", .execute(unique_key.clone(), || async move {
&[ self.request::<types::PaginatedMediaResponse>(
Some(("key", &self.key)), "/featured",
Some(("client_key", "Gifbox")), &[
Some(("media_filter", "webm,tinywebm")), Some(("key", &self.key)),
Some(("locale", locale)), Some(("client_key", "Gifbox")),
Some(("contentfilter", "high")), Some(("media_filter", "webm,tinywebm")),
Some(("limit", &limit.to_string())), Some(("locale", locale)),
position.is_empty().then_some(("pos", position)), Some(("contentfilter", "high")),
] Some(("limit", &limit.to_string())),
).await position.is_empty().then_some(("pos", position)),
}) ],
.await )
.unwrap(); .await
})
.await
.unwrap();
if let Ok(resp) = &*res { if let Ok(resp) = &*res {
self.featured.write().await.insert(unique_key, resp.clone()); self.featured.write().await.insert(unique_key, resp.clone());