mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-27 06:41:18 +00:00
Cleaning up validate.
This commit is contained in:
parent
a8972b09b8
commit
ed1b728fdb
2 changed files with 9 additions and 10 deletions
|
@ -12,12 +12,11 @@ use crate::{
|
||||||
utils::{get_conn, DbPool},
|
utils::{get_conn, DbPool},
|
||||||
};
|
};
|
||||||
use diesel::{
|
use diesel::{
|
||||||
dsl::exists,
|
|
||||||
insert_into,
|
insert_into,
|
||||||
result::Error,
|
result::Error,
|
||||||
select,
|
|
||||||
ExpressionMethods,
|
ExpressionMethods,
|
||||||
NotFound,
|
NotFound,
|
||||||
|
OptionalExtension,
|
||||||
QueryDsl,
|
QueryDsl,
|
||||||
};
|
};
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
|
@ -60,13 +59,12 @@ impl RemoteImage {
|
||||||
|
|
||||||
pub async fn validate(pool: &mut DbPool<'_>, link_: DbUrl) -> Result<(), Error> {
|
pub async fn validate(pool: &mut DbPool<'_>, link_: DbUrl) -> Result<(), Error> {
|
||||||
let conn = &mut get_conn(pool).await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
|
let res = remote_image::table
|
||||||
let exists = select(exists(
|
.find(link_)
|
||||||
remote_image::table.filter(remote_image::link.eq(link_)),
|
.first::<RemoteImage>(conn)
|
||||||
))
|
.await
|
||||||
.get_result::<bool>(conn)
|
.optional()?;
|
||||||
.await?;
|
if res.is_some() {
|
||||||
if exists {
|
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(NotFound)
|
Err(NotFound)
|
||||||
|
@ -79,6 +77,7 @@ impl ImageDetails {
|
||||||
let conn = &mut get_conn(pool).await?;
|
let conn = &mut get_conn(pool).await?;
|
||||||
insert_into(image_details::table)
|
insert_into(image_details::table)
|
||||||
.values(form)
|
.values(form)
|
||||||
|
.on_conflict_do_nothing()
|
||||||
.get_result::<Self>(conn)
|
.get_result::<Self>(conn)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ services:
|
||||||
|
|
||||||
pictrs:
|
pictrs:
|
||||||
restart: always
|
restart: always
|
||||||
image: asonix/pictrs:0.5.0-rc.2
|
image: asonix/pictrs:0.5.13
|
||||||
user: 991:991
|
user: 991:991
|
||||||
volumes:
|
volumes:
|
||||||
- ./volumes/pictrs_alpha:/mnt:Z
|
- ./volumes/pictrs_alpha:/mnt:Z
|
||||||
|
|
Loading…
Reference in a new issue