tradingprintable/auction-labels-pdf-api
0
1import os2from flask import request, jsonify3 4SECRET_ENV_KEY = "PDF_SECRET_TOKEN"5 6def check_token(req: request) -> bool:7 """Return True if the request carries the correct X-Secret-Token."""8 expected = os.getenv(SECRET_ENV_KEY, "")9 return req.headers.get("X-Secret-Token") == expected10 11 12 13# --------------------------------------------------------------------14# Serial generator (simple file-counter approach)15# Keeps the last number in a tiny text file on disk.16# Example output: JT-R25-0001, JT-R25-0002, ...17# --------------------------------------------------------------------18from datetime import datetime19import pathlib, threading20 21BASE_DIR = pathlib.Path(__file__).resolve().parent22_serial_lock = threading.Lock()23COUNTER_FILE = BASE_DIR / "serial_counter.txt"24 25def get_next_offer_serial(prefix: str = "JT-R") -> str:26 """Return a new serial like JT-R25-0001 where 25 = current year%100."""27 year_suffix = datetime.utcnow().year % 100 # 2025 → 2528 29 with _serial_lock: # thread-safe30 COUNTER_FILE.touch(exist_ok=True) # NEW ➜ auto-create file31 last = int(COUNTER_FILE.read_text().strip() or "0")32 new_num = last + 133 COUNTER_FILE.write_text(str(new_num))34 35 return f"{prefix}{year_suffix:02d}-{new_num:04d}"36 37 