Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3bef26b332 | ||
|
|
94751c12ff | ||
|
|
a6eb41f996 |
@@ -96,8 +96,8 @@ async function buendleZugang(clientId, subs, label, zeitSuffix) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Bündelt alle offenen Datensätze (optional nur ein Zugang), gruppiert je Zugang. */
|
/** Bündelt alle offenen Datensätze (optional nur ein Zugang), gruppiert je Zugang. */
|
||||||
async function buendleAlle({ clientId = null, label, zeitSuffix = '' }) {
|
async function buendleAlle({ clientId = null, ids = null, label, zeitSuffix = '' }) {
|
||||||
const alle = await fetchBatchPending(clientId);
|
const alle = await fetchBatchPending(clientId, ids);
|
||||||
const proZugang = new Map();
|
const proZugang = new Map();
|
||||||
for (const s of alle) {
|
for (const s of alle) {
|
||||||
const k = String(s.api_client);
|
const k = String(s.api_client);
|
||||||
@@ -117,12 +117,13 @@ async function buendleAlle({ clientId = null, label, zeitSuffix = '' }) {
|
|||||||
async function buildBundles(req, res) {
|
async function buildBundles(req, res) {
|
||||||
try {
|
try {
|
||||||
const clientId = (req.body && req.body.client_id != null && String(req.body.client_id).trim()) ? String(req.body.client_id).trim() : null;
|
const clientId = (req.body && req.body.client_id != null && String(req.body.client_id).trim()) ? String(req.body.client_id).trim() : null;
|
||||||
|
const ids = (req.body && Array.isArray(req.body.ids) && req.body.ids.length) ? req.body.ids : null;
|
||||||
const label = (req.body && req.body.label) ? String(req.body.label) : berlinParts().date;
|
const label = (req.body && req.body.label) ? String(req.body.label) : berlinParts().date;
|
||||||
// Manuelle Bündelung mit Uhrzeit-Suffix, damit sie den Cron-Tageslauf (nur Datum) nicht überschreibt.
|
// Manuelle Bündelung mit Uhrzeit-Suffix, damit sie den Cron-Tageslauf (nur Datum) nicht überschreibt.
|
||||||
const zeitSuffix = (req.body && req.body.time_suffix !== undefined)
|
const zeitSuffix = (req.body && req.body.time_suffix !== undefined)
|
||||||
? String(req.body.time_suffix)
|
? String(req.body.time_suffix)
|
||||||
: `${String(berlinParts().hour).padStart(2, '0')}${String(berlinParts().minute).padStart(2, '0')}`;
|
: `${String(berlinParts().hour).padStart(2, '0')}${String(berlinParts().minute).padStart(2, '0')}`;
|
||||||
const ergebnis = await buendleAlle({ clientId, label, zeitSuffix });
|
const ergebnis = await buendleAlle({ clientId, ids, label, zeitSuffix });
|
||||||
return res.json({ ok: true, bundles: ergebnis });
|
return res.json({ ok: true, bundles: ergebnis });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('[batch] build fehlgeschlagen:', err);
|
console.error('[batch] build fehlgeschlagen:', err);
|
||||||
|
|||||||
@@ -59,14 +59,20 @@ module.exports = {
|
|||||||
|
|
||||||
// Alternativer Übermittlungsweg (batch_submissions): Ziel-FTP für die täglichen
|
// Alternativer Übermittlungsweg (batch_submissions): Ziel-FTP für die täglichen
|
||||||
// Bündel (xlsx + Sammel-Druck-PDF). Passwort NUR über ENV.
|
// Bündel (xlsx + Sammel-Druck-PDF). Passwort NUR über ENV.
|
||||||
ftp: {
|
// envClean entfernt versehentliche umschließende Anführungszeichen und CR/LF
|
||||||
host: process.env.SKRIFT_FTP_HOST || '',
|
// (häufige .env-Fallen unter Windows/docker env_file), die sonst zu „530
|
||||||
port: parseInt(process.env.SKRIFT_FTP_PORT, 10) || 21,
|
// Login incorrect" führen, obwohl die Daten korrekt sind.
|
||||||
user: process.env.SKRIFT_FTP_USER || '',
|
ftp: (() => {
|
||||||
password: process.env.SKRIFT_FTP_PASSWORD || '',
|
const envClean = (v) => String(v || '').replace(/[\r\n]+/g, '').replace(/^(['"])([\s\S]*)\1$/, '$2');
|
||||||
|
return {
|
||||||
|
host: envClean(process.env.SKRIFT_FTP_HOST),
|
||||||
|
port: parseInt(process.env.SKRIFT_FTP_PORT, 10) || 21,
|
||||||
|
user: envClean(process.env.SKRIFT_FTP_USER),
|
||||||
|
password: envClean(process.env.SKRIFT_FTP_PASSWORD),
|
||||||
// explizites FTP über TLS (wie im FTP-Client eingestellt). 'false' schaltet ab.
|
// explizites FTP über TLS (wie im FTP-Client eingestellt). 'false' schaltet ab.
|
||||||
secure: String(process.env.SKRIFT_FTP_SECURE || 'true').toLowerCase() !== 'false',
|
secure: String(process.env.SKRIFT_FTP_SECURE || 'true').toLowerCase() !== 'false',
|
||||||
// Selbstsigniertes Zertifikat zulassen (viele FTP-Server) – auf 'false' setzen für strikte Prüfung.
|
// Selbstsigniertes Zertifikat zulassen (viele FTP-Server) – auf 'false' setzen für strikte Prüfung.
|
||||||
rejectUnauthorized: String(process.env.SKRIFT_FTP_REJECT_UNAUTHORIZED || 'false').toLowerCase() === 'true',
|
rejectUnauthorized: String(process.env.SKRIFT_FTP_REJECT_UNAUTHORIZED || 'false').toLowerCase() === 'true',
|
||||||
},
|
};
|
||||||
|
})(),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -84,18 +84,21 @@ app.listen(config.port, () => {
|
|||||||
refreshRenderFormats();
|
refreshRenderFormats();
|
||||||
setInterval(refreshRenderFormats, 60 * 60 * 1000);
|
setInterval(refreshRenderFormats, 60 * 60 * 1000);
|
||||||
|
|
||||||
// Batch-Bündelung: täglich um 03:00 (Europe/Berlin) den Vortag bündeln + FTP.
|
// Batch-FTP-Bündelung nur, wenn ausdrücklich aktiviert (Standardweg ist die
|
||||||
// Sa+So werden gemeinsam am Montag verarbeitet (Sonntag-Lauf wird übersprungen).
|
// Übernahme in die Produktion, nicht FTP). SKRIFT_BATCH_FTP_CRON=true schaltet
|
||||||
// Minuten-Tick; einmal pro Tag im 3-Uhr-Fenster (idempotent über letzterBatchTag).
|
// den täglichen 03:00-Lauf (Europe/Berlin) wieder ein; Sa+So am Montag.
|
||||||
let letzterBatchTag = null;
|
if (String(process.env.SKRIFT_BATCH_FTP_CRON || '').toLowerCase() === 'true') {
|
||||||
setInterval(() => {
|
let letzterBatchTag = null;
|
||||||
try {
|
setInterval(() => {
|
||||||
const { date, hour } = berlinParts();
|
try {
|
||||||
if (hour !== 3 || letzterBatchTag === date) return;
|
const { date, hour } = berlinParts();
|
||||||
letzterBatchTag = date; // markiert den Lauf für heute – auch bei Fehler kein Doppel-Lauf.
|
if (hour !== 3 || letzterBatchTag === date) return;
|
||||||
runScheduledBatch().catch((e) => console.error('[batch-cron] Fehler:', e.message));
|
letzterBatchTag = date;
|
||||||
} catch (e) { console.error('[batch-cron] Tick-Fehler:', e.message); }
|
runScheduledBatch().catch((e) => console.error('[batch-cron] Fehler:', e.message));
|
||||||
}, 60 * 1000);
|
} catch (e) { console.error('[batch-cron] Tick-Fehler:', e.message); }
|
||||||
|
}, 60 * 1000);
|
||||||
|
console.log('Batch-FTP-Cron: aktiv (03:00 Europe/Berlin)');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Graceful shutdown
|
// Graceful shutdown
|
||||||
|
|||||||
@@ -112,9 +112,10 @@ async function fetchRenderFormats() {
|
|||||||
|
|
||||||
/** Offene (pending) Batch-Übermittlungen MIT Druck-PDF, optional je Zugang.
|
/** Offene (pending) Batch-Übermittlungen MIT Druck-PDF, optional je Zugang.
|
||||||
* Text-only-Datensätze (ohne PDF) werden bewusst NICHT gebündelt. */
|
* Text-only-Datensätze (ohne PDF) werden bewusst NICHT gebündelt. */
|
||||||
async function fetchBatchPending(clientId) {
|
async function fetchBatchPending(clientId, ids) {
|
||||||
const filter = 'filter[status][_eq]=pending&filter[pdf_file][_nnull]=true'
|
let filter = 'filter[status][_eq]=pending&filter[pdf_file][_nnull]=true';
|
||||||
+ (clientId != null ? `&filter[api_client][_eq]=${encodeURIComponent(clientId)}` : '');
|
if (clientId != null) filter += `&filter[api_client][_eq]=${encodeURIComponent(clientId)}`;
|
||||||
|
if (Array.isArray(ids) && ids.length) filter += `&filter[id][_in]=${ids.map(encodeURIComponent).join(',')}`;
|
||||||
const fields = 'id,api_client,firma,vorname,nachname,zeile1,zeile2,zeile3,plz,stadt,land,pdf_file';
|
const fields = 'id,api_client,firma,vorname,nachname,zeile1,zeile2,zeile3,plz,stadt,land,pdf_file';
|
||||||
return (await directusFetch(`/items/batch_submissions?${filter}&sort=date_created&limit=-1&fields=${fields}`)) || [];
|
return (await directusFetch(`/items/batch_submissions?${filter}&sort=date_created&limit=-1&fields=${fields}`)) || [];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user