mirror of
https://github.com/YuzuZensai/Kiroku.git
synced 2026-01-06 04:33:18 +00:00
✨ feat: Switched to ElysiaJS
This commit is contained in:
@@ -4,10 +4,11 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"tsc": "tsc",
|
"tsc": "tsc",
|
||||||
"start": "bun run ./src/index.ts",
|
"start": "bun --watch run ./src/index.ts",
|
||||||
"dev": "tsc && bun start"
|
"dev": "tsc && bun start"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@types/bun": "^1.1.10",
|
||||||
"@types/steamapi": "^2.2.2",
|
"@types/steamapi": "^2.2.2",
|
||||||
"bun-types": "latest",
|
"bun-types": "latest",
|
||||||
"typescript": "^5.2.2"
|
"typescript": "^5.2.2"
|
||||||
@@ -18,6 +19,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"discord.js": "^14.13.0",
|
"discord.js": "^14.13.0",
|
||||||
"dotenv": "^16.3.1",
|
"dotenv": "^16.3.1",
|
||||||
|
"elysia": "^1.1.17",
|
||||||
"steamapi": "^2.4.2"
|
"steamapi": "^2.4.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
41
src/index.ts
41
src/index.ts
@@ -4,6 +4,7 @@ dotenv.config();
|
|||||||
import ConfigProvider from './providers/ConfigProvider';
|
import ConfigProvider from './providers/ConfigProvider';
|
||||||
import DiscordProvider from './providers/DiscordProvider';
|
import DiscordProvider from './providers/DiscordProvider';
|
||||||
import SteamProvider from './providers/SteamProvider';
|
import SteamProvider from './providers/SteamProvider';
|
||||||
|
import { Elysia, t } from 'elysia';
|
||||||
|
|
||||||
// 1 minute
|
// 1 minute
|
||||||
const REFRESH_TIME = 60 * 1000;
|
const REFRESH_TIME = 60 * 1000;
|
||||||
@@ -24,15 +25,9 @@ interface ReturnData {
|
|||||||
|
|
||||||
let latestReturnData: ReturnData = {};
|
let latestReturnData: ReturnData = {};
|
||||||
|
|
||||||
function sendJsonResponse(data: any) {
|
|
||||||
let res = new Response(JSON.stringify(data));
|
|
||||||
res.headers.set('Access-Control-Allow-Origin', '*');
|
|
||||||
res.headers.set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
if (!ConfigProvider.isReady()) return;
|
if (!ConfigProvider.isReady()) return;
|
||||||
|
const port = process.env.PORT || 3000;
|
||||||
|
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
let newData: ReturnData = {};
|
let newData: ReturnData = {};
|
||||||
@@ -79,34 +74,36 @@ async function main() {
|
|||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
const server = Bun.serve({
|
const server = new Elysia()
|
||||||
port: 3000,
|
.get('/', async ({ query, error }) => {
|
||||||
async fetch(request: Request) {
|
query: t.Object({
|
||||||
let url = new URL(request.url);
|
user: t.Optional(t.String())
|
||||||
let user = url.searchParams.get('user');
|
});
|
||||||
|
|
||||||
if (!user || user === null) {
|
let user = query.user;
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
if (!ConfigProvider.getConfig().global.lookup_all)
|
if (!ConfigProvider.getConfig().global.lookup_all)
|
||||||
return sendJsonResponse({ success: false, message: 'Lookup all is disabled' });
|
return error('Forbidden', { success: false, message: 'Lookup all is disabled' });
|
||||||
|
|
||||||
return sendJsonResponse({
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
data: latestReturnData
|
data: latestReturnData
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
user = user.toLowerCase();
|
user = user.toLowerCase();
|
||||||
|
|
||||||
if (!latestReturnData[user]) return sendJsonResponse({ success: false, message: 'Unable to find user' });
|
if (!latestReturnData[user]) return error('Not Found', { success: false, message: 'Unable to find user' });
|
||||||
const userData = latestReturnData[user];
|
const userData = latestReturnData[user];
|
||||||
|
|
||||||
return sendJsonResponse({
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
data: userData
|
data: userData
|
||||||
});
|
};
|
||||||
}
|
})
|
||||||
});
|
.listen(port);
|
||||||
|
|
||||||
console.log(`Listening on localhost:${server.port}`);
|
console.log(`Listening on port ${port}`);
|
||||||
}
|
}
|
||||||
main();
|
main();
|
||||||
|
|||||||
Reference in New Issue
Block a user