Skip to content

Commit 562d324

Browse files
committed
Refactor API structure: add Discord API integration, implement JWT authentication, and remove obsolete bot controller
1 parent e2f8338 commit 562d324

18 files changed

+477
-452
lines changed

package.json

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,26 +36,23 @@
3636
"devDependencies": {
3737
"@appujet/eslint-config": "^0.0.3",
3838
"@types/i18n": "^0.13.12",
39-
"@types/node": "^22.13.5",
39+
"@types/node": "^22.13.10",
4040
"@types/signale": "^1.4.7",
41-
"drizzle-kit": "latest",
42-
"eslint": "^9.21.0",
43-
"eslint-config-prettier": "^10.0.1",
44-
"prettier": "^3.5.2",
45-
"prisma": "^6.4.1",
46-
"typescript": "^5.7.3"
41+
"eslint": "^9.22.0",
42+
"eslint-config-prettier": "^10.1.1",
43+
"prettier": "^3.5.3",
44+
"prisma": "^6.5.0",
45+
"typescript": "^5.8.2"
4746
},
4847
"dependencies": {
4948
"@fastify/cors": "^10.1.0",
5049
"@fastify/helmet": "^13.0.1",
50+
"@fastify/jwt": "^9.0.4",
5151
"@fastify/sensible": "^6.0.3",
52-
"@libsql/client": "^0.14.0",
53-
"@prisma/adapter-libsql": "^6.4.1",
54-
"@prisma/client": "^6.4.1",
52+
"@prisma/client": "^6.5.0",
5553
"@top-gg/sdk": "^3.1.6",
5654
"discord.js": "^14.18.0",
5755
"dotenv": "^16.4.7",
58-
"drizzle-orm": "^0.40.0",
5956
"fastify": "^5.2.1",
6057
"fastify-plugin": "^5.0.1",
6158
"genius-lyrics-api": "^3.2.1",
@@ -68,7 +65,7 @@
6865
"topgg-autoposter": "^2.0.2",
6966
"tslib": "^2.8.1",
7067
"tsyringe": "^4.8.0",
71-
"undici": "^7.3.0",
68+
"undici": "^7.5.0",
7269
"zod": "^3.24.2"
7370
},
7471
"signale": {
@@ -80,4 +77,4 @@
8077
"displayTimestamp": true,
8178
"underlineLabel": true
8279
}
83-
}
80+
}

prisma/turso.schema.prisma

Lines changed: 0 additions & 83 deletions
This file was deleted.

src/api/Api.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import Fastify, {
2-
FastifyReply,
3-
FastifyRequest,
42
type FastifyInstance,
53
} from "fastify";
64
import helmet from "@fastify/helmet";
@@ -11,25 +9,23 @@ import { botRoutes } from "./routes/bot.routes";
119
import Logger from "../structures/Logger";
1210
import { guildRoutes } from "./routes/guild.routes";
1311
import { userRoutes } from "./routes/user.routes";
12+
import { authRoutes } from "./routes/auth.routes";
13+
import jwtPlugin from "./plugins/jwt";
14+
import { container } from "tsyringe";
1415

1516
export class Api {
1617
public fastify: FastifyInstance;
1718
public Logger = new Logger();
1819

1920
constructor() {
2021
this.fastify = Fastify({ trustProxy: true });
21-
this.fastify.addHook("preHandler", this.verifyJWT.bind(this));
22-
}
23-
private async verifyJWT(request: FastifyRequest, reply: FastifyReply) {
24-
const authHeader = request.headers["authorization"];
25-
if (!authHeader || !authHeader.startsWith("Bearer")) {
26-
reply
27-
.status(401)
28-
.send({ error: "Unauthorized: Missing or invalid token" });
29-
return;
30-
}
22+
container.register<FastifyInstance>("FastifyInstance", {
23+
useValue: this.fastify,
24+
});
25+
3126
}
3227
async start() {
28+
await this.fastify.register(jwtPlugin);
3329
await this.fastify.register(helmet);
3430
await this.fastify.register(cors, {
3531
origin: ["http://localhost:3000", env.NEXT_PUBLIC_BASE_URL!],
@@ -38,13 +34,17 @@ export class Api {
3834
});
3935
await this.fastify.register(sensible);
4036

37+
/* auth routes */
38+
await this.fastify.register(authRoutes, { prefix: "/api" });
39+
4140
/* bot routes */
4241
await this.fastify.register(botRoutes, {
4342
prefix: "/bot",
4443
});
4544
/* guild routes */
4645
await this.fastify.register(guildRoutes, {
4746
prefix: "/guild",
47+
preValidation: [this.fastify.authenticate],
4848
});
4949
/* user routes */
5050
await this.fastify.register(userRoutes, {

src/api/controllers/bot.controller.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/api/controllers/guild.controller.ts

Lines changed: 0 additions & 103 deletions
This file was deleted.

0 commit comments

Comments
 (0)