Skip to content

Commit

Permalink
Merge pull request #31 from xyzuan/dev
Browse files Browse the repository at this point in the history
hotfix
  • Loading branch information
xyzuan authored Dec 11, 2024
2 parents 2a2b247 + 5024280 commit 8a01e77
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
Binary file modified bun.lockb
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@prisma/client": "5.19.1",
"arctic": "^2.0.0",
"cloudinary": "^2.5.1",
"elysia-ip": "^1.0.7",
"elysia-rate-limit": "^4.1.0",
"file-type": "^19.6.0",
"logestic": "^1.2.4",
Expand Down
10 changes: 9 additions & 1 deletion src/api/controller/blog/commentBlog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ import { BadRequestException } from "@constants/exceptions";
import { rateLimit } from "elysia-rate-limit";
import { createElysia } from "@libs/elysia";
import blogModel from "@models/blog.model";
import { redis } from "@libs/redisClient";

export default createElysia()
.use(blogModel)
.use(authGuard)
.use(rateLimit())
.use(
rateLimit({
max: 3,
duration: 60000,
})
)
.post(
"/comment/:id",
async ({ body, params: { id }, user }) => {
Expand All @@ -21,6 +27,8 @@ export default createElysia()
throw new BadRequestException("Blog not found.");
}

await redis.del(`blog.${blog.slug}`);

return {
status: 200,
data: await prismaClient.blogComment.create({
Expand Down
3 changes: 3 additions & 0 deletions src/api/controller/blog/reactionBlog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { prismaClient } from "@libs/prismaDatabase";
import { BadRequestException } from "@constants/exceptions";
import { createElysia } from "@libs/elysia";
import blogModel from "@models/blog.model";
import { redis } from "@libs/redisClient";

export default createElysia()
.use(blogModel)
Expand All @@ -20,6 +21,8 @@ export default createElysia()
throw new BadRequestException("Blog not found.");
}

await redis.del(`blog.${blog.slug}`);

const existingReaction = await prismaClient.blogReaction.findFirst({
where: {
blogId: blog.id,
Expand Down
8 changes: 8 additions & 0 deletions src/api/controller/message/wsMessage.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { rateLimit } from "elysia-rate-limit";

import { UnauthorizedException } from "@constants/exceptions";
import { authGuard } from "@libs/authGuard";
import { createElysia } from "@libs/elysia";
Expand All @@ -6,6 +8,12 @@ import messageModel from "@models/message.model";

export default createElysia()
.use(messageModel)
.use(
rateLimit({
max: 10,
duration: 60000,
})
)
.use(authGuard)
.ws("/", {
body: "message.model",
Expand Down

0 comments on commit 8a01e77

Please sign in to comment.