Compare commits

...

5 Commits

Author SHA1 Message Date
orangecoding
18fdbd761a next release version 2025-09-17 09:12:45 +02:00
Iaroslav Postovalov
027e7d70ed Update SQLite adapter: configurable database path (#169) 2025-09-17 09:12:04 +02:00
Christian Kellner
de119c9199 Update logger.js 2025-09-14 15:46:31 +02:00
orangecoding
ce7f0bca9f next release version 2025-09-14 10:40:41 +02:00
orangecoding
ae1c4d936b do not log debug on production 2025-09-14 10:40:18 +02:00
4 changed files with 34 additions and 17 deletions

View File

@@ -1,7 +1,18 @@
import { markdown2Html } from '../../services/markdown.js'; import { markdown2Html } from '../../services/markdown.js';
import Database from 'better-sqlite3'; import Database from 'better-sqlite3';
export const send = ({ serviceName, newListings, jobKey }) => { import path from 'path';
const db = new Database('db/listings.db'); import fs from 'fs';
export const send = ({ serviceName, newListings, jobKey, notificationConfig }) => {
const sqliteConfig = notificationConfig.find((adapter) => adapter.id === config.id);
const dbPath = sqliteConfig?.fields?.dbPath || 'db/listings.db';
const dbDir = path.dirname(dbPath);
if (!fs.existsSync(dbDir)) {
fs.mkdirSync(dbDir, { recursive: true });
}
const db = new Database(dbPath);
const fields = [ const fields = [
'serviceName', 'serviceName',
'jobKey', 'jobKey',
@@ -30,8 +41,16 @@ export const send = ({ serviceName, newListings, jobKey }) => {
}; };
export const config = { export const config = {
id: 'sqlite', id: 'sqlite',
name: 'Sqlite', name: 'SQLite',
description: 'This adapter stores listings in a local sqlite3 database.', description: 'This adapter stores listings in a local SQLite 3 database.',
config: {}, fields: {
dbPath: {
type: 'text',
label: 'Database Path',
description:
'Path to the SQLite database file (e.g., db/listings.db). If not specified, defaults to db/listings.db',
placeholder: 'db/listings.db',
},
},
readme: markdown2Html('lib/notification/adapter/sqlite.md'), readme: markdown2Html('lib/notification/adapter/sqlite.md'),
}; };

View File

@@ -1,9 +1,9 @@
### Sqlite Adapter ### SQLite Adapter
This adapter stores search results in a sqlite database located in db/listings.db. This file can be used for further analysis later on. This adapter stores search results in an SQLite database. By default, the database is located at `db/listings.db`, but you can configure a custom location. This file can be used for further analysis later.
Fields are: The database table contains the following columns (all stored as `TEXT` type):
``` ```
['serviceName', 'jobKey', 'id', 'size', 'rooms', 'price', 'address', 'title', 'link', 'description'] ['serviceName', 'jobKey', 'id', 'size', 'rooms', 'price', 'address', 'title', 'link', 'description', 'image']
``` ```

View File

@@ -6,6 +6,7 @@ const COLORS = {
reset: '\x1b[0m', reset: '\x1b[0m',
}; };
const env = process.env.NODE_ENV || 'development';
const useColor = process.stdout.isTTY || process.stderr.isTTY; const useColor = process.stdout.isTTY || process.stderr.isTTY;
function ts() { function ts() {
@@ -27,6 +28,10 @@ function lvl(level) {
/* eslint-disable no-console */ /* eslint-disable no-console */
function log(level, ...args) { function log(level, ...args) {
if (level === 'debug' && env !== 'development') {
return; // Skip debug logs in non-development environments
}
const prefix = `[${ts()}] ${lvl(level)}:`; const prefix = `[${ts()}] ${lvl(level)}:`;
switch (level) { switch (level) {
case 'debug': case 'debug':
@@ -52,10 +57,3 @@ export default {
warn: (...a) => log('warn', ...a), warn: (...a) => log('warn', ...a),
error: (...a) => log('error', ...a), error: (...a) => log('error', ...a),
}; };
// Beispiel:
// import logger from './logger.js';
// const a = 'fick';
// const b = { tr: 'lolo' };
// logger.info('hallo', a, b);
// -> In IntelliJ siehst du das Objekt wie bei console.info, plus Prefix

View File

@@ -1,6 +1,6 @@
{ {
"name": "fredy", "name": "fredy",
"version": "11.6.4", "version": "11.6.6",
"description": "[F]ind [R]eal [E]states [d]amn eas[y].", "description": "[F]ind [R]eal [E]states [d]amn eas[y].",
"scripts": { "scripts": {
"prepare": "husky", "prepare": "husky",