From 8e241b34356b360d13dfb0eb1d23598a49f85f8e Mon Sep 17 00:00:00 2001 From: trisua Date: Sat, 10 May 2025 22:11:12 -0400 Subject: [PATCH] fix: gif emoji uploading fix: external image proxy --- .../src/public/html/communities/settings.html | 2 +- .../app/src/public/html/profile/settings.html | 7 ++---- .../src/routes/api/v1/communities/emojis.rs | 22 ++++++++++--------- crates/core/src/model/mod.rs | 4 +--- crates/shared/src/markdown.rs | 2 +- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/crates/app/src/public/html/communities/settings.html b/crates/app/src/public/html/communities/settings.html index 74f4edf..236f6db 100644 --- a/crates/app/src/public/html/communities/settings.html +++ b/crates/app/src/public/html/communities/settings.html @@ -191,7 +191,7 @@ id="avatar_file" name="file" type="file" - accept="image/png,image/jpeg,image/avif,image/webp" + accept="image/png,image/jpeg,image/avif,image/webp,image/gif" class="w-content" /> diff --git a/crates/app/src/public/html/profile/settings.html b/crates/app/src/public/html/profile/settings.html index fc14341..515e313 100644 --- a/crates/app/src/public/html/profile/settings.html +++ b/crates/app/src/public/html/profile/settings.html @@ -447,12 +447,9 @@
  • Use custom CSS on your profile
  • Ability to use community emojis outside of - their community (soon) -
  • -
  • - Ability to upload and use gif emojis - (soon) + their community
  • +
  • Ability to upload and use gif emojis
  • Create infinite stack timelines
  • diff --git a/crates/app/src/routes/api/v1/communities/emojis.rs b/crates/app/src/routes/api/v1/communities/emojis.rs index b441031..6e31d86 100644 --- a/crates/app/src/routes/api/v1/communities/emojis.rs +++ b/crates/app/src/routes/api/v1/communities/emojis.rs @@ -141,16 +141,18 @@ pub async fn create_request( .await { Ok(_) => { - if let Err(e) = save_buffer( - &upload.path(&data.0).to_string(), - img.0.to_vec(), - if is_animated { - ImageFormat::Gif - } else { - ImageFormat::WebP - }, - ) { - return Json(Error::MiscError(e.to_string()).into()); + if is_animated { + if let Err(e) = upload.write(&data.0, &img.0) { + return Json(Error::MiscError(e.to_string()).into()); + } + } else { + if let Err(e) = save_buffer( + &upload.path(&data.0).to_string(), + img.0.to_vec(), + ImageFormat::WebP, + ) { + return Json(Error::MiscError(e.to_string()).into()); + } } Json(ApiReturn { diff --git a/crates/core/src/model/mod.rs b/crates/core/src/model/mod.rs index 4ac7d83..12b52b4 100644 --- a/crates/core/src/model/mod.rs +++ b/crates/core/src/model/mod.rs @@ -66,9 +66,7 @@ impl Display for Error { Self::UsernameInUse => "Username in use".to_string(), Self::TitleInUse => "Title in use".to_string(), Self::QuestionsDisabled => "You are not allowed to ask questions there".to_string(), - Self::RequiresSupporter => { - "Only site supporters can upload GIF files as their avatar/banner".to_string() - } + Self::RequiresSupporter => "Only site supporters can do this".to_string(), _ => format!("An unknown error as occurred: ({:?})", self), }) } diff --git a/crates/shared/src/markdown.rs b/crates/shared/src/markdown.rs index ba5e50e..93aac30 100644 --- a/crates/shared/src/markdown.rs +++ b/crates/shared/src/markdown.rs @@ -39,7 +39,7 @@ pub fn render_markdown(input: &str) -> String { .to_string() .replace( "src=\"http", - "loading=\"lazy\" src=\"/api/v1/util/proxy?url=", + "loading=\"lazy\" src=\"/api/v1/util/proxy?url=http", ) .replace("