mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e868cdce86 | ||
|
|
d66dc2cd93 | ||
|
|
5e0405f1ec |
18
README.md
18
README.md
@@ -1,3 +1,16 @@
|
|||||||
|
<p align="center">
|
||||||
|
<a href="https://fredy.orange-coding.net/">
|
||||||
|
<img alt="Expo logo" width="400" src="https://github.com/orangecoding/fredy/blob/master/doc/logo.png">
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|

|
||||||
|
[](https://github.com/orangecoding/fredy/actions/workflows/docker.yml)
|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
# Fredy 🏡 – Your Self-Hosted Real Estate Finder for Germany
|
# Fredy 🏡 – Your Self-Hosted Real Estate Finder for Germany
|
||||||
|
|
||||||
Finding an apartment or house in Germany can be stressful and
|
Finding an apartment or house in Germany can be stressful and
|
||||||
@@ -11,12 +24,7 @@ With a modern architecture, Fredy provides a **clean Web UI**, removes
|
|||||||
duplicates across platforms, and stores results so you never see the
|
duplicates across platforms, and stores results so you never see the
|
||||||
same listing twice.
|
same listing twice.
|
||||||
|
|
||||||
<img src="https://github.com/orangecoding/fredy/blob/master/doc/logo.png" width="400">
|
|
||||||
|
|
||||||

|
|
||||||
[](https://github.com/orangecoding/fredy/actions/workflows/docker.yml)
|
|
||||||

|
|
||||||

|
|
||||||
|
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
4
index.js
4
index.js
@@ -6,9 +6,9 @@ import * as jobStorage from './lib/services/storage/jobStorage.js';
|
|||||||
import FredyRuntime from './lib/FredyRuntime.js';
|
import FredyRuntime from './lib/FredyRuntime.js';
|
||||||
import { duringWorkingHoursOrNotSet } from './lib/utils.js';
|
import { duringWorkingHoursOrNotSet } from './lib/utils.js';
|
||||||
import './lib/api/api.js';
|
import './lib/api/api.js';
|
||||||
import { track } from './lib/services/tracking/Tracker.js';
|
|
||||||
import { handleDemoUser } from './lib/services/storage/userStorage.js';
|
import { handleDemoUser } from './lib/services/storage/userStorage.js';
|
||||||
import { cleanupDemoAtMidnight } from './lib/services/demoCleanup.js';
|
import { cleanupDemoAtMidnight } from './lib/services/demoCleanup.js';
|
||||||
|
import { initTrackerCron } from './lib/services/tracking/Tracker-Cron.js';
|
||||||
//if db folder does not exist, ensure to create it before loading anything else
|
//if db folder does not exist, ensure to create it before loading anything else
|
||||||
if (!fs.existsSync('./db')) {
|
if (!fs.existsSync('./db')) {
|
||||||
fs.mkdirSync('./db');
|
fs.mkdirSync('./db');
|
||||||
@@ -29,13 +29,13 @@ const fetchedProvider = await Promise.all(
|
|||||||
);
|
);
|
||||||
|
|
||||||
handleDemoUser();
|
handleDemoUser();
|
||||||
|
await initTrackerCron();
|
||||||
|
|
||||||
setInterval(
|
setInterval(
|
||||||
(function exec() {
|
(function exec() {
|
||||||
const isDuringWorkingHoursOrNotSet = duringWorkingHoursOrNotSet(config, Date.now());
|
const isDuringWorkingHoursOrNotSet = duringWorkingHoursOrNotSet(config, Date.now());
|
||||||
if (!config.demoMode) {
|
if (!config.demoMode) {
|
||||||
if (isDuringWorkingHoursOrNotSet) {
|
if (isDuringWorkingHoursOrNotSet) {
|
||||||
track();
|
|
||||||
config.lastRun = Date.now();
|
config.lastRun = Date.now();
|
||||||
jobStorage
|
jobStorage
|
||||||
.getJobs()
|
.getJobs()
|
||||||
|
|||||||
17
lib/services/tracking/Tracker-Cron.js
Normal file
17
lib/services/tracking/Tracker-Cron.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import cron from 'node-cron';
|
||||||
|
import { config, inDevMode } from '../../utils.js';
|
||||||
|
import { trackMainEvent } from './Tracker.js';
|
||||||
|
|
||||||
|
async function runTask() {
|
||||||
|
//make sure to only send tracking events if the user gave us the green light and we are not in dev mode
|
||||||
|
if (config.analyticsEnabled && !inDevMode()) {
|
||||||
|
await trackMainEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function initTrackerCron() {
|
||||||
|
//run directly on start
|
||||||
|
await runTask();
|
||||||
|
// then every 6 hours
|
||||||
|
cron.schedule('0 */6 * * *', runTask);
|
||||||
|
}
|
||||||
@@ -10,11 +10,7 @@ const deviceId = getUniqueId() || 'N/A';
|
|||||||
const version = await getPackageVersion();
|
const version = await getPackageVersion();
|
||||||
const FREDY_TRACKING_URL = 'https://fredy.orange-coding.net/tracking';
|
const FREDY_TRACKING_URL = 'https://fredy.orange-coding.net/tracking';
|
||||||
|
|
||||||
let cached = null;
|
export const trackMainEvent = async () => {
|
||||||
let lastSent = 0;
|
|
||||||
const SIX_HOURS = 6 * 3_600_000;
|
|
||||||
|
|
||||||
export const track = async () => {
|
|
||||||
try {
|
try {
|
||||||
if (config.analyticsEnabled && !inDevMode()) {
|
if (config.analyticsEnabled && !inDevMode()) {
|
||||||
const activeProvider = new Set();
|
const activeProvider = new Set();
|
||||||
@@ -33,19 +29,11 @@ export const track = async () => {
|
|||||||
provider: Array.from(activeProvider),
|
provider: Array.from(activeProvider),
|
||||||
});
|
});
|
||||||
|
|
||||||
const stringify = JSON.stringify(trackingObj);
|
await fetch(`${FREDY_TRACKING_URL}/main`, {
|
||||||
const now = Date.now();
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
// send if changed OR six hours passed since last send
|
body: JSON.stringify(trackingObj),
|
||||||
if (stringify !== cached || now - lastSent >= SIX_HOURS) {
|
});
|
||||||
await fetch(`${FREDY_TRACKING_URL}/main`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: stringify,
|
|
||||||
});
|
|
||||||
cached = stringify;
|
|
||||||
lastSent = now;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "fredy",
|
"name": "fredy",
|
||||||
"version": "11.6.2",
|
"version": "11.6.3",
|
||||||
"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",
|
||||||
@@ -71,6 +71,7 @@
|
|||||||
"lowdb": "7.0.1",
|
"lowdb": "7.0.1",
|
||||||
"markdown": "^0.5.0",
|
"markdown": "^0.5.0",
|
||||||
"nanoid": "5.1.5",
|
"nanoid": "5.1.5",
|
||||||
|
"node-cron": "^4.2.1",
|
||||||
"node-fetch": "3.3.2",
|
"node-fetch": "3.3.2",
|
||||||
"node-mailjet": "6.0.9",
|
"node-mailjet": "6.0.9",
|
||||||
"p-throttle": "^8.0.0",
|
"p-throttle": "^8.0.0",
|
||||||
|
|||||||
@@ -5521,6 +5521,11 @@ node-abi@^3.3.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
semver "^7.3.5"
|
semver "^7.3.5"
|
||||||
|
|
||||||
|
node-cron@^4.2.1:
|
||||||
|
version "4.2.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/node-cron/-/node-cron-4.2.1.tgz#6979be4aee4702f06322d21220df8de252c8e265"
|
||||||
|
integrity sha512-lgimEHPE/QDgFlywTd8yTR61ptugX3Qer29efeyWw2rv259HtGBNn1vZVmp8lB9uo9wC0t/AT4iGqXxia+CJFg==
|
||||||
|
|
||||||
node-domexception@^1.0.0:
|
node-domexception@^1.0.0:
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/node-domexception/-/node-domexception-1.0.0.tgz#6888db46a1f71c0b76b3f7555016b63fe64766e5"
|
resolved "https://registry.yarnpkg.com/node-domexception/-/node-domexception-1.0.0.tgz#6888db46a1f71c0b76b3f7555016b63fe64766e5"
|
||||||
|
|||||||
Reference in New Issue
Block a user