From f4838349d4242addba703dac9ea7181dc9a8d842 Mon Sep 17 00:00:00 2001 From: Redume Date: Sun, 2 Mar 2025 21:46:41 +0300 Subject: [PATCH 01/20] chore(config): replace example configs --- config.example.hjson | 56 ++++++++++++++++++++++++++++++++++++++++++++ config.example.yaml | 42 --------------------------------- 2 files changed, 56 insertions(+), 42 deletions(-) create mode 100644 config.example.hjson delete mode 100644 config.example.yaml diff --git a/config.example.hjson b/config.example.hjson new file mode 100644 index 0000000..37cfbed --- /dev/null +++ b/config.example.hjson @@ -0,0 +1,56 @@ +{ + database: + { + user: DATABASE_USERNAME + password: DATABASE_PASSWORD + host: localhost + name: kekkai + port: 5432 + } + server: + { + host: 0.0.0.0 + ssl: + { + private_key: /CertSSL/privkey.pem + cert: /CertSSL/fullchain.pem + enabled: false + } + log: + { + level: info + } + } + analytics: + { + plausible_domain: plausible.io + plausible_token: TOKEN + enabled: false + } + currency: + { + collecting: + { + fiat: true + crypto: false + schedule: 30 * * * + crypto_apikey: TOKEN + } + fiat: + [ + USD + RUB + EUR + UAH + TRY + KZT + ] + crypto: + [ + ETH + TON + USDT + BTC + ] + } + } \ No newline at end of file diff --git a/config.example.yaml b/config.example.yaml deleted file mode 100644 index fef7b9b..0000000 --- a/config.example.yaml +++ /dev/null @@ -1,42 +0,0 @@ -# For more information, see the documentation -# https://kekkai-docs.redume.su/ - -database: # Postgresql database data, for connection - user: 'DATABASE_USERNAME' - password: 'DATABASE_PASSWORD' - host: 'DATABASE_HOST' - name: 'DATABASE_NAME' - port: 5432 -server: - host: '0.0.0.0' - ssl: - private_key: '/CertSSL/privkey.pem' # The path to the private SSL key file (String) - cert: '/CertSSL/fullchain.pem' # The path to the SSL certificate (String) - work: false # Enable or disable SSL support [Boolean] - log: - print: true # Enable or disable logging [Boolean] - level: 'info' # Log level (Fatal/Error/Warn/Log/Debug) [String] -analytics: - plausible_api: 'https://plausible.io/api/event/' - plausible_domain: 'PLAUSIBLE_DOMAIN' - plausible_token: 'PLAUSIBLE_TOKEN' - work: false -currency: - chart: - save: false # Enable or disable saving graphs to an image (Boolean) - collecting: - fiat: true # Turn off or turn on the collection of the fiat currency rate [Boolean] - crypto: false - schedule: '30 8 * * *' # Currency collection schedule in crontab format [String] - crypto_apikey: 'APIKEY' - fiat: # List of fiat currency to save the exchange rate [Array] - - USD - - RUB - - EUR - - UAH - - TRY - - KZT - crypto: - - ETH - - TON - - USDT From 2a4c02f6010fbb7d3c905f5361ceb9732fe9c1bc Mon Sep 17 00:00:00 2001 From: Redume Date: Sun, 2 Mar 2025 21:50:46 +0300 Subject: [PATCH 02/20] chore(config): Changed gitignore and split --- .gitignore | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d3002b3..e4855fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,20 @@ +# IDE & text redactors files .idea .vscode +# Project CertSSL/ charts/ + +# Depends node_modules/ + +# Docker compose postgres-data/ -config.yaml +# Config +config.hjson .env +# Other .DS_Store \ No newline at end of file From 3cbfe5dc70153ed053ba0c6d0e42f7d0585cad99 Mon Sep 17 00:00:00 2001 From: Redume Date: Sun, 2 Mar 2025 22:01:54 +0300 Subject: [PATCH 03/20] fix: Fix line endings from CRLF to LF to comply with Prettier and ESLint rules --- .eslintrc.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.eslintrc.js b/.eslintrc.js index 09ff85b..46ff384 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -17,7 +17,8 @@ module.exports = { 'error', { singleQuote: true, parser: "flow", - tabWidth: 4 + tabWidth: 4, + endOfLine: 'lf' }, ], }, From 7240fc4472b28f35a5f08cc8a8d80929e5ecd7b5 Mon Sep 17 00:00:00 2001 From: Redume Date: Sun, 2 Mar 2025 22:33:02 +0300 Subject: [PATCH 04/20] chore: eslint fix --- server/main.js | 80 +++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/server/main.js b/server/main.js index edc2d8a..6a21296 100644 --- a/server/main.js +++ b/server/main.js @@ -1,26 +1,32 @@ -const logger = require("../shared/logger/src/main.js"); -const config = require("../shared/config/src/main.js")(); +const logger = require('../shared/logger/src/main.js'); +const config = require('../shared/config/src/main.js')(); -const fs = require("fs"); -const axios = require("axios"); -const UAParser = require("ua-parser-js"); +const fs = require('fs'); +const axios = require('axios'); +const UAParser = require('ua-parser-js'); -require("../shared/database/src/create_table.js")(); +require('../shared/database/src/create_table.js')(); -const fastify = require("fastify")({ - logger: config["server"]["log"]["print"] ? logger : false, - ...(config["server"]["ssl"]["work"] +const fastify = require('fastify')({ + logger: config['server']['log']['print'] ? logger : false, + ...(config['server']['ssl']['work'] ? { - https: { - key: fs.readFileSync(config["server"]["ssl"]["private_key"], "utf8"), - cert: fs.readFileSync(config["server"]["ssl"]["cert"], "utf8"), - }, - } + https: { + key: fs.readFileSync( + config['server']['ssl']['private_key'], + 'utf8', + ), + cert: fs.readFileSync( + config['server']['ssl']['cert'], + 'utf8', + ), + }, + } : false), }); -const getRateRoute = require("./routes/getRate.js"); -const getMetadata = require("./routes/metadata.js"); +const getRateRoute = require('./routes/getRate.js'); +const getMetadata = require('./routes/metadata.js'); fastify.register(getRateRoute); fastify.register(getMetadata); @@ -28,69 +34,69 @@ fastify.register(getMetadata); fastify.setNotFoundHandler(function (res, reply) { return reply.status(404).send({ status: 404, - message: "Page not found!", - documentation: "https://kekkai-docs.redume.su/", + message: 'Page not found!', + documentation: 'https://kekkai-docs.redume.su/', }); }); -fastify.addHook("onResponse", async (request, reply) => { - const routePart = request.raw.url.split("/"); +fastify.addHook('onResponse', async (request, reply) => { + const routePart = request.raw.url.split('/'); const routePartFiltered = routePart - .filter((part) => part !== "") + .filter((part) => part !== '') .map((part) => `${part}/`); - routePartFiltered.unshift("/"); + routePartFiltered.unshift('/'); - if (!config?.["analytics"]["work"] ? config?.["analytics"]["work"] : false) + if (!config?.['analytics']['work'] ? config?.['analytics']['work'] : false) return; else if (!fastify.printRoutes().includes(routePartFiltered.at(-1))) return; - const userAgent = request.headers["user-agent"]; + const userAgent = request.headers['user-agent']; const parser = new UAParser(userAgent); const browser = parser.getBrowser(); const os = parser.getOS(); const formattedOS = - os.name && os.version ? `${os.name} ${os.version}` : "N/A"; + os.name && os.version ? `${os.name} ${os.version}` : 'N/A'; const formattedBrowser = browser.name && browser.version ? `${browser.name} ${browser.version}` - : "N/A"; + : 'N/A'; const event = { - domain: config["analytics"]["plausible_domain"], + domain: config['analytics']['plausible_domain'], name: request.routeOptions.url ? request.routeOptions.url - : "404 - Not Found", + : '404 - Not Found', url: request.raw.url, props: { method: request.method, statusCode: reply.statusCode, browser: formattedBrowser, os: formattedOS, - source: request.headers["referer"] - ? request.headers["referer"] - : "direct", + source: request.headers['referer'] + ? request.headers['referer'] + : 'direct', }, }; try { - await axios.post(config["analytics"]["plausible_api"], event, { + await axios.post(config['analytics']['plausible_api'], event, { headers: { - Authorization: `Bearer ${config["analytics"]["plausible_token"]}`, - "Content-Type": "application/json", - "User-Agent": userAgent, + Authorization: `Bearer ${config['analytics']['plausible_token']}`, + 'Content-Type': 'application/json', + 'User-Agent': userAgent, }, }); } catch (error) { - fastify.log.error("Error sending event to Plausible:", error.message); + fastify.log.error('Error sending event to Plausible:', error.message); } }); fastify.listen( { port: 3000, - host: config["server"]["host"] ? config["server"]["host"] : "localhost", + host: config['server']['host'] ? config['server']['host'] : 'localhost', }, (err) => { if (err) { From da7134f4441428b6efba26cd5e80444a6de3e062 Mon Sep 17 00:00:00 2001 From: Redume Date: Mon, 3 Mar 2025 01:22:31 +0300 Subject: [PATCH 05/20] chore(server): Changed the name of the keys. Made it easier to change the domain --- server/main.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/server/main.js b/server/main.js index 6a21296..040f1e1 100644 --- a/server/main.js +++ b/server/main.js @@ -47,7 +47,11 @@ fastify.addHook('onResponse', async (request, reply) => { routePartFiltered.unshift('/'); - if (!config?.['analytics']['work'] ? config?.['analytics']['work'] : false) + if ( + !config?.['analytics']['enabled'] + ? config?.['analytics']['enabled'] + : false + ) return; else if (!fastify.printRoutes().includes(routePartFiltered.at(-1))) return; @@ -81,13 +85,17 @@ fastify.addHook('onResponse', async (request, reply) => { }; try { - await axios.post(config['analytics']['plausible_api'], event, { - headers: { - Authorization: `Bearer ${config['analytics']['plausible_token']}`, - 'Content-Type': 'application/json', - 'User-Agent': userAgent, + await axios.post( + `https://${config['analytics']['plausible_domain']}/api/event`, + event, + { + headers: { + Authorization: `Bearer ${config['analytics']['plausible_token']}`, + 'Content-Type': 'application/json', + 'User-Agent': userAgent, + }, }, - }); + ); } catch (error) { fastify.log.error('Error sending event to Plausible:', error.message); } From 8aa070d0d1fdb6ef57b6b2fc8724595d3dbbad90 Mon Sep 17 00:00:00 2001 From: Redume Date: Mon, 3 Mar 2025 01:27:32 +0300 Subject: [PATCH 06/20] =?UTF-8?q?chore(server):=20If=20logging=20is=20set?= =?UTF-8?q?=20to=20=E2=80=9Cnone=E2=80=9D,=20it=20is=20disabled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/main.js b/server/main.js index 040f1e1..4b8738f 100644 --- a/server/main.js +++ b/server/main.js @@ -8,7 +8,7 @@ const UAParser = require('ua-parser-js'); require('../shared/database/src/create_table.js')(); const fastify = require('fastify')({ - logger: config['server']['log']['print'] ? logger : false, + logger: config['server']['log']['level'] !== 'none' ? logger : false, ...(config['server']['ssl']['work'] ? { https: { From 547b6c27546773277330e226ebe56008aa6e9488 Mon Sep 17 00:00:00 2001 From: Redume Date: Mon, 3 Mar 2025 01:29:00 +0300 Subject: [PATCH 07/20] chore(server): change key for config --- server/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/main.js b/server/main.js index 4b8738f..165c7b3 100644 --- a/server/main.js +++ b/server/main.js @@ -9,7 +9,7 @@ require('../shared/database/src/create_table.js')(); const fastify = require('fastify')({ logger: config['server']['log']['level'] !== 'none' ? logger : false, - ...(config['server']['ssl']['work'] + ...(config['server']['ssl']['enabled'] ? { https: { key: fs.readFileSync( From e2c513fe8122107d33011fcfe614b5fd646d1223 Mon Sep 17 00:00:00 2001 From: Redume Date: Mon, 3 Mar 2025 01:29:38 +0300 Subject: [PATCH 08/20] fix(server): added the patch at the end, it was causing the analytics to malfunction --- server/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/main.js b/server/main.js index 165c7b3..33142a0 100644 --- a/server/main.js +++ b/server/main.js @@ -86,7 +86,7 @@ fastify.addHook('onResponse', async (request, reply) => { try { await axios.post( - `https://${config['analytics']['plausible_domain']}/api/event`, + `https://${config['analytics']['plausible_domain']}/api/event/`, event, { headers: { From 58e6ccfda62bbe36e47992c96d18717212e15d57 Mon Sep 17 00:00:00 2001 From: Redume Date: Mon, 3 Mar 2025 09:07:13 +0300 Subject: [PATCH 09/20] chore: change config name --- docker-compose.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docker-compose.yaml b/docker-compose.yaml index fa60175..36146cf 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -24,7 +24,7 @@ services: - '3000:3000' volumes: - './CertSSL:/CertSSL' - - './config.yaml:/config.yaml' + - './config.hjson:/config.hjson' depends_on: - postgres @@ -36,7 +36,7 @@ services: - '3030:3030' volumes: - './CertSSL:/CertSSL' - - './config.yaml:/config.yaml' + - './config.hjson:/config.hjson' depends_on: postgres: condition: service_healthy @@ -50,7 +50,7 @@ services: - '3050:3050' volumes: - './CertSSL:/CertSSL' - - './config.yaml:/config.yaml' + - './config.hjson:/config.hjson' docs: build: @@ -63,7 +63,7 @@ services: dockerfile: Dockerfile-collect-currency restart: unless-stopped volumes: - - './config.yaml:/config.yaml' + - './config.hjson:/config.hjson' depends_on: - postgres From dd24356e811c0b9217fd3c53afa04b1ee2dcc9d1 Mon Sep 17 00:00:00 2001 From: Redume Date: Mon, 3 Mar 2025 09:43:13 +0300 Subject: [PATCH 10/20] chore(web): Changed the keys of the new config. Improved code readability --- web/main.js | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/web/main.js b/web/main.js index 86a2f43..5d27e2f 100644 --- a/web/main.js +++ b/web/main.js @@ -1,18 +1,24 @@ -const logger = require("../shared/logger"); -const config = require("../shared/config/src/main.js")(); +const logger = require('../shared/logger'); +const config = require('../shared/config/src/main.js')(); -const fs = require("fs"); -const path = require("node:path"); +const fs = require('fs'); +const path = require('node:path'); -const fastify = require("fastify")({ - logger: config["server"]["log"]["print"] ? logger : false, - ...(config["server"]["ssl"]["work"] +const fastify = require('fastify')({ + logger: config['server']['log']['level'] !== 'none' ? logger : false, + ...(config['server']['ssl']['enabled'] ? { - https: { - key: fs.readFileSync(config["server"]["ssl"]["private_key"], "utf8"), - cert: fs.readFileSync(config["server"]["ssl"]["cert"], "utf8"), - }, - } + https: { + key: fs.readFileSync( + config['server']['ssl']['private_key'], + 'utf8', + ), + cert: fs.readFileSync( + config['server']['ssl']['cert'], + 'utf8', + ), + }, + } : false), }); @@ -23,11 +29,10 @@ fastify.register(require('@fastify/static'), { fastify.register(require('./routes/home.js')); - fastify.listen( { port: 3050, - host: config["server"]["host"] ? config["server"]["host"] : "localhost", + host: config['server']['host'] ? config['server']['host'] : 'localhost', }, (err) => { if (err) { From 1964fd333a9e5b4bd1508d8d4ea77412e6c36ad0 Mon Sep 17 00:00:00 2001 From: Redume Date: Mon, 3 Mar 2025 09:44:49 +0300 Subject: [PATCH 11/20] chore(config): Adapted the code to output a new config. Added an error if there is no config file --- shared/config/package-lock.json | 17 +++++++---------- shared/config/package.json | 2 +- shared/config/src/main.js | 6 +++--- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/shared/config/package-lock.json b/shared/config/package-lock.json index 6f0d56d..5e649ba 100644 --- a/shared/config/package-lock.json +++ b/shared/config/package-lock.json @@ -9,19 +9,16 @@ "version": "1.0.0", "license": "GPL-3.0-or-later", "dependencies": { - "yaml": "^2.5.0" + "hjson": "^3.2.2" } }, - "node_modules/yaml": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.5.0.tgz", - "integrity": "sha512-2wWLbGbYDiSqqIKoPjar3MPgB94ErzCtrNE1FdqGuaO0pi2JGjmE8aW8TDZwzU7vuxcGRdL/4gPQwQ7hD5AMSw==", - "license": "ISC", + "node_modules/hjson": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/hjson/-/hjson-3.2.2.tgz", + "integrity": "sha512-MkUeB0cTIlppeSsndgESkfFD21T2nXPRaBStLtf3cAYA2bVEFdXlodZB0TukwZiobPD1Ksax5DK4RTZeaXCI3Q==", + "license": "MIT", "bin": { - "yaml": "bin.mjs" - }, - "engines": { - "node": ">= 14" + "hjson": "bin/hjson" } } } diff --git a/shared/config/package.json b/shared/config/package.json index 00b3ddd..e196982 100644 --- a/shared/config/package.json +++ b/shared/config/package.json @@ -17,6 +17,6 @@ "homepage": "https://github.com/Redume/Kekkai#readme", "description": "Config management service", "dependencies": { - "yaml": "^2.5.0" + "hjson": "^3.2.2" } } diff --git a/shared/config/src/main.js b/shared/config/src/main.js index 97b7b20..d0108d8 100644 --- a/shared/config/src/main.js +++ b/shared/config/src/main.js @@ -1,10 +1,10 @@ const fs = require('fs'); -const yaml = require('yaml'); +const hjson = require('hjson'); const config = () => { - if (!fs.existsSync('../config.yaml')) return; + if (!fs.existsSync('../config.hjson')) throw new Error('Config not found'); - return yaml.parse(fs.readFileSync('../config.yaml', 'utf-8')); + return hjson.parse(fs.readFileSync('../config.hjson', 'utf-8')); }; module.exports = config; From c00dea8a81026af8224ea1830dc3d426af94f499 Mon Sep 17 00:00:00 2001 From: Redume Date: Mon, 3 Mar 2025 10:38:53 +0300 Subject: [PATCH 12/20] =?UTF-8?q?=D1=81hore(chart):=20Made=20parsing=20and?= =?UTF-8?q?=20converting=20hjson=20to=20json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chart/utils/load_config.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/chart/utils/load_config.py b/chart/utils/load_config.py index c6f2bbd..746e106 100644 --- a/chart/utils/load_config.py +++ b/chart/utils/load_config.py @@ -1,20 +1,18 @@ -# pylint: disable=R0801 """ -This module provides a function for loading a YAML configuration file. -The function reads the file content and returns it as a Python dictionary. +Parsing and converting HJSON config to JSON """ -import yaml +import hjson +import json def load_config(file_path: str) -> dict: """ - Loads a YAML configuration file and returns its contents as a dictionary. + Load an HJSON file, convert it to a JSON string with indentation, + and return it. - This function opens the specified YAML file, parses its content, and - returns it in dictionary format, making it accessible for use in - the application. + params: file_path (str): The path to the HJSON file. - :param file_path: The path to the YAML configuration file to be loaded. - :return: A dictionary containing the parsed content of the YAML file. + returns str: The JSON string formatted with indentation. """ with open(file_path, 'r', encoding='utf-8') as file: - return yaml.safe_load(file) + hjson_data = hjson.load(file) + return json.dumps(hjson_data, indent=4) From 6cddaa53a830bc75596c86de1bb3ec925345724c Mon Sep 17 00:00:00 2001 From: Redume Date: Mon, 3 Mar 2025 10:39:43 +0300 Subject: [PATCH 13/20] chore(chart): rename config file, yaml to hjson --- chart/database/server.py | 2 +- chart/main.py | 2 +- chart/middleware/plausible_analytics.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/chart/database/server.py b/chart/database/server.py index 293ff24..a5f48de 100644 --- a/chart/database/server.py +++ b/chart/database/server.py @@ -9,7 +9,7 @@ import asyncpg from utils.load_config import load_config -config = load_config('config.yaml') +config = load_config('config.hjson') async def create_pool() -> asyncpg.pool.Pool: """ diff --git a/chart/main.py b/chart/main.py index b194c71..567baee 100644 --- a/chart/main.py +++ b/chart/main.py @@ -16,7 +16,7 @@ from routes import get_chart, get_chart_period from utils.load_config import load_config app = FastAPI() -config = load_config('config.yaml') +config = load_config('config.hjson') if not os.path.exists('../charts'): os.mkdir('../charts') diff --git a/chart/middleware/plausible_analytics.py b/chart/middleware/plausible_analytics.py index 50fa138..7afb4d5 100644 --- a/chart/middleware/plausible_analytics.py +++ b/chart/middleware/plausible_analytics.py @@ -9,7 +9,7 @@ from user_agents import parse as ua_parse from utils.load_config import load_config -config = load_config('config.yaml') +config = load_config('config.hjson') # pylint: disable=too-few-public-methods class PlausibleAnalytics: From f4475ae466c4f6337898907bacc1ff5cc28ad418 Mon Sep 17 00:00:00 2001 From: Redume Date: Mon, 3 Mar 2025 10:40:06 +0300 Subject: [PATCH 14/20] deps(chart): Replaced pyyaml with hjson. --- chart/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chart/requirements.txt b/chart/requirements.txt index 278ef87..105a064 100644 --- a/chart/requirements.txt +++ b/chart/requirements.txt @@ -1,5 +1,5 @@ matplotlib~=3.9.1 -PyYAML~=6.0.1 +hjson~=3.1.0 uvicorn~=0.29.0 fastapi[standard]~=0.115.2 starlette~=0.40.0 From f307644a8cbaa3acc99c611f68c1a9088d738693 Mon Sep 17 00:00:00 2001 From: Redume Date: Mon, 3 Mar 2025 10:47:56 +0300 Subject: [PATCH 15/20] fix(chart): fixed an error with getting a config item --- chart/utils/load_config.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/chart/utils/load_config.py b/chart/utils/load_config.py index 746e106..197b974 100644 --- a/chart/utils/load_config.py +++ b/chart/utils/load_config.py @@ -15,4 +15,6 @@ def load_config(file_path: str) -> dict: """ with open(file_path, 'r', encoding='utf-8') as file: hjson_data = hjson.load(file) - return json.dumps(hjson_data, indent=4) + return json.loads( + json.dumps(hjson_data, indent=4) + ) From 64185e75658ef3924c552d812247dd9643b9068f Mon Sep 17 00:00:00 2001 From: Redume Date: Mon, 3 Mar 2025 10:52:28 +0300 Subject: [PATCH 16/20] chore(chart): change to new key config --- chart/main.py | 4 ++-- chart/middleware/plausible_analytics.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/chart/main.py b/chart/main.py index 567baee..9fc86f2 100644 --- a/chart/main.py +++ b/chart/main.py @@ -35,10 +35,10 @@ if __name__ == '__main__': port=3030, ssl_keyfile= config['server']['ssl']['private_key'] - if config['server']['ssl']['work'] + if config['server']['ssl']['enabled'] else None, ssl_certfile= config['server']['ssl']['cert'] - if config['server']['ssl']['work'] + if config['server']['ssl']['enabled'] else None ) diff --git a/chart/middleware/plausible_analytics.py b/chart/middleware/plausible_analytics.py index 7afb4d5..9da2b7c 100644 --- a/chart/middleware/plausible_analytics.py +++ b/chart/middleware/plausible_analytics.py @@ -23,7 +23,7 @@ class PlausibleAnalytics: async def __call__(self, request, call_next): response = await call_next(request) - if HTTPStatus(response.status_code).is_client_error or not config['analytics']['work']: + if HTTPStatus(response.status_code).is_client_error or not config['analytics']['enabled']: return response user_agent = request.headers.get('user-agent', 'unknown') From dd69715f8e4b0d1a7ed41cb3bdc4ec9fcdad1321 Mon Sep 17 00:00:00 2001 From: Redume Date: Wed, 5 Mar 2025 21:48:27 +0300 Subject: [PATCH 17/20] fix(config): fix crontab --- config.example.hjson | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.example.hjson b/config.example.hjson index 37cfbed..4cafc6b 100644 --- a/config.example.hjson +++ b/config.example.hjson @@ -33,7 +33,7 @@ { fiat: true crypto: false - schedule: 30 * * * + schedule: 30 8 * * * crypto_apikey: TOKEN } fiat: From 8675fd918f66dd696c805d4c214e80102a5ca8ea Mon Sep 17 00:00:00 2001 From: Redume Date: Wed, 5 Mar 2025 21:48:45 +0300 Subject: [PATCH 18/20] chore: delete catch error --- collect-currency/main.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/collect-currency/main.js b/collect-currency/main.js index b81586a..be8722a 100644 --- a/collect-currency/main.js +++ b/collect-currency/main.js @@ -13,7 +13,7 @@ async function validateSchedule(schedule) { } async function initialize() { - await require('../shared/database/src/create_table')(); + //await require('../shared/database/src/create_table')(); } async function runTasks() { @@ -21,6 +21,7 @@ async function runTasks() { } async function main() { + console.log(config['currency']['collecting']['schedule']) await initialize(); await validateSchedule(config['currency']['collecting']['schedule']); @@ -32,8 +33,6 @@ async function main() { ); } -main().catch((err) => { - logger.error('Error in main execution:', err); -}); +main(); module.exports = { main }; From dd73f73869b955243c98cf082319c709c87592ee Mon Sep 17 00:00:00 2001 From: Redume Date: Wed, 5 Mar 2025 22:25:26 +0300 Subject: [PATCH 19/20] Revert "chore(server): Changed the name of the keys. Made it easier to change the domain" This reverts commit da7134f4441428b6efba26cd5e80444a6de3e062. --- config.example.hjson | 1 + server/main.js | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/config.example.hjson b/config.example.hjson index 4cafc6b..4685ea6 100644 --- a/config.example.hjson +++ b/config.example.hjson @@ -25,6 +25,7 @@ { plausible_domain: plausible.io plausible_token: TOKEN + plausiblee_api: https://plausible.io//api/event/ enabled: false } currency: diff --git a/server/main.js b/server/main.js index 33142a0..7c72dc3 100644 --- a/server/main.js +++ b/server/main.js @@ -47,11 +47,7 @@ fastify.addHook('onResponse', async (request, reply) => { routePartFiltered.unshift('/'); - if ( - !config?.['analytics']['enabled'] - ? config?.['analytics']['enabled'] - : false - ) + if (!config?.['analytics']['work'] ? config?.['analytics']['work'] : false) return; else if (!fastify.printRoutes().includes(routePartFiltered.at(-1))) return; @@ -85,6 +81,7 @@ fastify.addHook('onResponse', async (request, reply) => { }; try { +<<<<<<< HEAD await axios.post( `https://${config['analytics']['plausible_domain']}/api/event/`, event, @@ -94,8 +91,15 @@ fastify.addHook('onResponse', async (request, reply) => { 'Content-Type': 'application/json', 'User-Agent': userAgent, }, +======= + await axios.post(config['analytics']['plausible_api'], event, { + headers: { + Authorization: `Bearer ${config['analytics']['plausible_token']}`, + 'Content-Type': 'application/json', + 'User-Agent': userAgent, +>>>>>>> parent of da7134f (chore(server): Changed the name of the keys. Made it easier to change the domain) }, - ); + }); } catch (error) { fastify.log.error('Error sending event to Plausible:', error.message); } From f79d2b166a4ac773d04319b2d211c1b7a0172862 Mon Sep 17 00:00:00 2001 From: Redume Date: Wed, 5 Mar 2025 22:27:36 +0300 Subject: [PATCH 20/20] docs: Rename the file, replace the examples with a new config --- docs/astro.config.mjs | 4 +- .../{config-yaml.mdx => config-hjson.mdx} | 162 +++++++++++------- 2 files changed, 100 insertions(+), 66 deletions(-) rename docs/src/content/docs/docs/config/{config-yaml.mdx => config-hjson.mdx} (59%) diff --git a/docs/astro.config.mjs b/docs/astro.config.mjs index e310848..cf37752 100644 --- a/docs/astro.config.mjs +++ b/docs/astro.config.mjs @@ -51,8 +51,8 @@ export default defineConfig({ slug: 'docs/config/config-env' }, { - label: 'Configure config.yaml', - slug: 'docs/config/config-yaml' + label: 'Configure config.hjson', + slug: 'docs/config/config-hjson' }, { label: 'Configure Nginx', diff --git a/docs/src/content/docs/docs/config/config-yaml.mdx b/docs/src/content/docs/docs/config/config-hjson.mdx similarity index 59% rename from docs/src/content/docs/docs/config/config-yaml.mdx rename to docs/src/content/docs/docs/config/config-hjson.mdx index dcd0885..fe649ce 100644 --- a/docs/src/content/docs/docs/config/config-yaml.mdx +++ b/docs/src/content/docs/docs/config/config-hjson.mdx @@ -1,66 +1,93 @@ --- -title: Configure config.yaml +title: Configure config.hjson --- import { Aside } from '@astrojs/starlight/components'; -Kekkai can be configured using the `config.yaml` file in the working directory. -`config.example.yaml`. +Kekkai can be configured using the `config.hjson` file in the working directory. +`config.example.hjson`. -```yaml +```hjson # For more information, see the documentation # https://kekkai-docs.redume.su/ -database: - user: 'DATABASE_USERNAME' - password: 'DATABASE_PASSWORD' - host: 'DATABASE_HOST' - name: 'DATABASE_NAME' - port: 5432 -server: - host: '0.0.0.0' - ssl: - private_key: '/CertSSL/privkey.pem' - cert: '/CertSSL/fullchain.pem' - work: true - log: - print: true - level: 'info' -analytics: - plausible_api: 'https://plausible.io/api/event/' - plausible_domain: 'PLAUSIBLE_DOMAIN' - plausible_token: 'PLAUSIBLE_TOKEN' - work: false -currency: - chart: - save: false - collecting: +{ + database: + { + user: DATABASE_USERNAME + password: DATABASE_PASSWORD + host: localhost + name: kekkai + port: 5432 + } + server: + { + host: 0.0.0.0 + ssl: + { + private_key: /CertSSL/privkey.pem + cert: /CertSSL/fullchain.pem + enabled: false + } + log: + { + level: info + } + } + analytics: + { + plausible_domain: plausible.io + plausible_token: TOKEN + enabled: false + } + currency: + { + collecting: + { fiat: true - schedule: '30 8 * * *' - fiat: - - USD - - RUB - - EUR - - UAH - - TRY - - KZT + crypto: false + schedule: 30 8 * * * + crypto_apikey: TOKEN + } + fiat: + [ + USD + RUB + EUR + UAH + TRY + KZT + ] + crypto: + [ + ETH + TON + USDT + BTC + ] + } + } ``` ## Database Kekkai is used as a `PostgreSQL` database. @@ -96,7 +123,7 @@ analytics: plausible_api: 'https://plausible.io/api/event/' plausible_domain: 'PLAUSIBLE_DOMAIN' plausible_token: 'PLAUSIBLE_TOKEN' - work: true + enabled: true ... ``` @@ -107,7 +134,7 @@ analytics: You can add the domain [here](https://plausible.io/sites/new?flow=provisioning). - `plausible_token`: Api token for authorization and sending requests. You can create it [here](https://plausible.io/settings/api-keys). -- `work`: Enable or disable analytics. +- `enabled`: Enable or disable analytics. ## Currency `DuckDuckGo` (fiat currency collection) and `CoinMarketCap` (cryptocurrency collection) @@ -116,25 +143,32 @@ are used to collect currency rates. ```yaml ... -currency: - chart: - save: false # Enable or disable saving graphs to an image (Boolean) - collecting: - fiat: true # Turn off or turn on the collection of the fiat currency rate [Boolean] + currency: + { + collecting: + { + fiat: true crypto: false - schedule: '30 8 * * *' # Currency collection schedule in crontab format [String] - crypto_apikey: 'APIKEY' - fiat: # List of fiat currency to save the exchange rate [Array] - - USD - - RUB - - EUR - - UAH - - TRY - - KZT - crypto: - - ETH - - TON - - USDT + schedule: 30 8 * * * + crypto_apikey: TOKEN + } + fiat: + [ + USD + RUB + EUR + UAH + TRY + KZT + ] + crypto: + [ + ETH + TON + USDT + BTC + ] + } ``` - `currency.chart.save`: Enable or disable saving graphs.