refactor: make profile picture cooldown 7 days instead of 30
This commit is contained in:
parent
4987c2e59a
commit
09c2448116
2 changed files with 7 additions and 7 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export default function ProfilePictureSettings() {
|
|||
const [error, setError] = useState<string | undefined>(undefined);
|
||||
const [newPicture, setNewPicture] = useState<FileWithPath | undefined>();
|
||||
|
||||
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() {
|
|||
<div className="grid grid-cols-2">
|
||||
<div>
|
||||
<label className="font-semibold">Profile Picture</label>
|
||||
<p className="text-sm text-zinc-500">Manage your profile picture. Can only be changed once every 30 days.</p>
|
||||
<p className="text-sm text-zinc-500">Manage your profile picture. Can only be changed once every 7 days.</p>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col">
|
||||
|
|
@ -98,7 +98,7 @@ export default function ProfilePictureSettings() {
|
|||
)}
|
||||
<SubmitDialogButton
|
||||
title="Confirm Profile Picture Change"
|
||||
description="Are you sure? Your profile picture can only be changed every 30 days."
|
||||
description="Are you sure? Your profile picture can only be changed every 7 days."
|
||||
error={error}
|
||||
onSubmit={handleSubmit}
|
||||
>
|
||||
|
|
|
|||
Loading…
Reference in a new issue