-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
102 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Elysia } from "elysia"; | ||
import { dmUser } from "../../index.ts"; | ||
import { PrismaClient } from "@prisma/client"; | ||
|
||
const prisma = new PrismaClient(); | ||
|
||
export const AcclinkEndpoint = new Elysia({ prefix: "/admin/link" }).post( | ||
"/", | ||
async ({ query, body }) => { | ||
const key = query.key; | ||
const json = body as { uid: string; acc: string }; | ||
|
||
const uid = json.uid; | ||
const acc = json.acc; | ||
|
||
if (!key) return new Response("No key provided", { status: 400 }); | ||
if (!uid || !acc) | ||
return new Response("Missing uid or account information", { | ||
status: 400, | ||
}); | ||
|
||
if (key !== process.env.API_SIGNING_KEY) | ||
return new Response("Invalid key", { status: 401 }); | ||
|
||
const user = await prisma.user.findUnique({ | ||
where: { | ||
id: uid, | ||
}, | ||
}); | ||
|
||
if (!user) return new Response("User not found", { status: 404 }); | ||
|
||
await prisma.user.update({ | ||
where: { | ||
id: uid, | ||
}, | ||
data: { | ||
mdUID: acc, | ||
}, | ||
}); | ||
|
||
await dmUser( | ||
uid, | ||
"MikanDev Accounts", | ||
`Your account has been linked!\n\n**MikanDev UID:** ${acc}\n**Discord ID:**${uid}`, | ||
); | ||
|
||
return new Response("Account linked", { status: 200 }); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Elysia } from "elysia"; | ||
import { dmUser } from "../../index.ts"; | ||
|
||
export const dmEndpoint = new Elysia({ prefix: "/admin/dm" }).post( | ||
"/", | ||
async ({ query, body }) => { | ||
const key = query.key; | ||
const json = body as { provider: string; uid: string; message: string }; | ||
|
||
if (!json) | ||
return new Response("No JSON body provided", { status: 400 }); | ||
|
||
const provider = json.provider; | ||
const uid = json.uid; | ||
const message = json.message; | ||
|
||
if (!key) return new Response("No key provided", { status: 400 }); | ||
if (key !== process.env.API_SIGNING_KEY) | ||
return new Response("Invalid key", { status: 401 }); | ||
if (!provider || !uid || !message) | ||
return new Response("Missing provider, uid, or message", { | ||
status: 400, | ||
}); | ||
|
||
const response = await dmUser(uid, provider, message); | ||
if (response instanceof Error) | ||
return { status: 500, message: response.message }; | ||
return new Response("Message sent", { status: 200 }); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters