From 09c244811665f18add311928cd894fd4a83b1aab Mon Sep 17 00:00:00 2001 From: trafficlunar Date: Sat, 10 May 2025 14:35:40 +0100 Subject: [PATCH] refactor: make profile picture cooldown 7 days instead of 30 --- src/app/api/auth/picture/route.ts | 8 ++++---- src/components/profile-settings/profile-picture.tsx | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/app/api/auth/picture/route.ts b/src/app/api/auth/picture/route.ts index d531514..c5f5de3 100644 --- a/src/app/api/auth/picture/route.ts +++ b/src/app/api/auth/picture/route.ts @@ -25,13 +25,13 @@ export async function PATCH(request: NextRequest) { const check = await rateLimit.handle(); if (check) return check; - // Check if profile picture was updated in the last 30 days + // Check if profile picture was updated in the last 7 days const user = await prisma.user.findUnique({ where: { id: Number(session.user.id) } }); if (user && user.imageUpdatedAt) { - const timePeriod = dayjs().subtract(30, "days"); + const timePeriod = dayjs().subtract(7, "days"); const lastUpdate = dayjs(user.imageUpdatedAt); - if (lastUpdate.isAfter(timePeriod)) return rateLimit.sendResponse({ error: "Profile picture was changed in the last 30 days" }, 400); + if (lastUpdate.isAfter(timePeriod)) return rateLimit.sendResponse({ error: "Profile picture was changed in the last 7 days" }, 400); } // Parse data @@ -62,7 +62,7 @@ export async function PATCH(request: NextRequest) { try { const buffer = Buffer.from(await image.arrayBuffer()); - const webpBuffer = await sharp(buffer).resize({ width: 128, height: 128 }).webp({ quality: 85 }).toBuffer(); + const webpBuffer = await sharp(buffer, { animated: true }).resize({ width: 128, height: 128 }).webp({ quality: 85 }).toBuffer(); const fileLocation = path.join(uploadsDirectory, `${session.user.id}.webp`); await fs.writeFile(fileLocation, webpBuffer); diff --git a/src/components/profile-settings/profile-picture.tsx b/src/components/profile-settings/profile-picture.tsx index cfaebc2..3bca613 100644 --- a/src/components/profile-settings/profile-picture.tsx +++ b/src/components/profile-settings/profile-picture.tsx @@ -15,7 +15,7 @@ export default function ProfilePictureSettings() { const [error, setError] = useState(undefined); const [newPicture, setNewPicture] = useState(); - const changeDate = dayjs().add(30, "days"); + const changeDate = dayjs().add(7, "days"); const handleSubmit = async (close: () => void) => { const formData = new FormData(); @@ -53,7 +53,7 @@ export default function ProfilePictureSettings() {
-

Manage your profile picture. Can only be changed once every 30 days.

+

Manage your profile picture. Can only be changed once every 7 days.

@@ -98,7 +98,7 @@ export default function ProfilePictureSettings() { )}