Spaces:
Sleeping
Download examples/hf-generated/pdf/design.md from dellweb3/VibeCoding: direct link, hf CLI and curl.
- Browser
- Download file 1.14 kB
-
https://huggingface.co/spaces/dellweb3/VibeCoding/resolve/main/examples/hf-generated/pdf/design.md
- Command line
-
hf download hf://spaces/dellweb3/VibeCoding/examples/hf-generated/pdf/design.md
-
curl -L -o design.md https://huggingface.co/spaces/dellweb3/VibeCoding/resolve/main/examples/hf-generated/pdf/design.md
Implement demo.App as a Java17 HttpServer on port 8080. Define endpoints: GET /health returns {"status":"ok"}; POST /api/pdf/analyze requires Authorization header 'Bearer demo-pdf'. Enforce method/path checks before auth to return 405/404 appropriately. Parse JSON body strictly for single 'base64' field; reject extra fields or non-canonical Base64 with 400 INVALID_INPUT. Limit request size to 180001 bytes and decoded PDF to 131072 bytes (413 PDF_TOO_LARGE). Validate Content-Type starts with application/json. Use PDFBox 3.0.8 Loader.loadPDF(byte[]) in try-with-resources. Check document.isEncrypted() -> 422 ENCRYPTED_PDF. Verify page count: 0 pages -> 400 INVALID_PDF, >20 pages -> 422 PAGE_LIMIT. Extract text per page using PDFTextStripper (sortByPosition=true), normalize CRLF/CR to LF, strip surrounding whitespace. Count Unicode code points. If all pages empty -> status NO_TEXT, else TEXT_EXTRACTED. Check total UTF-8 text length <= 24000 and serialized response <= 60000 bytes; otherwise 413 TEXT_LIMIT. Return JSON with pageCount, pages array, totalCharacters, and status. Ensure no external dependencies beyond pinned PDFBox jar.