1 Commits

Author SHA1 Message Date
s4luorth
25ffb3727b Scriptalizer: nach Zeichenlaenge batchen (32000-Limit)
All checks were successful
Build & Deploy / deploy (push) Successful in 19s
Fixe 18er-Batches sprengen bei langen/mehrseitigen Texten das InputText-Limit der
Scriptalizer-API (32000 Zeichen) -> 'Input length limit 32000 exceeded'. Jetzt werden
Batches nach kumulativer Zeichenlaenge (max 28000, Sicherheitsabstand) gebildet, die
Anzahl 18 bleibt als zusaetzlicher Deckel.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-29 10:00:58 +02:00

View File

@@ -141,29 +141,49 @@ async function scriptalizeBatch(texts, font = "tilda", errFrequency = 10) {
config.scriptalizer.fontMap[font.toLowerCase()] || config.scriptalizer.fontMap[font.toLowerCase()] ||
config.scriptalizer.fontMap.tilda; config.scriptalizer.fontMap.tilda;
const separator = config.scriptalizer.separator; const separator = config.scriptalizer.separator;
const BATCH_SIZE = 18; // 18 Texte pro Scriptalizer API Call (Scriptalizer-API-Limit: 32000 Zeichen pro Call → ca. 1700 Zeichen pro Brief sicher) const BATCH_SIZE = 18; // Zusätzlicher Deckel: max. 18 Texte pro Call (unabhängig von der Länge).
// Primäre Grenze ist die ZEICHENLÄNGE: die Scriptalizer-API begrenzt den
// InputText auf 32000 Zeichen pro Call ("Input length limit 32000 exceeded").
// Fixe 18er-Batches sprengen das bei langen (mehrseitigen) Texten – daher nach
// kumulativer Länge batchen, mit Sicherheitsabstand.
const MAX_BATCH_CHARS = 28000;
const sepLen = separator.length;
// Batches nach Länge (und max. Anzahl) bilden.
const batches = [];
{
let cur = [];
let curLen = 0;
for (const t of texts) {
const tLen = String(t || "").length;
const projected = curLen + (cur.length ? sepLen : 0) + tLen;
if (cur.length && (projected > MAX_BATCH_CHARS || cur.length >= BATCH_SIZE)) {
batches.push(cur);
cur = [];
curLen = 0;
}
cur.push(t);
curLen += (cur.length > 1 ? sepLen : 0) + tLen;
}
if (cur.length) batches.push(cur);
}
const totalBatches = batches.length;
console.log( console.log(
`[Scriptalizer] Processing ${texts.length} texts in batches of ${BATCH_SIZE}` `[Scriptalizer] Processing ${texts.length} texts in ${totalBatches} batch(es) (max ${BATCH_SIZE} texts / ${MAX_BATCH_CHARS} chars each)`
); );
const allScriptalized = []; const allScriptalized = [];
// Teile in 25er Batches auf for (let b = 0; b < batches.length; b += 1) {
for (let i = 0; i < texts.length; i += BATCH_SIZE) { const batch = batches[b];
const batch = texts.slice(i, i + BATCH_SIZE); const batchNumber = b + 1;
const batchNumber = Math.floor(i / BATCH_SIZE) + 1; const combinedText = batch.join(separator);
const totalBatches = Math.ceil(texts.length / BATCH_SIZE);
console.log( console.log(
`[Scriptalizer] Processing batch ${batchNumber}/${totalBatches} (${ `[Scriptalizer] Processing batch ${batchNumber}/${totalBatches} (${batch.length} texts, ${combinedText.length} chars)`
batch.length
} texts, indices ${i}-${i + batch.length - 1})`
); );
// Kombiniere Texte mit Separator
const combinedText = batch.join(separator);
try { try {
const result = await callScriptalizer( const result = await callScriptalizer(
combinedText, combinedText,