mirror of https://github.com/LemmyNet/lemmy
Add logging for pictrs uploads (#3927)
* Add logging for pictrs uploads * cleanupmanual-html-escape
parent
797d26fdf4
commit
fe3ebea95a
@ -0,0 +1,47 @@
|
|||||||
|
use crate::{
|
||||||
|
newtypes::{ImageUploadId, LocalUserId},
|
||||||
|
schema::image_upload::dsl::{image_upload, local_user_id, pictrs_alias},
|
||||||
|
source::image_upload::{ImageUpload, ImageUploadForm},
|
||||||
|
utils::{get_conn, DbPool},
|
||||||
|
};
|
||||||
|
use diesel::{insert_into, result::Error, ExpressionMethods, QueryDsl, Table};
|
||||||
|
use diesel_async::RunQueryDsl;
|
||||||
|
|
||||||
|
impl ImageUpload {
|
||||||
|
pub async fn create(pool: &mut DbPool<'_>, form: &ImageUploadForm) -> Result<Self, Error> {
|
||||||
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
insert_into(image_upload)
|
||||||
|
.values(form)
|
||||||
|
.get_result::<Self>(conn)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_all_by_local_user_id(
|
||||||
|
pool: &mut DbPool<'_>,
|
||||||
|
user_id: &LocalUserId,
|
||||||
|
) -> Result<Vec<Self>, Error> {
|
||||||
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
image_upload
|
||||||
|
.filter(local_user_id.eq(user_id))
|
||||||
|
.select(image_upload::all_columns())
|
||||||
|
.load::<ImageUpload>(conn)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn delete(
|
||||||
|
pool: &mut DbPool<'_>,
|
||||||
|
image_upload_id: ImageUploadId,
|
||||||
|
) -> Result<usize, Error> {
|
||||||
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
diesel::delete(image_upload.find(image_upload_id))
|
||||||
|
.execute(conn)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn delete_by_alias(pool: &mut DbPool<'_>, alias: &str) -> Result<usize, Error> {
|
||||||
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
diesel::delete(image_upload.filter(pictrs_alias.eq(alias)))
|
||||||
|
.execute(conn)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
use crate::newtypes::{ImageUploadId, LocalUserId};
|
||||||
|
#[cfg(feature = "full")]
|
||||||
|
use crate::schema::image_upload;
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use serde_with::skip_serializing_none;
|
||||||
|
use std::fmt::Debug;
|
||||||
|
#[cfg(feature = "full")]
|
||||||
|
use ts_rs::TS;
|
||||||
|
use typed_builder::TypedBuilder;
|
||||||
|
|
||||||
|
#[skip_serializing_none]
|
||||||
|
#[derive(PartialEq, Eq, Debug, Clone, Serialize, Deserialize)]
|
||||||
|
#[cfg_attr(feature = "full", derive(Queryable, Associations, Identifiable, TS))]
|
||||||
|
#[cfg_attr(feature = "full", diesel(table_name = image_upload))]
|
||||||
|
#[cfg_attr(feature = "full", ts(export))]
|
||||||
|
#[cfg_attr(
|
||||||
|
feature = "full",
|
||||||
|
diesel(belongs_to(crate::source::local_user::LocalUser))
|
||||||
|
)]
|
||||||
|
pub struct ImageUpload {
|
||||||
|
pub id: ImageUploadId,
|
||||||
|
pub local_user_id: LocalUserId,
|
||||||
|
pub pictrs_alias: String,
|
||||||
|
pub pictrs_delete_token: String,
|
||||||
|
pub published: DateTime<Utc>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, TypedBuilder)]
|
||||||
|
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
|
||||||
|
#[cfg_attr(feature = "full", diesel(table_name = image_upload))]
|
||||||
|
pub struct ImageUploadForm {
|
||||||
|
pub local_user_id: LocalUserId,
|
||||||
|
pub pictrs_alias: String,
|
||||||
|
pub pictrs_delete_token: String,
|
||||||
|
}
|
@ -0,0 +1,2 @@
|
|||||||
|
DROP TABLE image_upload;
|
||||||
|
|
@ -0,0 +1,10 @@
|
|||||||
|
CREATE TABLE image_upload (
|
||||||
|
id serial PRIMARY KEY,
|
||||||
|
local_user_id int REFERENCES local_user ON UPDATE CASCADE ON DELETE CASCADE NOT NULL,
|
||||||
|
pictrs_alias text NOT NULL UNIQUE,
|
||||||
|
pictrs_delete_token text NOT NULL,
|
||||||
|
published timestamptz DEFAULT now() NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX idx_image_upload_local_user_id ON image_upload (local_user_id);
|
||||||
|
|
Loading…
Reference in New Issue