Skip to content

Commit 8471049

Browse files
klopez4212Princess DonutDuncanwpfleger96Hayt
authored
feat(desktop): add KLIPY GIF search to composers (#5554)
## Summary - Supersedes #1913 with a KLIPY-hosted URL implementation. - Adds KLIPY GIF search and trending results to desktop message and forum composers. - Keeps selected GIFs hosted by KLIPY; Buzz stores only the external URL and media metadata (no imeta tag, since relays only accept hash-backed local `/media/` entries). - Aligns the Emoji/GIF picker with Buzz's standard segmented control, theme surfaces, and motion behavior. ## Relay-to-provider boundary - The relay proxies KLIPY search/share so the `BUZZ_KLIPY_API_KEY` never reaches the desktop; the key stays server-side behind a redacted `Debug` impl. - The dedicated GIF `reqwest` client sets `redirect::Policy::none()`. Because the API key rides in the request path, following a provider `3xx` could replay a key-bearing URL to an attacker-chosen host (an SSRF/key-disclosure primitive). With redirects disabled, a `3xx` returns as a non-success status that the handlers map to a generic `502`; the `Location` target is never read or forwarded. - Admission reuses the established NIP-98, membership, replay, and per-pubkey rate-limit gates, with an upstream response-size cap and allowlisting so KLIPY error bodies never cross the relay boundary. ## Accessibility - Under `prefers-reduced-motion: reduce`, the picker grid renders a static provider poster (a normalized `jpg` asset) instead of the animated preview, or a named static placeholder when no poster is available. It reacts to preference changes while mounted. `no-preference` keeps the animated preview. - Selected GIFs carry their title through `ImetaMedia`'s `displayLabel`, so the composer thumbnail, preview dialog, editor, lightbox, and remove control all derive one non-empty accessible name instead of an empty `Attachment ` label. Ordinary hashed uploads keep their existing hash-derived names. --------- Signed-off-by: kenny lopez <[email protected]> Signed-off-by: Kenny Lopez <[email protected]> Signed-off-by: Will Pfleger <[email protected]> Signed-off-by: Duncan <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz> Signed-off-by: Hayt <9e1c23a3fd83f61da34420e4e88ff1b16e45cafcc0cd9019eb07d4ecfa8ca9b0@buzz.block.builderlab.xyz> Co-authored-by: Princess Donut <b238ea756dee4d98afa5883fc7f1de61eeabe65bf700e3a5a5a80db5e42e2c2b@buzz.block.builderlab.xyz> Co-authored-by: Duncan <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz> Co-authored-by: Will Pfleger <[email protected]> Co-authored-by: Hayt <9e1c23a3fd83f61da34420e4e88ff1b16e45cafcc0cd9019eb07d4ecfa8ca9b0@buzz.block.builderlab.xyz>
1 parent e8cd751 commit 8471049

34 files changed

Lines changed: 2215 additions & 146 deletions

‎.env.example‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,15 @@ RELAY_URL=ws://localhost:3000
5959
# (use `just web` for Vite HMR instead).
6060
# BUZZ_WEB_DIR=./web/dist
6161

62+
# Optional relay-owned KLIPY key. When set, NIP-11 advertises GIF search and
63+
# authenticated desktop clients use this relay as the metadata/search proxy.
64+
# Keep the real value in your deployment's secret manager; never commit it.
65+
# BUZZ_KLIPY_API_KEY=
66+
6267
# Shared Redis-backed admission limits. Defaults shown below; each value must
6368
# be a positive integer.
6469
# BUZZ_RATE_LIMIT_HUMAN_MESSAGES_PER_MIN=60
70+
# BUZZ_RATE_LIMIT_GIF_SEARCHES_PER_MIN=30
6571
# BUZZ_RATE_LIMIT_HUMAN_API_CALLS_PER_MIN=300
6672
# BUZZ_RATE_LIMIT_HUMAN_WS_EVENTS_PER_SEC=10
6773
# BUZZ_RATE_LIMIT_AGENT_STANDARD_MESSAGES_PER_MIN=120

‎crates/buzz-auth/src/rate_limit.rs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ pub enum LimitType {
6060
Messages,
6161
/// HTTP REST API calls.
6262
ApiCalls,
63+
/// Relay-proxied GIF metadata searches.
64+
GifSearches,
6365
/// All WebSocket events (broader than `Messages`).
6466
WsEvents,
6567
/// Concurrent WebSocket connections from a single IP address.
@@ -72,6 +74,7 @@ impl LimitType {
7274
match self {
7375
Self::Messages => "msg",
7476
Self::ApiCalls => "api",
77+
Self::GifSearches => "gif",
7578
Self::WsEvents => "ws",
7679
Self::IpConnections => "conn",
7780
}
@@ -87,6 +90,10 @@ pub struct RateLimitConfig {
8790
/// Maximum messages per minute for human users. Default: 60.
8891
#[serde(default = "default_human_msg")]
8992
pub human_messages_per_min: u64,
93+
/// Maximum relay-proxied GIF searches per minute for each pubkey.
94+
/// Default: 30.
95+
#[serde(default = "default_gif_searches")]
96+
pub gif_searches_per_min: u64,
9097
/// Maximum HTTP API calls per minute for human users. Default: 300.
9198
#[serde(default = "default_human_api")]
9299
pub human_api_calls_per_min: u64,
@@ -110,6 +117,9 @@ pub struct RateLimitConfig {
110117
fn default_human_msg() -> u64 {
111118
60
112119
}
120+
fn default_gif_searches() -> u64 {
121+
30
122+
}
113123
fn default_human_api() -> u64 {
114124
300
115125
}
@@ -133,6 +143,7 @@ impl Default for RateLimitConfig {
133143
fn default() -> Self {
134144
Self {
135145
human_messages_per_min: default_human_msg(),
146+
gif_searches_per_min: default_gif_searches(),
136147
human_api_calls_per_min: default_human_api(),
137148
human_ws_events_per_sec: default_human_ws(),
138149
agent_standard_messages_per_min: default_agent_std_msg(),
@@ -272,6 +283,17 @@ mod tests {
272283
assert!(key.ends_with(":msg"));
273284
}
274285

286+
#[test]
287+
fn gif_searches_have_an_independent_quota_key() {
288+
let ctx = fixture_ctx("relay-a.example");
289+
let keys = Keys::generate();
290+
let gif_key = rate_limit_key(&ctx, &keys.public_key(), &LimitType::GifSearches);
291+
let api_key = rate_limit_key(&ctx, &keys.public_key(), &LimitType::ApiCalls);
292+
293+
assert!(gif_key.ends_with(":gif"));
294+
assert_ne!(gif_key, api_key);
295+
}
296+
275297
#[test]
276298
fn rate_limit_key_isolates_communities_for_same_pubkey() {
277299
// The S1 cross-community isolation fence at the rate-limit key layer:

0 commit comments

Comments
 (0)