diff --git a/.env_example b/.env_example index b680d60..9927eb7 100644 --- a/.env_example +++ b/.env_example @@ -42,7 +42,6 @@ BARCODE_MINCODELENGTH=3 # 💾 Show backup button in the top navigation bar (1 = show, 0 = hide) ADMIN_BUTTON_SWITCH=1 - ############################################# # 🏫 BUSINESS CONFIGURATION ############################################# @@ -152,4 +151,9 @@ USERLABEL_LINE_3=["User.schoolGrade","90%","3%","35vw","2pt","black",12] # 🔲 Barcode for user labels # Format: [top, left, width, height, version] -USERLABEL_BARCODE=["80%","63%","3cm","1.6cm","code128"] \ No newline at end of file +USERLABEL_BARCODE=["80%","63%","3cm","1.6cm","code128"] + +# Prefix und Suffix für den Barcode. +# Beispiele: Escape: \x1B | Enter: \x0D | Tabulator: \x09 | Backspace: \x08 | Line Feed: \x0A | Home (Pos 1): \x01 +USERLABEL_BARCODE_PREFIX="" # Optionales Steuerzeichen vor Eingabe der Ausweisnummer (z.B. ESC) +USERLABEL_BARCODE_SUFFIX="" # Suffix für den Barcode (z.B. um mit einem Zeilenumbruch zu enden) diff --git a/pages/api/report/userlabels/index.tsx b/pages/api/report/userlabels/index.tsx index cfdb0e7..26a7256 100644 --- a/pages/api/report/userlabels/index.tsx +++ b/pages/api/report/userlabels/index.tsx @@ -94,6 +94,18 @@ const barcodeMinLength: number = ? parseInt(process.env.BARCODE_MINCODELENGTH) : DEFAULT_BARCODE_MINCODELENGTH; +// Postfix & Prefix for Barcode +// Hilfs-Funktion zum "Auflösen" von Hex-Strings aus Barcode Prefix/Suffix +const parseEnv = (str: string) => + str.replace(/\\x([0-9A-Fa-f]{2})/g, (_, hex) => String.fromCharCode(parseInt(hex, 16))) + .replace(/\\r/g, "\r") + .replace(/\\n/g, "\n") + .replace(/\\t/g, "\t"); + +const barcodePrefix = parseEnv(process.env.USERLABEL_BARCODE_PREFIX || ""); +const barcodeSuffix = parseEnv(process.env.USERLABEL_BARCODE_SUFFIX || ""); + + // ============================================================================= // Styles // ============================================================================= @@ -221,13 +233,15 @@ const generateBarcode = async (id: string) => { try { const png = await bwipjs.toBuffer({ - bcid: BARCODE_SETTINGS[4], // Barcode type (e.g., 'code128') - text: barId, + bcid: BARCODE_SETTINGS[4], + text: barcodePrefix + barId + barcodeSuffix, + alttext: barId, // Zeigt unten nur die Nummer an scale: 3, + parse: true, height: 10, includetext: true, textxalign: "center", - }); + }); return (