diff --git a/crates/api_common/src/request.rs b/crates/api_common/src/request.rs index cc506b896d..a7c2a348ad 100644 --- a/crates/api_common/src/request.rs +++ b/crates/api_common/src/request.rs @@ -12,7 +12,7 @@ use futures::StreamExt; use lemmy_db_schema::{ newtypes::DbUrl, source::{ - images::{ImageDetailsForm, LocalImage, LocalImageForm}, + images::{ImageDetailsInsertForm, LocalImage, LocalImageForm}, post::{Post, PostUpdateForm}, site::Site, }, @@ -271,17 +271,20 @@ pub struct PictrsFileDetails { pub height: u16, pub content_type: String, pub created_at: DateTime, + // TODO this can get changed to String on future versions of pictrs + pub blurhash: Option, } impl PictrsFileDetails { /// Builds the image form. This should always use the thumbnail_url, /// Because the post_view joins to it - pub fn build_image_details_form(&self, thumbnail_url: &Url) -> ImageDetailsForm { - ImageDetailsForm { + pub fn build_image_details_form(&self, thumbnail_url: &Url) -> ImageDetailsInsertForm { + ImageDetailsInsertForm { link: thumbnail_url.clone().into(), width: self.width.into(), height: self.height.into(), content_type: self.content_type.clone(), + blurhash: self.blurhash.clone(), } } } diff --git a/crates/db_schema/src/impls/images.rs b/crates/db_schema/src/impls/images.rs index 8ded98e414..92688b8da6 100644 --- a/crates/db_schema/src/impls/images.rs +++ b/crates/db_schema/src/impls/images.rs @@ -1,7 +1,7 @@ use crate::{ newtypes::DbUrl, schema::{image_details, local_image, remote_image}, - source::images::{ImageDetails, ImageDetailsForm, LocalImage, LocalImageForm, RemoteImage}, + source::images::{ImageDetails, ImageDetailsInsertForm, LocalImage, LocalImageForm, RemoteImage}, utils::{get_conn, DbPool}, }; use diesel::{ @@ -20,7 +20,7 @@ impl LocalImage { pub async fn create( pool: &mut DbPool<'_>, form: &LocalImageForm, - image_details_form: &ImageDetailsForm, + image_details_form: &ImageDetailsInsertForm, ) -> Result { let conn = &mut get_conn(pool).await?; conn @@ -84,7 +84,10 @@ impl RemoteImage { } impl ImageDetails { - pub async fn create(pool: &mut DbPool<'_>, form: &ImageDetailsForm) -> Result { + pub async fn create( + pool: &mut DbPool<'_>, + form: &ImageDetailsInsertForm, + ) -> Result { let conn = &mut get_conn(pool).await?; insert_into(image_details::table) diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index f2b186d35d..8596d5352a 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -303,6 +303,8 @@ diesel::table! { width -> Int4, height -> Int4, content_type -> Text, + #[max_length = 50] + blurhash -> Nullable, } } diff --git a/crates/db_schema/src/source/images.rs b/crates/db_schema/src/source/images.rs index acd339d8ea..7d44efdc3d 100644 --- a/crates/db_schema/src/source/images.rs +++ b/crates/db_schema/src/source/images.rs @@ -64,14 +64,16 @@ pub struct ImageDetails { pub width: i32, pub height: i32, pub content_type: String, + pub blurhash: Option, } #[derive(Debug, Clone)] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", diesel(table_name = image_details))] -pub struct ImageDetailsForm { +pub struct ImageDetailsInsertForm { pub link: DbUrl, pub width: i32, pub height: i32, pub content_type: String, + pub blurhash: Option, } diff --git a/migrations/2024-11-25-161129_add_blurhash_to_image_details/down.sql b/migrations/2024-11-25-161129_add_blurhash_to_image_details/down.sql new file mode 100644 index 0000000000..0f5a50e7dd --- /dev/null +++ b/migrations/2024-11-25-161129_add_blurhash_to_image_details/down.sql @@ -0,0 +1,3 @@ +ALTER TABLE image_details + DROP COLUMN blurhash; + diff --git a/migrations/2024-11-25-161129_add_blurhash_to_image_details/up.sql b/migrations/2024-11-25-161129_add_blurhash_to_image_details/up.sql new file mode 100644 index 0000000000..9a3f5e1153 --- /dev/null +++ b/migrations/2024-11-25-161129_add_blurhash_to_image_details/up.sql @@ -0,0 +1,6 @@ +-- Add a blurhash column for image_details +ALTER TABLE image_details +-- Supposed to be 20-30 chars, use 50 to be safe +-- TODO this should be made not null for future versions of pictrs + ADD COLUMN blurhash varchar(50); +