Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding blurhash to image_details. #5227

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions crates/api_common/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -271,17 +271,20 @@ pub struct PictrsFileDetails {
pub height: u16,
pub content_type: String,
pub created_at: DateTime<Utc>,
// TODO this can get changed to String on future versions of pictrs
pub blurhash: Option<String>,
}

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(),
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions crates/db_schema/src/impls/images.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -20,7 +20,7 @@ impl LocalImage {
pub async fn create(
pool: &mut DbPool<'_>,
form: &LocalImageForm,
image_details_form: &ImageDetailsForm,
image_details_form: &ImageDetailsInsertForm,
) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
conn
Expand Down Expand Up @@ -84,7 +84,10 @@ impl RemoteImage {
}

impl ImageDetails {
pub async fn create(pool: &mut DbPool<'_>, form: &ImageDetailsForm) -> Result<usize, Error> {
pub async fn create(
pool: &mut DbPool<'_>,
form: &ImageDetailsInsertForm,
) -> Result<usize, Error> {
let conn = &mut get_conn(pool).await?;

insert_into(image_details::table)
Expand Down
2 changes: 2 additions & 0 deletions crates/db_schema/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ diesel::table! {
width -> Int4,
height -> Int4,
content_type -> Text,
#[max_length = 50]
blurhash -> Nullable<Varchar>,
}
}

Expand Down
4 changes: 3 additions & 1 deletion crates/db_schema/src/source/images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,16 @@ pub struct ImageDetails {
pub width: i32,
pub height: i32,
pub content_type: String,
pub blurhash: Option<String>,
}

#[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<String>,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE image_details
DROP COLUMN blurhash;

Original file line number Diff line number Diff line change
@@ -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);