mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-12-22 19:01:32 +00:00
parent
ba3d574d92
commit
c4a88e56ee
6 changed files with 26 additions and 7 deletions
|
@ -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<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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Self, Error> {
|
||||
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<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)
|
||||
|
|
|
@ -303,6 +303,8 @@ diesel::table! {
|
|||
width -> Int4,
|
||||
height -> Int4,
|
||||
content_type -> Text,
|
||||
#[max_length = 50]
|
||||
blurhash -> Nullable<Varchar>,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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>,
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE image_details
|
||||
DROP COLUMN blurhash;
|
||||
|
|
@ -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);
|
||||
|
Loading…
Reference in a new issue