Project-wide linting and formatting (#150)

* chore: configure project-wide linting and formatting

* chore: run lint autofix and formatter
This commit is contained in:
Alexander Roidl
2025-07-26 20:42:58 +02:00
committed by GitHub
parent 206f768b41
commit 2b36f868e7
52 changed files with 435 additions and 382 deletions

View File

@@ -3,9 +3,7 @@
[ [
"@babel/preset-env", "@babel/preset-env",
{ {
"exclude": [ "exclude": ["transform-regenerator"]
"transform-regenerator"
]
} }
], ],
[ [
@@ -15,4 +13,4 @@
} }
] ]
] ]
} }

3
.eslintignore Normal file
View File

@@ -0,0 +1,3 @@
/ui/public
/db/
/conf/

View File

@@ -277,6 +277,5 @@ module.exports = {
// Prevent passing of children as props // Prevent passing of children as props
// https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-children-prop.md // https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-children-prop.md
'react/no-children-prop': 'warn', 'react/no-children-prop': 'warn',
}, },
}; };

View File

@@ -4,7 +4,6 @@ about: Create a report to help us improve
title: '' title: ''
labels: '' labels: ''
assignees: '' assignees: ''
--- ---
**Describe the bug** **Describe the bug**
@@ -12,6 +11,7 @@ A clear and concise description of what the bug is.
**To Reproduce** **To Reproduce**
Steps to reproduce the behavior: Steps to reproduce the behavior:
1. Go to '...' 1. Go to '...'
2. Click on '....' 2. Click on '....'
3. Scroll down to '....' 3. Scroll down to '....'

View File

@@ -4,7 +4,6 @@ about: Suggest an idea for this project
title: '' title: ''
labels: '' labels: ''
assignees: '' assignees: ''
--- ---
**Is your feature request related to a problem? Please describe.** **Is your feature request related to a problem? Please describe.**

View File

@@ -2,7 +2,7 @@ name: Close stale issues and PRs
on: on:
schedule: schedule:
- cron: '0 0 * * *' # Daily - cron: '0 0 * * *' # Daily
jobs: jobs:
stale: stale:
@@ -12,10 +12,10 @@ jobs:
with: with:
days-before-stale: 30 days-before-stale: 30
days-before-close: 7 days-before-close: 7
stale-issue-message: "This issue has been automatically marked as stale due to inactivity." stale-issue-message: 'This issue has been automatically marked as stale due to inactivity.'
stale-pr-message: "This PR has been automatically marked as stale due to inactivity." stale-pr-message: 'This PR has been automatically marked as stale due to inactivity.'
close-issue-message: "Closing this issue due to prolonged inactivity." close-issue-message: 'Closing this issue due to prolonged inactivity.'
close-pr-message: "Closing this PR due to prolonged inactivity." close-pr-message: 'Closing this PR due to prolonged inactivity.'
exempt-issue-labels: "keep-open" exempt-issue-labels: 'keep-open'
exempt-pr-labels: "keep-open" exempt-pr-labels: 'keep-open'
only: "pulls" only: 'pulls'

6
.prettierignore Normal file
View File

@@ -0,0 +1,6 @@
/ui/public
/db/
/conf/
# TODO re-write from scratch or fix all html structure issues
/lib/notification/emailTemplate/template.hbs

View File

@@ -1,34 +1,42 @@
Newer release changelog see https://github.com/orangecoding/fredy/releases Newer release changelog see https://github.com/orangecoding/fredy/releases
------------ ---
###### [V5.5.0] ###### [V5.5.0]
- Upgrading dependencies - Upgrading dependencies
- fixing provider - fixing provider
- allow multiple instances of 1 provider - allow multiple instances of 1 provider
- __BREAKING__: Minimum node version is now 16 - **BREAKING**: Minimum node version is now 16
###### [V5.4.6] ###### [V5.4.6]
- Adding Instana node.js monitoring - Adding Instana node.js monitoring
- -
###### [V5.4.5] ###### [V5.4.5]
- Adding Instana node.js monitoring
- Adding Instana node.js monitoring
###### [V5.4.4] ###### [V5.4.4]
- Add support for Immo Südwest Presse (immo.swp.de) - Add support for Immo Südwest Presse (immo.swp.de)
- Telegram: Use job name instead of ID and link in title - Telegram: Use job name instead of ID and link in title
- Fix race condition if user ID is in session but not in user store - Fix race condition if user ID is in session but not in user store
- Allow visiting the original provider URL - Allow visiting the original provider URL
###### [V5.4.3] ###### [V5.4.3]
- re-writing readme - re-writing readme
- improving docker build - improving docker build
- using github's actions to build docker and test automatically - using github's actions to build docker and test automatically
###### [V5.4.2] ###### [V5.4.2]
- Fixing prod build - Fixing prod build
###### [V5.4.1] ###### [V5.4.1]
- Upgrading dependencies - Upgrading dependencies
- Provider urls are now automagically been changed to include the correct sort order for search results - Provider urls are now automagically been changed to include the correct sort order for search results
@@ -39,36 +47,44 @@ results, thus cannot report them. This release fixes it by adding the necessary
``` ```
###### [V5.3.0] ###### [V5.3.0]
- Upgrading dependencies - Upgrading dependencies
- It's now possible to send mails to multiple receiver using comma separation for MailJet & Sendgrid - It's now possible to send mails to multiple receiver using comma separation for MailJet & Sendgrid
- Fixing Immowelt scraping - Fixing Immowelt scraping
###### [V5.2.0] ###### [V5.2.0]
- Upgrading dependencies - Upgrading dependencies
- Adding new similarity check layer (Duplicates are being removed now) - Adding new similarity check layer (Duplicates are being removed now)
- Adding paging for search results - Adding paging for search results
###### [V5.1.0] ###### [V5.1.0]
- Upgrading dependencies - Upgrading dependencies
- NodeJS 12.13 is now the minimum supported version - NodeJS 12.13 is now the minimum supported version
- Adding general settings as new configuration page to ui - Adding general settings as new configuration page to ui
- Adding new feature working hours - Adding new feature working hours
###### [V5.0.0] ###### [V5.0.0]
- Upgrading dependencies - Upgrading dependencies
- NodeJS 12 is now the minimum supported version - NodeJS 12 is now the minimum supported version
###### [V4.0.0] ###### [V4.0.0]
Bringing back Immoscout :tada: Bringing back Immoscout :tada:
###### [V3.0.0] ###### [V3.0.0]
This is basically a re-write, your old config file will not be compatible anymore. Please re-created your search jobs This is basically a re-write, your old config file will not be compatible anymore. Please re-created your search jobs
on the new ui and use the values from your previous config file if needed. on the new ui and use the values from your previous config file if needed.
``` ```
- We're getting rid of manual config changes, Fredy, now ships with a UI so that it's easy for you to create and edit jobs - We're getting rid of manual config changes, Fredy, now ships with a UI so that it's easy for you to create and edit jobs
``` ```
###### [V2.0.0] ###### [V2.0.0]
``` ```
- Fredy can now run multiple search job on one instance - Fredy can now run multiple search job on one instance
- Changed lot's of the structure of Fredy to make this happen - Changed lot's of the structure of Fredy to make this happen

View File

@@ -2,8 +2,8 @@
If you want to contribute, please make sure you've executed the tests. If you want to contribute, please make sure you've executed the tests.
### How to write new provider? ### How to write new provider?
- create the provider filer under `/lib/provider` - create the provider filer under `/lib/provider`
- create a test under /test and make sure it is running successfully - create a test under /test and make sure it is running successfully
@@ -13,7 +13,7 @@ let appliedBlackList = [];
//normalize incoming values //normalize incoming values
function normalize(o) { function normalize(o) {
const id = parseInt(o.id.substring(o.id.indexOf('_') + 1, o.id.length)); const id = parseInt(o.id.substring(o.id.indexOf('_') + 1, o.id.length));
return Object.assign(o, { id }); return Object.assign(o, { id });
} }
@@ -27,7 +27,7 @@ function applyBlacklist(o) {
const config = { const config = {
url: null, url: null,
//this is the container wrapping the search listings //this is the container wrapping the search listings
crawlContainer: '#result-list-stage .item', crawlContainer: '#result-list-stage .item',
crawlFields: { crawlFields: {
id: '@id', id: '@id',
@@ -49,7 +49,7 @@ exports.init = (sourceConfig, blacklist) => {
appliedBlackList = blacklist || []; appliedBlackList = blacklist || [];
}; };
//ths //ths
exports.metaInformation = { exports.metaInformation = {
name: 'your provider name', name: 'your provider name',
baseUrl: 'https://www.yourprovider.de/', baseUrl: 'https://www.yourprovider.de/',
@@ -57,11 +57,10 @@ exports.metaInformation = {
}; };
exports.config = config; exports.config = config;
``` ```
### How to write new notification adapter? ### How to write new notification adapter?
- create the provider filer under `/lib/notification/adapter` - create the provider filer under `/lib/notification/adapter`
- create a description of the provider under `/lib/notification/adapter/*.md`. Make sure the name of the md file is equal to the notification adapter - create a description of the provider under `/lib/notification/adapter/*.md`. Make sure the name of the md file is equal to the notification adapter
@@ -72,43 +71,43 @@ const Slack = require('slack');
const msg = Slack.chat.postMessage; const msg = Slack.chat.postMessage;
const { markdown2Html } = require('../../services/markdown'); const { markdown2Html } = require('../../services/markdown');
//as a parameter, you will always get the serviceName, newListings and all the values, that //as a parameter, you will always get the serviceName, newListings and all the values, that
//you have defined exports.config.fields. (This is being used for rendering in the frontend) //you have defined exports.config.fields. (This is being used for rendering in the frontend)
exports.send = ({ serviceName, newListings, notificationConfig, jobKey }) => { exports.send = ({ serviceName, newListings, notificationConfig, jobKey }) => {
const { token, channel } = notificationConfig.find((adapter) => adapter.id === 'slack').fields; const { token, channel } = notificationConfig.find((adapter) => adapter.id === 'slack').fields;
return newListings.map((payload) => { return newListings.map((payload) => {
//tho whatever needs to be done to send the data to the receiver, make sure the format is human readable //tho whatever needs to be done to send the data to the receiver, make sure the format is human readable
}); });
}; };
exports.config = { exports.config = {
id: __filename.slice(__dirname.length + 1, -3), id: __filename.slice(__dirname.length + 1, -3),
name: 'someUniqueName, used in the frontend', name: 'someUniqueName, used in the frontend',
//this readme is rendered in the frontend to explain how to use this //this readme is rendered in the frontend to explain how to use this
readme: markdown2Html('lib/notification/adapter/slack.md'), readme: markdown2Html('lib/notification/adapter/slack.md'),
description: 'Some description text rendered on the notification page', description: 'Some description text rendered on the notification page',
fields: { fields: {
token: { token: {
//type can be text/number/boolean //type can be text/number/boolean
type: 'text', type: 'text',
label: 'Token', label: 'Token',
description: 'The token needed to send notifications to slack.', description: 'The token needed to send notifications to slack.',
},
channel: {
type: 'channel',
label: 'Channel',
description: 'The channel where fredy should send notifications to.',
},
}, },
channel: {
type: 'channel',
label: 'Channel',
description: 'The channel where fredy should send notifications to.',
},
},
}; };
``` ```
#### Running Tests #### Running Tests
If you've written a new provider you are an awesome person. If you now write tests for it, you are even more awesome. And who doesn't want to be more awesome, right? If you've written a new provider you are an awesome person. If you now write tests for it, you are even more awesome. And who doesn't want to be more awesome, right?
#### Codestyle #### Codestyle
I'm using ESLint to maintain quote style and quality. Do not skip it... I'm using ESLint to maintain quote style and quality. Do not skip it...
##### To-do before merging: ##### To-do before merging:

View File

@@ -1,14 +1,15 @@
<img src="https://github.com/orangecoding/fredy/blob/master/doc/logo.png" width="400"> <img src="https://github.com/orangecoding/fredy/blob/master/doc/logo.png" width="400">
![Test](https://github.com/orangecoding/fredy/actions/workflows/test.yml/badge.svg) [![Create and publish Docker image](https://github.com/orangecoding/fredy/actions/workflows/docker.yml/badge.svg)](https://github.com/orangecoding/fredy/actions/workflows/docker.yml) ![Check the sourcecode](https://github.com/orangecoding/fredy/actions/workflows/check_source.yml/badge.svg) ![Test](https://github.com/orangecoding/fredy/actions/workflows/test.yml/badge.svg) [![Create and publish Docker image](https://github.com/orangecoding/fredy/actions/workflows/docker.yml/badge.svg)](https://github.com/orangecoding/fredy/actions/workflows/docker.yml) ![Check the sourcecode](https://github.com/orangecoding/fredy/actions/workflows/check_source.yml/badge.svg)
Searching an apartment in Germany can be a frustrating task. Not any longer though, as _Fredy_ will take over and will only notify you once new listings have been found that match your requirements. Searching an apartment in Germany can be a frustrating task. Not any longer though, as _Fredy_ will take over and will only notify you once new listings have been found that match your requirements.
_Fredy_ scrapes multiple services (Immonet, Immowelt etc.) and send new listings to you once they become available. The list of available services can easily be extended. For your convenience, _Fredy_ has a UI to help you configure your search jobs. _Fredy_ scrapes multiple services (Immonet, Immowelt etc.) and send new listings to you once they become available. The list of available services can easily be extended. For your convenience, _Fredy_ has a UI to help you configure your search jobs.
If _Fredy_ finds matching results, it will send them to you via Slack, Email, Telegram etc. (More adapters can be configured.) As _Fredy_ stores the listings it has found, new results will not be sent to you twice (and as a side-effect, _Fredy_ can show some statistics). Furthermore, _Fredy_ checks duplicates per scraping so that the same listings are not being sent twice or more when posted on various platforms (which happens more often than one might think). If _Fredy_ finds matching results, it will send them to you via Slack, Email, Telegram etc. (More adapters can be configured.) As _Fredy_ stores the listings it has found, new results will not be sent to you twice (and as a side-effect, _Fredy_ can show some statistics). Furthermore, _Fredy_ checks duplicates per scraping so that the same listings are not being sent twice or more when posted on various platforms (which happens more often than one might think).
# Sponsorship [![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/orangecoding) # Sponsorship [![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/orangecoding)
If you like my work, consider becoming a sponsor. I'm not expecting anybody to pay for _Fredy_ or any other Open Source Project I'm maintaining, however keep in mind, I'm doing all of this in my spare time :) Thanks. If you like my work, consider becoming a sponsor. I'm not expecting anybody to pay for _Fredy_ or any other Open Source Project I'm maintaining, however keep in mind, I'm doing all of this in my spare time :) Thanks.
[![JetBrains logo.](https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.svg)](https://jb.gg/OpenSourceSupport) [![JetBrains logo.](https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.svg)](https://jb.gg/OpenSourceSupport)
@@ -16,17 +17,20 @@ If you like my work, consider becoming a sponsor. I'm not expecting anybody to p
_Fredy_ is supported by JetBrains under Open Source Support Program _Fredy_ is supported by JetBrains under Open Source Support Program
## Demo ## Demo
If you want to try out _Fredy_, you can access the demo version [here](https://fredy.orange-coding.net) 🤘 If you want to try out _Fredy_, you can access the demo version [here](https://fredy.orange-coding.net) 🤘
## Usage ## Usage
- Make sure to use Node.js 20 or above - Make sure to use Node.js 20 or above
- Run the following commands: - Run the following commands:
```ssh ```ssh
yarn yarn
yarn run start:backend yarn run start:backend
yarn run start:frontend yarn run start:frontend
``` ```
_Fredy_ will start with the default port, set to `9998`. You can access _Fredy_ by opening your browser at `http://localhost:9998`. The default login is `admin`, both for username and password. You should change the password as soon as possible when you plan to run Fredy on a server. _Fredy_ will start with the default port, set to `9998`. You can access _Fredy_ by opening your browser at `http://localhost:9998`. The default login is `admin`, both for username and password. You should change the password as soon as possible when you plan to run Fredy on a server.
<p align="center"> <p align="center">
@@ -38,62 +42,79 @@ _Fredy_ will start with the default port, set to `9998`. You can access _Fredy_
</p> </p>
## Understanding the fundamentals ## Understanding the fundamentals
There are 3 important parts in Fredy, that you need to understand to leverage the full power of _Fredy_. There are 3 important parts in Fredy, that you need to understand to leverage the full power of _Fredy_.
#### Provider #### Provider
_Fredy_ supports multiple services. Immonet, Immowelt and Ebay are just a few examples. Those services are called providers within _Fredy_. When creating a new job, you can choose one or more providers. _Fredy_ supports multiple services. Immonet, Immowelt and Ebay are just a few examples. Those services are called providers within _Fredy_. When creating a new job, you can choose one or more providers.
A provider contains the URL that points to the search results for the respective service. If you go to immonet.de and search for something, the displayed URL in the browser is what the provider needs to do its magic. A provider contains the URL that points to the search results for the respective service. If you go to immonet.de and search for something, the displayed URL in the browser is what the provider needs to do its magic.
**It is important that you order the search results by date, so that _Fredy_ always picks the latest results first!** **It is important that you order the search results by date, so that _Fredy_ always picks the latest results first!**
#### Adapter #### Adapter
_Fredy_ supports multiple adapters, such as Slack, SendGrid, Telegram etc. A search job can have as many adapters as supported by _Fredy_. Each adapter needs different configuration values, which you have to provide when using them. An adapter dictates how the frontend renders by telling the frontend what information it needs in order to send listings to the user. _Fredy_ supports multiple adapters, such as Slack, SendGrid, Telegram etc. A search job can have as many adapters as supported by _Fredy_. Each adapter needs different configuration values, which you have to provide when using them. An adapter dictates how the frontend renders by telling the frontend what information it needs in order to send listings to the user.
#### Jobs #### Jobs
A Job wraps adapters and providers. _Fredy_ runs the configured jobs in a specific interval (can be configured in `/conf/config.json`). A Job wraps adapters and providers. _Fredy_ runs the configured jobs in a specific interval (can be configured in `/conf/config.json`).
## Creating your first job ## Creating your first job
To create your first job, click on the button "Create New Job" on the job table. The job creation dialog should be self-explanatory, however there is one important thing. To create your first job, click on the button "Create New Job" on the job table. The job creation dialog should be self-explanatory, however there is one important thing.
When configuring providers, before copying the URL from your browser, make sure that you have sorted the results by date to make sure _Fredy_ always picks the latest results first. When configuring providers, before copying the URL from your browser, make sure that you have sorted the results by date to make sure _Fredy_ always picks the latest results first.
## User management ## User management
As an administrator, you can create, edit and remove users from _Fredy_. Be careful, each job is connected to the user that has created the job. If you remove the user, their jobs will also be removed. As an administrator, you can create, edit and remove users from _Fredy_. Be careful, each job is connected to the user that has created the job. If you remove the user, their jobs will also be removed.
# Development # Development
### Running Fredy in development mode ### Running Fredy in development mode
Start the backend with: Start the backend with:
```shell ```shell
yarn run start:backend:dev yarn run start:backend:dev
``` ```
For the frontend, run: For the frontend, run:
```shell ```shell
yarn run start:frontend:dev yarn run start:frontend:dev
``` ```
You should now be able to access _Fredy_ from your browser. Check your Terminal to see what port the frontend is running on. You should now be able to access _Fredy_ from your browser. Check your Terminal to see what port the frontend is running on.
### Running Tests ### Running Tests
To run the tests, run To run the tests, run
```shell ```shell
yarn run test yarn run test
``` ```
# Architecture # Architecture
![Architecture](/doc/architecture.jpg "Architecture")
![Architecture](/doc/architecture.jpg 'Architecture')
### Immoscout ### Immoscout
Immoscout has implemented advanced bot detection. In order to work around this, we are using a reversed engineered version of their mobile api. See [Immoscout Reverse Engineering Documentation](https://github.com/orangecoding/fredy/blob/master/reverse-engineered-immoscout.md) Immoscout has implemented advanced bot detection. In order to work around this, we are using a reversed engineered version of their mobile api. See [Immoscout Reverse Engineering Documentation](https://github.com/orangecoding/fredy/blob/master/reverse-engineered-immoscout.md)
# Analytics # Analytics
Fredy is completely free (and will always remain free). However, it would be a huge help if youd allow me to collect some analytical data.
Before you freak out, let me explain... Fredy is completely free (and will always remain free). However, it would be a huge help if youd allow me to collect some analytical data.
If you agree, Fredy will send a ping to my Mixpanel project each time it runs. Before you freak out, let me explain...
If you agree, Fredy will send a ping to my Mixpanel project each time it runs.
The data includes: names of active adapters/providers, OS, architecture, Node version, and language. The information is entirely anonymous and helps me understand which adapters/providers are most frequently used.</p> The data includes: names of active adapters/providers, OS, architecture, Node version, and language. The information is entirely anonymous and helps me understand which adapters/providers are most frequently used.</p>
**Thanks**🤘 **Thanks**🤘
# Docker # Docker
Use the Dockerfile in this repository to build an image.
Example: `docker build -t fredy/fredy /path/to/your/Dockerfile` Use the Dockerfile in this repository to build an image.
Example: `docker build -t fredy/fredy /path/to/your/Dockerfile`
Or use docker-compose: Or use docker-compose:
@@ -103,17 +124,18 @@ Or use the container that will be built automatically.
`docker pull ghcr.io/orangecoding/fredy:master` `docker pull ghcr.io/orangecoding/fredy:master`
## Create & run a container ## Create & run a container
Put your config.json into a path of your choice, such as `/path/to/your/conf/`. Put your config.json into a path of your choice, such as `/path/to/your/conf/`.
Example: `docker create --name fredy -v /path/to/your/conf/:/conf -p 9998:9998 fredy/fredy` Example: `docker create --name fredy -v /path/to/your/conf/:/conf -p 9998:9998 fredy/fredy`
## Logs ## Logs
You can browse the logs with `docker logs fredy -f`. You can browse the logs with `docker logs fredy -f`.
### 👐 Contributing ### 👐 Contributing
Thanks to all the people who already contributed! Thanks to all the people who already contributed!
<a href="https://github.com/orangecoding/fredy/graphs/contributors"> <a href="https://github.com/orangecoding/fredy/graphs/contributors">
@@ -122,7 +144,6 @@ Thanks to all the people who already contributed!
See [Contributing](https://github.com/orangecoding/fredy/blob/master/CONTRIBUTING.md) See [Contributing](https://github.com/orangecoding/fredy/blob/master/CONTRIBUTING.md)
## Star History ## Star History
[![Star History Chart](https://api.star-history.com/svg?repos=orangecoding/fredy&type=Date)](https://www.star-history.com/#orangecoding/fredy&Date) [![Star History Chart](https://api.star-history.com/svg?repos=orangecoding/fredy&type=Date)](https://www.star-history.com/#orangecoding/fredy&Date)

View File

@@ -1 +1,7 @@
{"interval":"60","port":9998,"workingHours":{"from":"","to":""},"demoMode":false,"analyticsEnabled":null} {
"interval": "60",
"port": 9998,
"workingHours": { "from": "", "to": "" },
"demoMode": false,
"analyticsEnabled": null
}

View File

@@ -1,4 +1,3 @@
version: '3.8'
services: services:
fredy: fredy:
container_name: fredy container_name: fredy
@@ -12,5 +11,5 @@ services:
- ./conf:/conf - ./conf:/conf
- ./db:/db - ./db:/db
ports: ports:
- 9998:9998 - 9998:9998
restart: unless-stopped restart: unless-stopped

View File

@@ -1,16 +1,17 @@
<!DOCTYPE html> <!doctype html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" <meta
name="viewport" charset="UTF-8"
content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"> name="viewport"
<meta name="google" content="notranslate"> content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"
/>
<meta name="google" content="notranslate" />
<title>Fredy</title> <title>Fredy</title>
</head> </head>
<body theme-mode="dark"> <body theme-mode="dark">
<div id="fredy" style="position: absolute; top: 0; left: 0; right: 0; bottom: 0"></div>
<div id="fredy" style="position: absolute;top: 0;left: 0;right: 0;bottom: 0;"></div> </body>
</body> <script type="module" src="/ui/src/Index.jsx"></script>
<script type="module" src="/ui/src/Index.jsx"></script> </html>
</html>

View File

@@ -1,10 +1,10 @@
import restana from 'restana'; import restana from 'restana';
import {config} from '../../utils.js'; import { config } from '../../utils.js';
const service = restana(); const service = restana();
const demoRouter = service.newRouter(); const demoRouter = service.newRouter();
demoRouter.get('/', async (req, res) => { demoRouter.get('/', async (req, res) => {
res.body = Object.assign({}, {demoMode: config.demoMode}); res.body = Object.assign({}, { demoMode: config.demoMode });
res.send(); res.send();
}); });

View File

@@ -1,7 +1,7 @@
import restana from 'restana'; import restana from 'restana';
import {config, getDirName, readConfigFromStorage, refreshConfig} from '../../utils.js'; import { config, getDirName, readConfigFromStorage, refreshConfig } from '../../utils.js';
import fs from 'fs'; import fs from 'fs';
import {handleDemoUser} from '../../services/storage/userStorage.js'; import { handleDemoUser } from '../../services/storage/userStorage.js';
const service = restana(); const service = restana();
const generalSettingsRouter = service.newRouter(); const generalSettingsRouter = service.newRouter();
generalSettingsRouter.get('/', async (req, res) => { generalSettingsRouter.get('/', async (req, res) => {
@@ -11,12 +11,12 @@ generalSettingsRouter.get('/', async (req, res) => {
generalSettingsRouter.post('/', async (req, res) => { generalSettingsRouter.post('/', async (req, res) => {
const settings = req.body; const settings = req.body;
try { try {
if(config.demoMode){ if (config.demoMode) {
res.send(new Error('In demo mode, it is not allowed to change these settings.')); res.send(new Error('In demo mode, it is not allowed to change these settings.'));
return; return;
} }
const currentConfig = await readConfigFromStorage(); const currentConfig = await readConfigFromStorage();
fs.writeFileSync(`${getDirName()}/../conf/config.json`, JSON.stringify({...currentConfig, ...settings})); fs.writeFileSync(`${getDirName()}/../conf/config.json`, JSON.stringify({ ...currentConfig, ...settings }));
await refreshConfig(); await refreshConfig();
handleDemoUser(); handleDemoUser();
} catch (err) { } catch (err) {

View File

@@ -1,8 +1,8 @@
import restana from 'restana'; import restana from 'restana';
import * as userStorage from '../../services/storage/userStorage.js'; import * as userStorage from '../../services/storage/userStorage.js';
import * as hasher from '../../services/security/hash.js'; import * as hasher from '../../services/security/hash.js';
import {config} from '../../utils.js'; import { config } from '../../utils.js';
import {trackDemoAccessed} from '../../services/tracking/Tracker.js'; import { trackDemoAccessed } from '../../services/tracking/Tracker.js';
const service = restana(); const service = restana();
const loginRouter = service.newRouter(); const loginRouter = service.newRouter();
loginRouter.get('/user', async (req, res) => { loginRouter.get('/user', async (req, res) => {
@@ -26,8 +26,7 @@ loginRouter.post('/', async (req, res) => {
return; return;
} }
if (user.password === hasher.hash(password)) { if (user.password === hasher.hash(password)) {
if (config.demoMode) {
if(config.demoMode){
trackDemoAccessed(); trackDemoAccessed();
} }

View File

@@ -6,7 +6,7 @@ const notificationAdapterList = fs.readdirSync('./lib//notification/adapter').fi
const notificationAdapter = await Promise.all( const notificationAdapter = await Promise.all(
notificationAdapterList.map(async (pro) => { notificationAdapterList.map(async (pro) => {
return await import(`../../notification/adapter/${pro}`); return await import(`../../notification/adapter/${pro}`);
}) }),
); );
notificationAdapterRouter.post('/try', async (req, res) => { notificationAdapterRouter.post('/try', async (req, res) => {
const { id, fields } = req.body; const { id, fields } = req.body;

View File

@@ -6,7 +6,7 @@ const providerList = fs.readdirSync('./lib/provider').filter((file) => file.ends
const provider = await Promise.all( const provider = await Promise.all(
providerList.map(async (pro) => { providerList.map(async (pro) => {
return await import(`../../provider/${pro}`); return await import(`../../provider/${pro}`);
}) }),
); );
providerRouter.get('/', async (req, res) => { providerRouter.get('/', async (req, res) => {
res.body = provider.map((p) => p.metaInformation); res.body = provider.map((p) => p.metaInformation);

View File

@@ -1,7 +1,7 @@
import restana from 'restana'; import restana from 'restana';
import * as userStorage from '../../services/storage/userStorage.js'; import * as userStorage from '../../services/storage/userStorage.js';
import * as jobStorage from '../../services/storage/jobStorage.js'; import * as jobStorage from '../../services/storage/jobStorage.js';
import {config} from '../../utils.js'; import { config } from '../../utils.js';
const service = restana(); const service = restana();
const userRouter = service.newRouter(); const userRouter = service.newRouter();
function checkIfAnyAdminAfterRemovingUser(userIdToBeRemoved, allUser) { function checkIfAnyAdminAfterRemovingUser(userIdToBeRemoved, allUser) {
@@ -21,7 +21,7 @@ userRouter.get('/:userId', async (req, res) => {
res.send(); res.send();
}); });
userRouter.delete('/', async (req, res) => { userRouter.delete('/', async (req, res) => {
if(config.demoMode){ if (config.demoMode) {
res.send(new Error('In demo mode, it is not allowed to remove user.')); res.send(new Error('In demo mode, it is not allowed to remove user.'));
return; return;
} }
@@ -42,10 +42,9 @@ userRouter.delete('/', async (req, res) => {
res.send(); res.send();
}); });
userRouter.post('/', async (req, res) => { userRouter.post('/', async (req, res) => {
if (config.demoMode) {
if(config.demoMode){ res.send(new Error('In demo mode, it is not allowed to change or add user.'));
res.send(new Error('In demo mode, it is not allowed to change or add user.')); return;
return;
} }
const { username, password, password2, isAdmin, userId } = req.body; const { username, password, password2, isAdmin, userId } = req.body;
@@ -60,7 +59,7 @@ userRouter.post('/', async (req, res) => {
const allUser = userStorage.getUsers(false); const allUser = userStorage.getUsers(false);
if (!isAdmin && !checkIfAnyAdminAfterRemovingUser(userId, allUser)) { if (!isAdmin && !checkIfAnyAdminAfterRemovingUser(userId, allUser)) {
res.send( res.send(
new Error('You cannot change the admin flag for this user as otherwise, there is no other user in the system') new Error('You cannot change the admin flag for this user as otherwise, there is no other user in the system'),
); );
return; return;
} }

View File

@@ -1,7 +1,7 @@
export const DEFAULT_CONFIG = { export const DEFAULT_CONFIG = {
'interval': '60', interval: '60',
'port': 9998, port: 9998,
'workingHours': {'from': '', 'to': ''}, workingHours: { from: '', to: '' },
'demoMode': false, demoMode: false,
'analyticsEnabled': null analyticsEnabled: null,
}; };

View File

@@ -1,4 +1,4 @@
### Console Adapter ### Console Adapter
The console adapter prints everything found by Fredy into the console (not sending any notifications to you). This can be useful when you want to check if your search The console adapter prints everything found by Fredy into the console (not sending any notifications to you). This can be useful when you want to check if your search
criteria meet the expectations. criteria meet the expectations.

View File

@@ -1,8 +1,8 @@
### MailJet Adapter ### MailJet Adapter
To use [MailJet](https://mailjet.com), you need to create an account. You'll need to decided from which email address you want Fredy to send from. To use [MailJet](https://mailjet.com), you need to create an account. You'll need to decided from which email address you want Fredy to send from.
E.g. if you use yourGmailAccount@gmail.com, you have to add this to MailJet and verify it as well. E.g. if you use yourGmailAccount@gmail.com, you have to add this to MailJet and verify it as well.
The given public/private api keys are needed in order to use MailJet with Fredy. Fredy will use the same template, it is using for SendGrid. The given public/private api keys are needed in order to use MailJet with Fredy. Fredy will use the same template, it is using for SendGrid.
If this email should be sent to multiple receiver use a comma separator (some@email.com, someOther@email.com). If this email should be sent to multiple receiver use a comma separator (some@email.com, someOther@email.com).

View File

@@ -1,5 +1,5 @@
### Mattermost Adapter ### Mattermost Adapter
For Mattermost, you need to create a incoming webhook. This is pretty easy. Please visit the steps in the [developer docs](https://docs.mattermost.com/developer/webhooks-incoming.html) and follow the instructions. For Mattermost, you need to create a incoming webhook. This is pretty easy. Please visit the steps in the [developer docs](https://docs.mattermost.com/developer/webhooks-incoming.html) and follow the instructions.
As a result, you get the webhook URL for configuration in fredy. In addition, the target channel must be defined. As a result, you get the webhook URL for configuration in fredy. In addition, the target channel must be defined.

View File

@@ -1,5 +1,5 @@
### ntfy Adapter ### ntfy Adapter
For ntfy, you need to create a topic on your preferred ntfy instance. This is pretty easy. Please visit the steps in the [docs](https://docs.ntfy.sh/publish/) and follow the instructions. For ntfy, you need to create a topic on your preferred ntfy instance. This is pretty easy. Please visit the steps in the [docs](https://docs.ntfy.sh/publish/) and follow the instructions.
As a result, you get the URL for configuration in fredy. In addition, the priority must be defined. As a result, you get the URL for configuration in fredy. In addition, the priority must be defined.

View File

@@ -1,73 +1,74 @@
import {markdown2Html} from '../../services/markdown.js'; import { markdown2Html } from '../../services/markdown.js';
import {getJob} from '../../services/storage/jobStorage.js'; import { getJob } from '../../services/storage/jobStorage.js';
import fetch from 'node-fetch'; import fetch from 'node-fetch';
export const send = ({serviceName, newListings, notificationConfig, jobKey}) => { export const send = ({ serviceName, newListings, notificationConfig, jobKey }) => {
const {token, user, device} = notificationConfig.find((adapter) => adapter.id === config.id).fields; const { token, user, device } = notificationConfig.find((adapter) => adapter.id === config.id).fields;
const job = getJob(jobKey); const job = getJob(jobKey);
const jobName = job == null ? jobKey : job.name; const jobName = job == null ? jobKey : job.name;
const promises = newListings.map((newListing) => { const promises = newListings.map((newListing) => {
const title = `${jobName} at ${serviceName}: ${newListing.title}`; const title = `${jobName} at ${serviceName}: ${newListing.title}`;
const message = `Address: ${newListing.address}\nSize: ${newListing.size}\nPrice: ${newListing.price}\nLink: ${newListing.link}`; const message = `Address: ${newListing.address}\nSize: ${newListing.size}\nPrice: ${newListing.price}\nLink: ${newListing.link}`;
return fetch('https://api.pushover.net/1/messages.json', { return fetch('https://api.pushover.net/1/messages.json', {
method: 'POST', method: 'POST',
headers: {'Content-Type': 'application/json'}, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ body: JSON.stringify({
token: token, token: token,
user: user, user: user,
message: message, message: message,
device: device, device: device,
title: title, title: title,
}), }),
});
}); });
});
return Promise.all(promises) return Promise.all(promises)
.then((responses) => { .then((responses) => {
// Convert all responses to JSON // Convert all responses to JSON
return Promise.all(responses.map((response) => response.json())); return Promise.all(responses.map((response) => response.json()));
}) })
.then((data) => { .then((data) => {
// Check for errors in the data // Check for errors in the data
const error = data const error = data
.map((item) => (item.errors != null && item.errors.length > 0 ? item.errors.join(', ') : null)) .map((item) => (item.errors != null && item.errors.length > 0 ? item.errors.join(', ') : null))
.filter((err) => err !== null); .filter((err) => err !== null);
if (error.length > 0) { if (error.length > 0) {
// Reject with the combined error messages // Reject with the combined error messages
return Promise.reject(error.join('; ')); return Promise.reject(error.join('; '));
} }
return data; return data;
}) })
.then(() => { .then(() => {
return Promise.resolve(); return Promise.resolve();
}) })
.catch((error) => { .catch((error) => {
return Promise.reject(error); return Promise.reject(error);
}); });
}; };
export const config = { export const config = {
id: 'pushover', id: 'pushover',
name: 'Pushover', name: 'Pushover',
readme: markdown2Html('lib/notification/adapter/pushover.md'), readme: markdown2Html('lib/notification/adapter/pushover.md'),
description: 'Fredy will send new listings to your mobile using Pushover.', description: 'Fredy will send new listings to your mobile using Pushover.',
fields: { fields: {
token: { token: {
type: 'text', type: 'text',
label: 'API token', label: 'API token',
description: 'Your application\'s API token.', description: "Your application's API token.",
},
user: {
type: 'text',
label: 'User key',
description: 'Your user/group key.',
},
device: {
type: 'text',
label: 'Device name',
description: 'The device name to send your notification to. Messages may be addressed to multiple specific devices by joining them with a comma.',
},
}, },
user: {
type: 'text',
label: 'User key',
description: 'Your user/group key.',
},
device: {
type: 'text',
label: 'Device name',
description:
'The device name to send your notification to. Messages may be addressed to multiple specific devices by joining them with a comma.',
},
},
}; };

View File

@@ -2,4 +2,4 @@
Refer to the [instructions](https://support.pushover.net/i7-what-is-pushover-and-how-do-i-use-it) to set up your Pushover application. Refer to the [instructions](https://support.pushover.net/i7-what-is-pushover-and-how-do-i-use-it) to set up your Pushover application.
After setting up the application, please enter both your newly created User key and API token. After setting up the application, please enter both your newly created User key and API token.

View File

@@ -1,9 +1,8 @@
### SendGrid Adapter ### SendGrid Adapter
SendGrid is a free email service (free as in "you cannot send more than 100(Sendgrid) and 200(Mailjet) emails a day"), which is more than enough for Fredy. SendGrid is a free email service (free as in "you cannot send more than 100(Sendgrid) and 200(Mailjet) emails a day"), which is more than enough for Fredy.
To use [SendGrid](https://sendgrid.com/), you need to create an account. You'll need to decided from which email address you want Fredy to send from. E.g. if you use yourGmailAccount@gmail.com, you have to add this to sendgrid and verify it as well. To use [SendGrid](https://sendgrid.com/), you need to create an account. You'll need to decided from which email address you want Fredy to send from. E.g. if you use yourGmailAccount@gmail.com, you have to add this to sendgrid and verify it as well.
Lastly you have to create an api-key and feed it into Fredy's config, as well as creating a new dynamic template. For this new template, I recommend copying and pasting the code from the one I have provided under `/lib/notification/emailTemplate/template.hbs`. Lastly you have to create an api-key and feed it into Fredy's config, as well as creating a new dynamic template. For this new template, I recommend copying and pasting the code from the one I have provided under `/lib/notification/emailTemplate/template.hbs`.

View File

@@ -1,6 +1,5 @@
### Slack Adapter ### Slack Adapter
In order to use [Slack](https://slack.com), you need to create an account. When done, you need to create a new App in your workspace. Give it the permission `chat:write:bot` and `chat:write:user`.
In order to use [Slack](https://slack.com), you need to create an account. When done, you need to create a new App in your workspace. Give it the permission `chat:write:bot` and `chat:write:user`.
Now you need to create a user token and a channel. Make sure the bot is installed to this channel.
Now you need to create a user token and a channel. Make sure the bot is installed to this channel.

View File

@@ -1,7 +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 a sqlite database located in db/listings.db. This file can be used for further analysis later on.
Fields are: Fields are:
``` ```
['serviceName', 'jobKey', 'id', 'size', 'rooms', 'price', 'address', 'title', 'link', 'description'] ['serviceName', 'jobKey', 'id', 'size', 'rooms', 'price', 'address', 'title', 'link', 'description']
``` ```

View File

@@ -28,11 +28,13 @@ export const send = ({ serviceName, newListings, notificationConfig, jobKey }) =
const messageParagraphs = []; const messageParagraphs = [];
messageParagraphs.push(`<i>${jobName}</i> (${serviceName}) found <b>${newListings.length}</b> new listings:`); messageParagraphs.push(`<i>${jobName}</i> (${serviceName}) found <b>${newListings.length}</b> new listings:`);
messageParagraphs.push(...chunk.map( messageParagraphs.push(
(o) => ...chunk.map(
`<a href='${o.link}'><b>${shorten(o.title.replace(/\*/g, ''), 45).trim()}</b></a>\n` + (o) =>
[o.address, o.price, o.size].join(' | ') `<a href='${o.link}'><b>${shorten(o.title.replace(/\*/g, ''), 45).trim()}</b></a>\n` +
)); [o.address, o.price, o.size].join(' | '),
),
);
/** /**
* This is to not break the rate limit. It is to only send 1 message per second * This is to not break the rate limit. It is to only send 1 message per second

View File

@@ -1,13 +1,12 @@
### Telegram Adapter ### Telegram Adapter
For Telegram, you need to create a Bot. This is pretty easy. Open [this](https://telegram.me/BotFather) url on your smartphone and follow the instructions. For Telegram, you need to create a Bot. This is pretty easy. Open [this](https://telegram.me/BotFather) url on your smartphone and follow the instructions.
A telegram bot is not allowed to send messages directly to a user, you as a user need to first contact the bot to get a chatId.
After the user has send a message to your bot the first time, you can gather the chatId like this:
``` A telegram bot is not allowed to send messages directly to a user, you as a user need to first contact the bot to get a chatId.
curl -X GET https://api.telegram.org/bot{YOUR_TELEGRAM_TOKEN}/getUpdates After the user has send a message to your bot the first time, you can gather the chatId like this:
```
```
curl -X GET https://api.telegram.org/bot{YOUR_TELEGRAM_TOKEN}/getUpdates
```
A more detailed list of instructions can be found here [https://core.telegram.org/bots#botfather](https://core.telegram.org/bots#botfather) A more detailed list of instructions can be found here [https://core.telegram.org/bots#botfather](https://core.telegram.org/bots#botfather)

View File

@@ -1,90 +1,90 @@
import Mixpanel from 'mixpanel'; import Mixpanel from 'mixpanel';
import {getJobs} from '../storage/jobStorage.js'; import { getJobs } from '../storage/jobStorage.js';
import {getUniqueId} from './uniqueId.js'; import { getUniqueId } from './uniqueId.js';
import {config, inDevMode} from '../../utils.js'; import { config, inDevMode } from '../../utils.js';
import os from 'os'; import os from 'os';
import {readFileSync} from 'fs'; import { readFileSync } from 'fs';
import {packageUp} from 'package-up'; import { packageUp } from 'package-up';
const mixpanelTracker = Mixpanel.init('718670ef1c58c0208256c1e408a3d75e'); const mixpanelTracker = Mixpanel.init('718670ef1c58c0208256c1e408a3d75e');
const distinct_id = getUniqueId() || 'N/A'; const distinct_id = getUniqueId() || 'N/A';
const version = await getPackageVersion(); const version = await getPackageVersion();
export const track = function () { export const track = function () {
//only send tracking information if the user allowed to do so. //only send tracking information if the user allowed to do so.
if (config.analyticsEnabled && !inDevMode()) { if (config.analyticsEnabled && !inDevMode()) {
const activeProvider = new Set(); const activeProvider = new Set();
const activeAdapter = new Set(); const activeAdapter = new Set();
const jobs = getJobs(); const jobs = getJobs();
if (jobs != null && jobs.length > 0) { if (jobs != null && jobs.length > 0) {
jobs.forEach((job) => { jobs.forEach((job) => {
job.provider.forEach((provider) => { job.provider.forEach((provider) => {
activeProvider.add(provider.id); activeProvider.add(provider.id);
}); });
job.notificationAdapter.forEach((adapter) => { job.notificationAdapter.forEach((adapter) => {
activeAdapter.add(adapter.id); activeAdapter.add(adapter.id);
}); });
}); });
mixpanelTracker.track( mixpanelTracker.track(
'fredy_tracking', 'fredy_tracking',
enrichTrackingObject({ enrichTrackingObject({
adapter: Array.from(activeAdapter), adapter: Array.from(activeAdapter),
provider: Array.from(activeProvider), provider: Array.from(activeProvider),
}), }),
); );
}
} }
}
}; };
/** /**
* Note, this will only be used when Fredy runs in demo mode * Note, this will only be used when Fredy runs in demo mode
*/ */
export function trackDemoJobCreated(jobData) { export function trackDemoJobCreated(jobData) {
if (config.analyticsEnabled && !inDevMode() && config.demoMode) { if (config.analyticsEnabled && !inDevMode() && config.demoMode) {
mixpanelTracker.track('demoJobCreated', enrichTrackingObject(jobData)); mixpanelTracker.track('demoJobCreated', enrichTrackingObject(jobData));
} }
} }
/** /**
* Note, this will only be used when Fredy runs in demo mode * Note, this will only be used when Fredy runs in demo mode
*/ */
export function trackDemoAccessed() { export function trackDemoAccessed() {
if (config.analyticsEnabled && !inDevMode() && config.demoMode) { if (config.analyticsEnabled && !inDevMode() && config.demoMode) {
mixpanelTracker.track('demoAccessed', enrichTrackingObject({})); mixpanelTracker.track('demoAccessed', enrichTrackingObject({}));
} }
} }
function enrichTrackingObject(trackingObject) { function enrichTrackingObject(trackingObject) {
const operating_system = os.platform(); const operating_system = os.platform();
const os_version = os.release(); const os_version = os.release();
const arch = process.arch; const arch = process.arch;
const language = process.env.LANG || 'en'; const language = process.env.LANG || 'en';
const nodeVersion = process.version || 'N/A'; const nodeVersion = process.version || 'N/A';
return { return {
...trackingObject, ...trackingObject,
isDemo: config.demoMode, isDemo: config.demoMode,
operating_system, operating_system,
os_version, os_version,
arch, arch,
nodeVersion, nodeVersion,
language, language,
distinct_id, distinct_id,
fredy_version: version fredy_version: version,
}; };
} }
async function getPackageVersion() { async function getPackageVersion() {
try { try {
const packagePath = await packageUp(); const packagePath = await packageUp();
const packageJson = readFileSync(packagePath, 'utf8'); const packageJson = readFileSync(packagePath, 'utf8');
const json = JSON.parse(packageJson); const json = JSON.parse(packageJson);
return json.version; return json.version;
} catch (error) { } catch (error) {
console.error('Error reading version from package.json', error); console.error('Error reading version from package.json', error);
} }
return 'N/A'; return 'N/A';
} }

View File

@@ -1,88 +1,86 @@
import {dirname} from 'node:path'; import { dirname } from 'node:path';
import {fileURLToPath} from 'node:url'; import { fileURLToPath } from 'node:url';
import {readFile} from 'fs/promises'; import { readFile } from 'fs/promises';
import {createHash} from 'crypto'; import { createHash } from 'crypto';
import {DEFAULT_CONFIG} from './defaultConfig.js'; import { DEFAULT_CONFIG } from './defaultConfig.js';
function inDevMode(){ function inDevMode() {
return process.env.NODE_ENV == null || process.env.NODE_ENV !== 'production'; return process.env.NODE_ENV == null || process.env.NODE_ENV !== 'production';
} }
function isOneOf(word, arr) { function isOneOf(word, arr) {
if (!arr || arr.length === 0 || word == null) return false; if (!arr || arr.length === 0 || word == null) return false;
const lowerWord = word.toLowerCase(); const lowerWord = word.toLowerCase();
return arr.some(item => lowerWord.indexOf(item.toLowerCase()) !== -1); return arr.some((item) => lowerWord.indexOf(item.toLowerCase()) !== -1);
} }
function nullOrEmpty(val) { function nullOrEmpty(val) {
return val == null || val.length === 0; return val == null || val.length === 0;
} }
function timeStringToMs(timeString, now) { function timeStringToMs(timeString, now) {
const d = new Date(now); const d = new Date(now);
const parts = timeString.split(':'); const parts = timeString.split(':');
d.setHours(parts[0]); d.setHours(parts[0]);
d.setMinutes(parts[1]); d.setMinutes(parts[1]);
d.setSeconds(0); d.setSeconds(0);
return d.getTime(); return d.getTime();
} }
function duringWorkingHoursOrNotSet(config, now) { function duringWorkingHoursOrNotSet(config, now) {
const {workingHours} = config; const { workingHours } = config;
if (workingHours == null || nullOrEmpty(workingHours.from) || nullOrEmpty(workingHours.to)) { if (workingHours == null || nullOrEmpty(workingHours.from) || nullOrEmpty(workingHours.to)) {
return true; return true;
} }
const toDate = timeStringToMs(workingHours.to, now); const toDate = timeStringToMs(workingHours.to, now);
const fromDate = timeStringToMs(workingHours.from, now); const fromDate = timeStringToMs(workingHours.from, now);
return fromDate <= now && toDate >= now; return fromDate <= now && toDate >= now;
} }
function getDirName() { function getDirName() {
return dirname(fileURLToPath(import.meta.url)); return dirname(fileURLToPath(import.meta.url));
} }
function buildHash(...inputs) { function buildHash(...inputs) {
if (inputs == null) { if (inputs == null) {
return null; return null;
} }
const cleaned = inputs.filter(i => i != null && i.length > 0); const cleaned = inputs.filter((i) => i != null && i.length > 0);
if (cleaned.length === 0) { if (cleaned.length === 0) {
return null; return null;
} }
return createHash('sha256') return createHash('sha256').update(cleaned.join(',')).digest('hex');
.update(cleaned.join(','))
.digest('hex');
} }
let config = {}; let config = {};
export async function readConfigFromStorage(){ export async function readConfigFromStorage() {
return JSON.parse(await readFile(new URL('../conf/config.json', import.meta.url))); return JSON.parse(await readFile(new URL('../conf/config.json', import.meta.url)));
} }
export async function refreshConfig(){ export async function refreshConfig() {
try { try {
config = await readConfigFromStorage(); config = await readConfigFromStorage();
//backwards compatability... //backwards compatability...
config.analyticsEnabled ??= null; config.analyticsEnabled ??= null;
config.demoMode ??= false; config.demoMode ??= false;
} catch (error) { } catch (error) {
config = {...DEFAULT_CONFIG}; config = { ...DEFAULT_CONFIG };
console.error('Error reading config file', error); console.error('Error reading config file', error);
} }
} }
await refreshConfig(); await refreshConfig();
export {isOneOf}; export { isOneOf };
export {inDevMode}; export { inDevMode };
export {nullOrEmpty}; export { nullOrEmpty };
export {duringWorkingHoursOrNotSet}; export { duringWorkingHoursOrNotSet };
export {getDirName}; export { getDirName };
export {config}; export { config };
export {buildHash}; export { buildHash };
export default { export default {
isOneOf, isOneOf,
nullOrEmpty, nullOrEmpty,
duringWorkingHoursOrNotSet, duringWorkingHoursOrNotSet,
getDirName, getDirName,
config, config,
}; };

View File

@@ -9,10 +9,10 @@
"start:frontend": "vite -m production", "start:frontend": "vite -m production",
"start:frontend:dev": "vite", "start:frontend:dev": "vite",
"build:frontend": "vite build", "build:frontend": "vite build",
"format": "prettier --write lib/**/*.js ui/src/**/*.jsx test/**/*.js *.js", "format": "prettier --write .",
"format:check": "prettier --check lib/**/*.js ui/src/**/*.jsx test/**/*.js *.js", "format:check": "prettier --check .",
"test": "mocha --loader=esmock --timeout 3000000 test/**/*.test.js", "test": "mocha --loader=esmock --timeout 3000000 test/**/*.test.js",
"lint": "eslint index.js lib/**/*.js test/**/*.js ui/src/**/*.jsx", "lint": "eslint .",
"lint:fix": "yarn lint --fix" "lint:fix": "yarn lint --fix"
}, },
"type": "module", "type": "module",

View File

@@ -22,22 +22,24 @@ These protections make it extremely difficult to reliably extract data from Immo
To work around these limitations, we are in the progress of reverse-engineering Immoscout24's mobile API. The mobile applications need to communicate with Immoscout's servers to retrieve listing data, and these API endpoints typically have fewer anti-bot protections than the web interface. To work around these limitations, we are in the progress of reverse-engineering Immoscout24's mobile API. The mobile applications need to communicate with Immoscout's servers to retrieve listing data, and these API endpoints typically have fewer anti-bot protections than the web interface.
The mobile API provides several key endpoints: The mobile API provides several key endpoints:
- Search total endpoint: Returns the total number of listings for a given query - Search total endpoint: Returns the total number of listings for a given query
- Search list endpoint: Retrieves the actual listings with details - Search list endpoint: Retrieves the actual listings with details
- Expose endpoint: Returns detailed information about a specific listing - Expose endpoint: Returns detailed information about a specific listing
Challenges: Challenges:
1. Identifying the necessary endpoints and parameters required to perform searches 1. Identifying the necessary endpoints and parameters required to perform searches
2. Mapping the mobile API parameters to their web counterparts to maintain compatibility with existing search URLs 2. Mapping the mobile API parameters to their web counterparts to maintain compatibility with existing search URLs
## Api Specs ## Api Specs
#### Search for Listings #### Search for Listings
`GET /search/total?{search parameters}` `GET /search/total?{search parameters}`
*Returns the total number of listings for the given query.* _Returns the total number of listings for the given query._
``` ```
curl -H "User-Agent: ImmoScout24_1410_30_._" \ curl -H "User-Agent: ImmoScout24_1410_30_._" \
-H "Accept: application/json" \ -H "Accept: application/json" \
@@ -47,14 +49,17 @@ curl -H "User-Agent: ImmoScout24_1410_30_._" \
--- ---
#### Retrieve the listings #### Retrieve the listings
`POST /search/list?{search parameters}`
*The body is json encoded and contains data specifying additional results (advertisements) to return. The format is as follows (It is not necessary to provide data for the specified keys.)* `POST /search/list?{search parameters}`
``` _The body is json encoded and contains data specifying additional results (advertisements) to return. The format is as follows (It is not necessary to provide data for the specified keys.)_
{
"supportedResultListTypes": [], ```
"userData": {} {
} "supportedResultListTypes": [],
``` "userData": {}
}
```
``` ```
curl -X POST 'https://api.mobile.immobilienscout24.de/search/list?pricetype=calculatedtotalrent&realestatetype=apartmentrent&searchType=region&geocodes=%2Fde%2Fberlin%2Fberlin&pagenumber=1' \ curl -X POST 'https://api.mobile.immobilienscout24.de/search/list?pricetype=calculatedtotalrent&realestatetype=apartmentrent&searchType=region&geocodes=%2Fde%2Fberlin%2Fberlin&pagenumber=1' \
-H "Connection: keep-alive" \ -H "Connection: keep-alive" \
@@ -66,15 +71,18 @@ curl -X POST 'https://api.mobile.immobilienscout24.de/search/list?pricetype=calc
``` ```
--- ---
#### Get details of listings #### Get details of listings
`GET /expose/{id}` `GET /expose/{id}`
The response contains additional details not included in the listing response. The response contains additional details not included in the listing response.
``` ```
curl -H "User-Agent: ImmoScout24_1410_30_._" \ curl -H "User-Agent: ImmoScout24_1410_30_._" \
-H "Accept: application/json" \ -H "Accept: application/json" \
"https://api.mobile.immobilienscout24.de/expose/158382494" "https://api.mobile.immobilienscout24.de/expose/158382494"
``` ```
## Parameters
## Parameters
The parameters between web and mobile are very different which is why we have to translate them. Please see [/lib/services/immoscout/immoscout-web-translator.js](https://github.com/orangecoding/fredy/blob/master/lib/services/immoscout/immoscout-web-translator.js). The parameters between web and mobile are very different which is why we have to translate them. Please see [/lib/services/immoscout/immoscout-web-translator.js](https://github.com/orangecoding/fredy/blob/master/lib/services/immoscout/immoscout-web-translator.js).

View File

@@ -30,4 +30,4 @@
"shouldBecome": "https://www.immobilienscout24.de/Suche/de/nordrhein-westfalen/duesseldorf/wohnung-mieten?numberofrooms=1.5-&price=1.0-1000000.0&livingspace=1.0-10000.0&pricetype=rentpermonth&enteredFrom=result_list&sorting=-firstactivation", "shouldBecome": "https://www.immobilienscout24.de/Suche/de/nordrhein-westfalen/duesseldorf/wohnung-mieten?numberofrooms=1.5-&price=1.0-1000000.0&livingspace=1.0-10000.0&pricetype=rentpermonth&enteredFrom=result_list&sorting=-firstactivation",
"id": "immoscout" "id": "immoscout"
} }
] ]

View File

@@ -19,4 +19,4 @@
"url": "https://www.immobilienscout24.de/Suche/de/nordrhein-westfalen/duesseldorf/haus-mieten?enteredFrom=one_step_search", "url": "https://www.immobilienscout24.de/Suche/de/nordrhein-westfalen/duesseldorf/haus-mieten?enteredFrom=one_step_search",
"type": "houserent" "type": "houserent"
} }
} }

View File

@@ -1,7 +1,7 @@
.app { .app {
display:flex; display: flex;
flex-direction: column; flex-direction: column;
width:100%; width: 100%;
&__container { &__container {
padding: 1rem 1rem; padding: 1rem 1rem;
@@ -10,12 +10,13 @@
} }
} }
.ui.inverted.segment{ .ui.inverted.segment {
background: #31303078!important; background: #31303078 !important;
} }
.ui.black.label, .ui.black.labels .label { .ui.black.label,
background-color: #31303078!important; .ui.black.labels .label {
background-color: #31303078 !important;
} }
a:link { a:link {

View File

@@ -1,15 +1,16 @@
body, html { body,
html {
margin: 0; margin: 0;
height: 100%; height: 100%;
width: 100%; width: 100%;
background-color: #232429; background-color: #232429;
} }
.semi-table-row-head{ .semi-table-row-head {
background-color: #2b2b2b !important; background-color: #2b2b2b !important;
color: #fff !important; color: #fff !important;
} }
.semi-table-row-cell { .semi-table-row-cell {
background-color: #333333 !important; background-color: #333333 !important;
} }

View File

@@ -1,5 +1,5 @@
.logo { .logo {
position: absolute; position: absolute;
top: .1rem; top: 0.1rem;
right: 2rem; right: 2rem;
} }

View File

@@ -1,10 +1,10 @@
.place { .place {
height: 100%; height: 100%;
width: 100%; width: 100%;
display:flex; display: flex;
&__place_lines_wrapper{ &__place_lines_wrapper {
width:100%; width: 100%;
} }
&__line { &__line {
@@ -20,17 +20,16 @@
border-radius: 360px; border-radius: 360px;
animation: pulse 1s infinite ease-in-out; animation: pulse 1s infinite ease-in-out;
} }
} }
@keyframes pulse { @keyframes pulse {
0% { 0% {
background-color: rgba(165, 165, 165, 0.1) background-color: rgba(165, 165, 165, 0.1);
} }
50% { 50% {
background-color: rgba(165, 165, 165, 0.3) background-color: rgba(165, 165, 165, 0.3);
} }
100% { 100% {
background-color: rgba(165, 165, 165, 0.1) background-color: rgba(165, 165, 165, 0.1);
} }
} }

View File

@@ -1,4 +1,4 @@
.segmentParts { .segmentParts {
border: 1px solid #323232 !important; border: 1px solid #323232 !important;
border-radius: 5px !important; border-radius: 5px !important;
} }

View File

@@ -1,5 +1,5 @@
.trackingModal { .trackingModal {
&__description { &__description {
margin-top:10rem; margin-top: 10rem;
} }
} }

View File

@@ -1,4 +1,4 @@
export default function isDevelopmentMode(){ export default function isDevelopmentMode() {
const inDevMode= import.meta.env.MODE; const inDevMode = import.meta.env.MODE;
return inDevMode != null && inDevMode === 'development'; return inDevMode != null && inDevMode === 'development';
} }

View File

@@ -129,6 +129,6 @@ function parseJSON(response) {
}); });
} }
}) })
.catch((error) => reject('Error while trying to parse json.', error)) .catch((error) => reject('Error while trying to parse json.', error)),
); );
} }

View File

@@ -5,9 +5,8 @@
gap: 1rem; gap: 1rem;
} }
&__help{ &__help {
font-size: 11px; font-size: 11px;
margin-left: 1rem; margin-left: 1rem;
} }
} }

View File

@@ -1,7 +1,7 @@
.jobs { .jobs {
&__newButton{ &__newButton {
margin-top:1rem !important; margin-top: 1rem !important;
float: right; float: right;
margin-bottom: 1rem !important; margin-bottom: 1rem !important;
} }
} }

View File

@@ -1,5 +1,5 @@
.jobMutation { .jobMutation {
&__newButton{ &__newButton {
float: right; float: right;
margin-bottom: 1rem; margin-bottom: 1rem;
} }
@@ -7,4 +7,4 @@
.semi-select-option-list-wrapper { .semi-select-option-list-wrapper {
width: 25rem; width: 25rem;
} }

View File

@@ -1,6 +1,6 @@
.providerMutator { .providerMutator {
&__fields{ &__fields {
width:25rem !important; width: 25rem !important;
} }
&__helpBox { &__helpBox {
@@ -9,8 +9,8 @@
padding: 1rem !important; padding: 1rem !important;
} }
&__helpLink{ &__helpLink {
color: #4183c4; color: #4183c4;
cursor: pointer; cursor: pointer;
} }
} }

View File

@@ -1,5 +1,5 @@
.providerMutator { .providerMutator {
&__fields{ &__fields {
width:25rem !important; width: 25rem !important;
} }
} }

View File

@@ -1,7 +1,7 @@
.users { .users {
&__newButton{ &__newButton {
margin-top:1rem !important; margin-top: 1rem !important;
float: right; float: right;
margin-bottom: 1rem !important; margin-bottom: 1rem !important;
} }
} }

View File

@@ -1,3 +1,3 @@
.userMutator { .userMutator {
margin-top: 2rem ; margin-top: 2rem;
} }