Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
feat(/user/uploadkey): add deletion of upload keys
Browse files Browse the repository at this point in the history
  • Loading branch information
GGORG0 committed Jun 30, 2022
1 parent 0d291b3 commit 42b9d3d
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions src/routes/userRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const signale = createSignale(__filename);

const router = Router();

router.post("/createKey", authenticateJWT, async (req, res) => {
router.post("/uploadKey", authenticateJWT, async (req, res) => {
try {
const key = jwt.sign({ user: res.locals.user as string, ip: req.ip, type: "upload" }, process.env.JWT_SECRET as string, { expiresIn: "30d" });

Expand All @@ -34,7 +34,7 @@ router.post("/createKey", authenticateJWT, async (req, res) => {
}
});

router.get("/uploadKeys", authenticateJWT, async (req, res) => {
router.get("/uploadKey", authenticateJWT, async (req, res) => {
try {
const keyObjects = await prisma.uploadKey.findMany({
where: {
Expand All @@ -60,6 +60,34 @@ router.get("/uploadKeys", authenticateJWT, async (req, res) => {
}
});

router.delete("/uploadKey/:key", authenticateJWT, async (req, res) => {
try {
const keyObject = await prisma.uploadKey.findFirst({
where: {
key: req.params.key,
userId: res.locals.user as string,
},
});
if (!keyObject) throw "Key not found";

await prisma.uploadKey.delete({
where: {
key: req.params.key,
},
});

res.json({
success: true,
});
}
catch (err) {
res.json({
success: false,
error: err,
});
}
});

router.get("/info", authenticateJWT, (req, res) => {
const user = res.locals.userObj as User;
res.json({
Expand Down

0 comments on commit 42b9d3d

Please sign in to comment.