Compare commits
9 Commits
2.0.4
...
3c6bdeab60
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c6bdeab60 | ||
|
|
11a26bff83 | ||
|
|
e1cf854d27 | ||
|
|
972ee67f53 | ||
|
|
9ecfdef62b | ||
|
|
e56f0883cf | ||
|
|
5aa69588fb | ||
|
|
28b028d056 | ||
|
|
4ac04d4457 |
11
dockerfile
11
dockerfile
@@ -1,17 +1,20 @@
|
|||||||
# Use oven/bun as parent image
|
# Use oven/bun as parent image
|
||||||
FROM oven/bun:latest
|
FROM oven/bun:1.0.27
|
||||||
|
|
||||||
# Change the working directory on the Docker image to /app
|
# Change the working directory on the Docker image to /app
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy package.json and package-lock.json to the /app directory
|
# Copy package.json and package-lock.json to the /app directory
|
||||||
COPY . .
|
COPY package.json ./
|
||||||
|
COPY bun.lockb ./
|
||||||
|
COPY src ./src
|
||||||
|
COPY tsconfig.json ./
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
RUN bun install
|
RUN bun install --frozen-lockfile
|
||||||
|
|
||||||
# Expose application port
|
# Expose application port
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
# Start the application
|
# Start the application
|
||||||
CMD bun start
|
CMD ["bun", "start"]
|
||||||
69
package.json
69
package.json
@@ -1,35 +1,38 @@
|
|||||||
{
|
{
|
||||||
"name": "legica-dana",
|
"name": "legica-dana",
|
||||||
"version": "2.0.4",
|
"version": "2.0.7",
|
||||||
"main": "src/app.ts",
|
"main": "src/app.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "bun src/app.ts"
|
"start": "bun run src/app.ts",
|
||||||
},
|
"build-script": "bun build src/app.ts --outdir dist --target bun",
|
||||||
"author": "Fran Jurmanović <fjurma12@outlook.com>",
|
"start-build": "bun run dist/app.js"
|
||||||
"license": "MIT",
|
},
|
||||||
"dependencies": {
|
"author": "Fran Jurmanović <fjurma12@outlook.com>",
|
||||||
"@elysiajs/cron": "^0.7.0",
|
"license": "MIT",
|
||||||
"@elysiajs/static": "^0.7.1",
|
"dependencies": {
|
||||||
"@elysiajs/swagger": "^0.7.3",
|
"@elysiajs/cron": "^0.7.0",
|
||||||
"axios": "^0.26.0",
|
"@elysiajs/static": "^0.7.1",
|
||||||
"body-parser": "^1.20.2",
|
"@elysiajs/swagger": "^0.7.3",
|
||||||
"cheerio": "^1.0.0-rc.10",
|
"axios": "^0.26.0",
|
||||||
"dayjs": "^1.11.10",
|
"body-parser": "^1.20.2",
|
||||||
"discord.js": "^12.5.1",
|
"cheerio": "^1.0.0-rc.10",
|
||||||
"dotenv": "^8.2.0",
|
"dayjs": "^1.11.10",
|
||||||
"elysia": "^0.7.15",
|
"discord.js": "^12.5.1",
|
||||||
"lodash-es": "^4.17.21",
|
"dotenv": "^8.2.0",
|
||||||
"minimatch": "^9.0.3",
|
"elysia": "^0.7.15",
|
||||||
"pino": "^8.15.4",
|
"ffmpeg-static": "^5.2.0",
|
||||||
"typescript": "^4.1.5"
|
"lodash-es": "^4.17.21",
|
||||||
},
|
"minimatch": "^9.0.3",
|
||||||
"devDependencies": {
|
"pino": "^8.15.4",
|
||||||
"@types/lodash-es": "^4.17.9",
|
"typescript": "^4.1.5"
|
||||||
"@types/node": "^20.8.2",
|
},
|
||||||
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
"devDependencies": {
|
||||||
"@typescript-eslint/parser": "^6.7.4",
|
"@types/lodash-es": "^4.17.9",
|
||||||
"bun-types": "^1.0.4-canary.20231004T140131",
|
"@types/node": "^20.8.2",
|
||||||
"eslint": "^8.50.0",
|
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
||||||
"prettier": "^2.2.1"
|
"@typescript-eslint/parser": "^6.7.4",
|
||||||
}
|
"bun-types": "^1.0.4-canary.20231004T140131",
|
||||||
|
"eslint": "^8.50.0",
|
||||||
|
"prettier": "^2.2.1"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
54
src/app.ts
54
src/app.ts
@@ -5,7 +5,6 @@ import { Elysia, t } from "elysia";
|
|||||||
import { swagger } from "@elysiajs/swagger";
|
import { swagger } from "@elysiajs/swagger";
|
||||||
import { basicAuth, BasicAuthError } from "@core";
|
import { basicAuth, BasicAuthError } from "@core";
|
||||||
import pino from "pino";
|
import pino from "pino";
|
||||||
import staticPlugin from "@elysiajs/static";
|
|
||||||
import cron from "@elysiajs/cron";
|
import cron from "@elysiajs/cron";
|
||||||
|
|
||||||
const client: Client = new Client();
|
const client: Client = new Client();
|
||||||
@@ -29,6 +28,55 @@ async function jobRunner() {
|
|||||||
logger.error(err);
|
logger.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const botPlugin = new Elysia({ prefix: "/bot" })
|
||||||
|
.use(
|
||||||
|
basicAuth({
|
||||||
|
users: [
|
||||||
|
{
|
||||||
|
username: "admin",
|
||||||
|
password: config.PASSWORD,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
errorMessage: "Unauthorized",
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.get(
|
||||||
|
"/",
|
||||||
|
() => ({
|
||||||
|
uptime: client.uptime,
|
||||||
|
readyAt: client.readyAt,
|
||||||
|
readyTimestamp: client.readyTimestamp,
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
detail: {
|
||||||
|
summary: "Get BOT status",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.post(
|
||||||
|
"/",
|
||||||
|
() => {
|
||||||
|
client.login(config.TOKEN);
|
||||||
|
return "Bot logged in started";
|
||||||
|
},
|
||||||
|
{
|
||||||
|
detail: {
|
||||||
|
summary: "Start BOT if it is not running",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.delete(
|
||||||
|
"/",
|
||||||
|
() => {
|
||||||
|
client.destroy();
|
||||||
|
return "Bot logged out";
|
||||||
|
},
|
||||||
|
{
|
||||||
|
detail: {
|
||||||
|
summary: "Stops the BOT.",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const taskPlugin = new Elysia({ prefix: "/job" })
|
const taskPlugin = new Elysia({ prefix: "/job" })
|
||||||
.use(
|
.use(
|
||||||
@@ -138,7 +186,7 @@ const taskPlugin = new Elysia({ prefix: "/job" })
|
|||||||
"/send",
|
"/send",
|
||||||
async ({ set, body }) => {
|
async ({ set, body }) => {
|
||||||
try {
|
try {
|
||||||
const url = body.url;
|
const url = body?.url;
|
||||||
if (url) {
|
if (url) {
|
||||||
await sendDiscordMessage(client, url);
|
await sendDiscordMessage(client, url);
|
||||||
} else {
|
} else {
|
||||||
@@ -210,8 +258,8 @@ const app = new Elysia()
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.use(staticPlugin())
|
|
||||||
.use(taskPlugin)
|
.use(taskPlugin)
|
||||||
|
.use(botPlugin)
|
||||||
.listen(config.PORT);
|
.listen(config.PORT);
|
||||||
|
|
||||||
client.login(config.TOKEN);
|
client.login(config.TOKEN);
|
||||||
|
|||||||
Reference in New Issue
Block a user