mirror of https://github.com/LemmyNet/lemmy.git
no regex
parent
25e83c466e
commit
160d558dd9
|
@ -11,7 +11,7 @@ killall -s1 lemmy_server || true
|
|||
popd
|
||||
|
||||
pnpm i
|
||||
pnpm api-test-user || true
|
||||
pnpm api-test || true
|
||||
|
||||
killall -s1 lemmy_server || true
|
||||
killall -s1 pict-rs || true
|
||||
|
|
|
@ -141,7 +141,7 @@ test("Create user with Arabic name", async () => {
|
|||
expect(alphaPerson).toBeDefined();
|
||||
});
|
||||
|
||||
test.only("Set a new avatar, old avatar is deleted", async () => {
|
||||
test("Set a new avatar, old avatar is deleted", async () => {
|
||||
const listMediaRes = await alphaImage.listMedia();
|
||||
expect(listMediaRes.images.length).toBe(0);
|
||||
const upload_form1: UploadImage = {
|
||||
|
@ -149,15 +149,13 @@ test.only("Set a new avatar, old avatar is deleted", async () => {
|
|||
};
|
||||
const upload1 = await alphaImage.uploadImage(upload_form1);
|
||||
expect(upload1.url).toBeDefined();
|
||||
console.log(upload1);
|
||||
|
||||
let form1 = {
|
||||
avatar: upload1.url
|
||||
avatar: upload1.url,
|
||||
};
|
||||
await saveUserSettings(alpha, form1);
|
||||
const listMediaRes1 = await alphaImage.listMedia();
|
||||
expect(listMediaRes1.images.length).toBe(1);
|
||||
console.log(listMediaRes1);
|
||||
|
||||
const upload_form2: UploadImage = {
|
||||
image: Buffer.from("test2"),
|
||||
|
@ -166,10 +164,10 @@ test.only("Set a new avatar, old avatar is deleted", async () => {
|
|||
expect(upload2.url).toBeDefined();
|
||||
|
||||
let form2 = {
|
||||
avatar: upload1.url
|
||||
avatar: upload1.url,
|
||||
};
|
||||
await saveUserSettings(alpha, form2);
|
||||
// make sure only the new avatar is kept
|
||||
const listMediaRes2 = await alphaImage.listMedia();
|
||||
expect(listMediaRes2.images.length).toBe(1);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -14,8 +14,6 @@ use diesel::{
|
|||
QueryDsl,
|
||||
};
|
||||
use diesel_async::RunQueryDsl;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use url::Url;
|
||||
|
||||
impl LocalImage {
|
||||
|
@ -85,10 +83,7 @@ impl LocalImage {
|
|||
|
||||
pub async fn delete_by_url(pool: &mut DbPool<'_>, url: &DbUrl) -> Result<Self, Error> {
|
||||
let conn = &mut get_conn(pool).await?;
|
||||
static IMAGE_REGEX: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"^.*/pictrs/image/([a-z0-9-]+\.[a-z]+)$").expect("compile regex"));
|
||||
let captures = IMAGE_REGEX.captures(url.as_str()).unwrap();
|
||||
let alias = &captures[1];
|
||||
let alias = url.as_str().split('/').last().ok_or(NotFound)?;
|
||||
diesel::delete(local_image::table.filter(local_image::pictrs_alias.eq(alias)))
|
||||
.get_result(conn)
|
||||
.await
|
||||
|
|
Loading…
Reference in New Issue