-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add API and database * Store room data in database * Get stuff working * Remove hardcoded stuff * Move api to bot process Co-authored-by: Porasjeet Singh <[email protected]>
- Loading branch information
Showing
20 changed files
with
799 additions
and
62 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 61,7 @@ | |
"always" | ||
], | ||
"comma-dangle": [ | ||
"error", | ||
"always-multiline" | ||
], | ||
"no-return-await": "warn", | ||
|
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 |
---|---|---|
|
@@ -135,3 135,4 @@ config.json | |
.vscode/ | ||
.env | ||
dist/ | ||
database.db |
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
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,14 @@ | ||
generator client { | ||
provider = "prisma-client-js" | ||
} | ||
|
||
datasource db { | ||
provider = "sqlite" | ||
url = env("DATABASE_URL") | ||
} | ||
|
||
model Room { | ||
id Int @id @default(autoincrement()) | ||
room_id String @unique | ||
hb_session_id String @unique | ||
} |
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,34 @@ | ||
import { PrismaClient } from "@prisma/client"; | ||
import express from "express"; | ||
|
||
export default function apiServer(db: PrismaClient) { | ||
const app = express(); | ||
|
||
app.use(function (_req, res, next) { | ||
res.header("Access-Control-Allow-Origin", process.env.VITE_CLIENT_BASE_URL); | ||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); | ||
next(); | ||
}); | ||
|
||
app.get("/api/rooms/:id", async (req, res) => { | ||
const hyperbeam_session_id = await db.room.findFirst({ where: { room_id: req.params.id } }).then(room => room?.hb_session_id); | ||
if (!hyperbeam_session_id) | ||
return res.status(404).send("Room not found"); | ||
const hbResponse = await fetch( | ||
`https://enginetest.hyperbeam.com/v0/vm/${hyperbeam_session_id}`, | ||
{ | ||
headers: { | ||
Authorization: `Bearer ${process.env.HYPERBEAM_API_KEY}`, | ||
}, | ||
}, | ||
); | ||
if (!hbResponse.ok) { | ||
return res.status(500).send("Internal Server Error"); | ||
} | ||
res.setHeader("Content-Type", "application/json"); | ||
const { embed_url } = await hbResponse.json(); | ||
res.send({ embed_url }); | ||
}); | ||
|
||
return app; | ||
} |
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,6 @@ | ||
import { PrismaClient } from "@prisma/client"; | ||
import { Client } from "discord.js"; | ||
|
||
export interface BotClient extends Client { | ||
db: PrismaClient; | ||
} |
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
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,43 @@ | ||
import Hyperbeam from "@hyperbeam/iframe"; | ||
import React from "react"; | ||
import { ReactNode } from "react"; | ||
import { useParams } from "react-router-dom"; | ||
|
||
interface IProps { | ||
params: { id: string | null | undefined; }; | ||
} | ||
|
||
interface IState { | ||
} | ||
|
||
class VMElement extends React.Component<IProps, IState> { | ||
constructor(props) { | ||
super(props); | ||
this.state = {}; | ||
} | ||
|
||
async componentDidMount() { | ||
const { id } = this.props.params; | ||
const apiResponse = await fetch(`http://localhost:3000/api/rooms/${id}`).then(response => { | ||
console.log(response); | ||
return response.json(); | ||
}); | ||
const hbiframe = document.getElementById("hyperbeam") as HTMLIFrameElement | null; | ||
if (hbiframe) { | ||
await Hyperbeam(hbiframe, apiResponse.embed_url); | ||
} | ||
} | ||
|
||
render(): ReactNode { | ||
return <div className="OAuth"> | ||
<h2>VM</h2> | ||
<iframe id="hyperbeam" title="Hyperbeam" /> | ||
</div>; | ||
} | ||
} | ||
|
||
const VM = (props) => { | ||
return <VMElement {...props} params={useParams()} />; | ||
}; | ||
|
||
export default VM; |
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
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
Oops, something went wrong.