37 lines
1002 B
JavaScript
37 lines
1002 B
JavaScript
// Konfigurationsklasse für AgrarmonitorLib
|
|
|
|
|
|
const { CookieJar } = require('tough-cookie');
|
|
const fs = require('fs');
|
|
|
|
class Config {
|
|
/**
|
|
* @param {Object} options
|
|
* @param {string} options.cookiePath - Pfad zum Cookie-Speicher
|
|
* @param {string} options.username - Benutzername
|
|
* @param {string} options.password - Passwort
|
|
* @param {string} options.baseUrl - Basis-URL für Agrarmonitor
|
|
*/
|
|
constructor({ cookiePath, username, password, baseUrl }) {
|
|
this.cookiePath = cookiePath;
|
|
this.username = username;
|
|
this.password = password;
|
|
this.baseUrl = baseUrl || 'https://admin7.agrarmonitor.de/';
|
|
this.cookieJar = this.loadCookieJar();
|
|
}
|
|
|
|
loadCookieJar() {
|
|
try {
|
|
if (fs.existsSync(this.cookiePath)) {
|
|
const data = fs.readFileSync(this.cookiePath, 'utf8');
|
|
return CookieJar.fromJSON(data);
|
|
}
|
|
} catch (e) {
|
|
// Fehler beim Laden, leere Jar zurückgeben
|
|
}
|
|
return new CookieJar();
|
|
}
|
|
}
|
|
|
|
module.exports = Config;
|