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