From 160d558dd9e4f09ecd4b1def15b19a2a4cae386c Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Tue, 26 Mar 2024 14:58:48 +0100 Subject: [PATCH] no regex --- api_tests/run-federation-test.sh | 2 +- api_tests/src/user.spec.ts | 10 ++++------ crates/db_schema/src/impls/images.rs | 7 +------ 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/api_tests/run-federation-test.sh b/api_tests/run-federation-test.sh index d571236be..969a95b3e 100755 --- a/api_tests/run-federation-test.sh +++ b/api_tests/run-federation-test.sh @@ -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 diff --git a/api_tests/src/user.spec.ts b/api_tests/src/user.spec.ts index 9f7e35700..f129d267e 100644 --- a/api_tests/src/user.spec.ts +++ b/api_tests/src/user.spec.ts @@ -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); -}); \ No newline at end of file +}); diff --git a/crates/db_schema/src/impls/images.rs b/crates/db_schema/src/impls/images.rs index 498aa8450..221aa1a68 100644 --- a/crates/db_schema/src/impls/images.rs +++ b/crates/db_schema/src/impls/images.rs @@ -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 { let conn = &mut get_conn(pool).await?; - static IMAGE_REGEX: Lazy = - 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