Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3bef26b332 | ||
|
|
94751c12ff |
@@ -96,8 +96,8 @@ async function buendleZugang(clientId, subs, label, zeitSuffix) {
|
||||
}
|
||||
|
||||
/** Bündelt alle offenen Datensätze (optional nur ein Zugang), gruppiert je Zugang. */
|
||||
async function buendleAlle({ clientId = null, label, zeitSuffix = '' }) {
|
||||
const alle = await fetchBatchPending(clientId);
|
||||
async function buendleAlle({ clientId = null, ids = null, label, zeitSuffix = '' }) {
|
||||
const alle = await fetchBatchPending(clientId, ids);
|
||||
const proZugang = new Map();
|
||||
for (const s of alle) {
|
||||
const k = String(s.api_client);
|
||||
@@ -117,12 +117,13 @@ async function buendleAlle({ clientId = null, label, zeitSuffix = '' }) {
|
||||
async function buildBundles(req, res) {
|
||||
try {
|
||||
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;
|
||||
// Manuelle Bündelung mit Uhrzeit-Suffix, damit sie den Cron-Tageslauf (nur Datum) nicht überschreibt.
|
||||
const zeitSuffix = (req.body && req.body.time_suffix !== undefined)
|
||||
? String(req.body.time_suffix)
|
||||
: `${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 });
|
||||
} catch (err) {
|
||||
console.error('[batch] build fehlgeschlagen:', err);
|
||||
|
||||
@@ -59,14 +59,20 @@ module.exports = {
|
||||
|
||||
// Alternativer Übermittlungsweg (batch_submissions): Ziel-FTP für die täglichen
|
||||
// Bündel (xlsx + Sammel-Druck-PDF). Passwort NUR über ENV.
|
||||
ftp: {
|
||||
host: process.env.SKRIFT_FTP_HOST || '',
|
||||
port: parseInt(process.env.SKRIFT_FTP_PORT, 10) || 21,
|
||||
user: process.env.SKRIFT_FTP_USER || '',
|
||||
password: process.env.SKRIFT_FTP_PASSWORD || '',
|
||||
// envClean entfernt versehentliche umschließende Anführungszeichen und CR/LF
|
||||
// (häufige .env-Fallen unter Windows/docker env_file), die sonst zu „530
|
||||
// Login incorrect" führen, obwohl die Daten korrekt sind.
|
||||
ftp: (() => {
|
||||
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.
|
||||
secure: String(process.env.SKRIFT_FTP_SECURE || 'true').toLowerCase() !== 'false',
|
||||
// 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',
|
||||
};
|
||||
})(),
|
||||
};
|
||||
|
||||
@@ -112,9 +112,10 @@ async function fetchRenderFormats() {
|
||||
|
||||
/** Offene (pending) Batch-Übermittlungen MIT Druck-PDF, optional je Zugang.
|
||||
* Text-only-Datensätze (ohne PDF) werden bewusst NICHT gebündelt. */
|
||||
async function fetchBatchPending(clientId) {
|
||||
const filter = 'filter[status][_eq]=pending&filter[pdf_file][_nnull]=true'
|
||||
+ (clientId != null ? `&filter[api_client][_eq]=${encodeURIComponent(clientId)}` : '');
|
||||
async function fetchBatchPending(clientId, ids) {
|
||||
let filter = 'filter[status][_eq]=pending&filter[pdf_file][_nnull]=true';
|
||||
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';
|
||||
return (await directusFetch(`/items/batch_submissions?${filter}&sort=date_created&limit=-1&fields=${fields}`)) || [];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user