11 Commits
2.0.2 ... 2.0.6

Author SHA1 Message Date
Fran Jurmanović
e1cf854d27 remove static plugin 2024-04-17 20:53:36 +02:00
Fran Jurmanović
972ee67f53 remove static plugin 2024-04-17 20:49:05 +02:00
Fran Jurmanović
9ecfdef62b update dockerfile 2024-04-17 20:39:46 +02:00
Fran Jurmanović
e56f0883cf increase version 2024-03-02 14:50:29 +01:00
Fran Jurmanović
5aa69588fb add bot endpoints 2024-03-02 14:49:57 +01:00
Fran Jurmanović
28b028d056 increase version 2023-11-01 15:48:41 +01:00
Fran Jurmanović
4ac04d4457 formatting 2023-11-01 15:48:15 +01:00
Fran Jurmanović
9d137b6b52 fix legica date format 2023-11-01 15:46:04 +01:00
Fran Jurmanović
79110bdb1c version increase 2023-10-21 11:51:25 +02:00
Fran Jurmanović
0d2fba3883 fix regex not working everytime 2023-10-21 11:50:47 +02:00
Fran Jurmanović
77aa924161 increase version 2023-10-21 11:50:23 +02:00
6 changed files with 93 additions and 43 deletions

BIN
bun.lockb

Binary file not shown.

View File

@@ -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"]

View File

@@ -1,35 +1,35 @@
{ {
"name": "legica-dana", "name": "legica-dana",
"version": "2.0.2", "version": "2.0.6",
"main": "src/app.ts", "main": "src/app.ts",
"scripts": { "scripts": {
"start": "bun src/app.ts" "start": "bun run src/app.ts"
}, },
"author": "Fran Jurmanović <fjurma12@outlook.com>", "author": "Fran Jurmanović <fjurma12@outlook.com>",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@elysiajs/cron": "^0.7.0", "@elysiajs/cron": "^0.7.0",
"@elysiajs/static": "^0.7.1", "@elysiajs/static": "^0.7.1",
"@elysiajs/swagger": "^0.7.3", "@elysiajs/swagger": "^0.7.3",
"axios": "^0.26.0", "axios": "^0.26.0",
"body-parser": "^1.20.2", "body-parser": "^1.20.2",
"cheerio": "^1.0.0-rc.10", "cheerio": "^1.0.0-rc.10",
"dayjs": "^1.11.10", "dayjs": "^1.11.10",
"discord.js": "^12.5.1", "discord.js": "^12.5.1",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"elysia": "^0.7.15", "elysia": "^0.7.15",
"lodash-es": "^4.17.21", "lodash-es": "^4.17.21",
"minimatch": "^9.0.3", "minimatch": "^9.0.3",
"pino": "^8.15.4", "pino": "^8.15.4",
"typescript": "^4.1.5" "typescript": "^4.1.5"
}, },
"devDependencies": { "devDependencies": {
"@types/lodash-es": "^4.17.9", "@types/lodash-es": "^4.17.9",
"@types/node": "^20.8.2", "@types/node": "^20.8.2",
"@typescript-eslint/eslint-plugin": "^6.7.4", "@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4", "@typescript-eslint/parser": "^6.7.4",
"bun-types": "^1.0.4-canary.20231004T140131", "bun-types": "^1.0.4-canary.20231004T140131",
"eslint": "^8.50.0", "eslint": "^8.50.0",
"prettier": "^2.2.1" "prettier": "^2.2.1"
} }
} }

View File

@@ -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);

View File

@@ -6,8 +6,6 @@ import { Client, MessageEmbed, TextChannel } from "discord.js";
dayjs.extend(customParseFormat); dayjs.extend(customParseFormat);
const dateRegex = /\d{1,2}.\d{1,2}.\d{4}/g;
export async function sendDiscordMessage( export async function sendDiscordMessage(
client: Client, client: Client,
url: string, url: string,
@@ -17,6 +15,7 @@ export async function sendDiscordMessage(
const { img, title } = await getImgTitle(url); const { img, title } = await getImgTitle(url);
if (dateCheck) { if (dateCheck) {
const dateRegex = /\d{1,2}.\d{1,2}.\d{4}/g;
const date = dateRegex.exec(title)?.[0]; const date = dateRegex.exec(title)?.[0];
const dayjsDate = dayjs(date, config.LEGICA_DATE_FORMAT); const dayjsDate = dayjs(date, config.LEGICA_DATE_FORMAT);
if (!dateCheck.isSame(dayjsDate, "D")) if (!dateCheck.isSame(dayjsDate, "D"))

View File

@@ -17,7 +17,7 @@ const config: ProjectConfig = {
APP_VERSION: version, APP_VERSION: version,
LEGICA_URL: "https://sib.net.hr/legica-dana", LEGICA_URL: "https://sib.net.hr/legica-dana",
TIMEZONE: process.env.TIMEZONE || "utc", TIMEZONE: process.env.TIMEZONE || "utc",
LEGICA_DATE_FORMAT: process.env.LEGICA_DATE_FORMAT || "DD.MM.YYYY", LEGICA_DATE_FORMAT: process.env.LEGICA_DATE_FORMAT || "D.M.YYYY",
}; };
export { config }; export { config };