From 23ffc1c55d210def5ff6f392e400d0bc1ba1b74c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Tue, 14 Jul 2026 08:56:54 +0400 Subject: [PATCH] =?UTF-8?q?Revert=20"feat:=20=D0=BF=D0=BE=D0=B4=D0=B4?= =?UTF-8?q?=D0=B5=D1=80=D0=B6=D0=BA=D0=B0=20.doc=20=D1=87=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=B7=20LibreOffice=20headless"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 00d54dbfb68984c0557fc6a70c4d3366df5b25e4. --- Dockerfile | 3 --- docs/ARCHITECTURE.md | 2 +- drhider/extractor.py | 54 +++----------------------------------------- site/app.py | 2 +- 4 files changed, 5 insertions(+), 56 deletions(-) diff --git a/Dockerfile b/Dockerfile index 30915ef..fd17096 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,5 @@ FROM python:3.12-slim WORKDIR /app -RUN apt-get update && apt-get install -y --no-install-recommends \ - libreoffice-writer \ - && rm -rf /var/lib/apt/lists/* COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY site /app/site diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 0958521..fa14ece 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -45,7 +45,7 @@ site/app.py ──→ Flask (create_app) | **`.pdf`** | → Markdown | Текст + таблицы (`pdfplumber`), без форматирования | | **`.txt`** и прочие текстовые | → как есть | Декодируется UTF-8, ошибки заменяются `�` | | **`.zip`** | → распаковка | Файлы внутри обрабатываются рекурсивно. Защита от ZIP-бомб: ≤500 файлов, ratio ≤100:1, ≤500 MB | -| **`.doc`** (бинарный) | → Docx → Markdown | LibreOffice headless: .doc → .docx → штатный `docx_to_markdown()` (таблицы, форматирование). Требует `libreoffice-writer` в контейнере | +| **`.doc`** (бинарный) | ❌ не поддерживается | Возвращает заглушку `[DOC binary — not supported. Convert to .docx first.]` | Ограничение на размер загрузки: **200 MB** (`MAX_CONTENT_LENGTH`). diff --git a/drhider/extractor.py b/drhider/extractor.py index 2c0d159..3c5b353 100644 --- a/drhider/extractor.py +++ b/drhider/extractor.py @@ -4,7 +4,7 @@ Поддерживает: - .docx → MD (python-docx: стили, жирный/курсив, таблицы) - .pdf → MD (pdfplumber: текст + таблицы, без форматирования) -- .doc → MD (LibreOffice headless: .doc → .docx → штатный docx_to_markdown) +- .doc (бинарный — не парсится, возвращает заглушку) - .txt и прочие → как есть Также содержит: @@ -14,9 +14,6 @@ import io import os import zipfile -import tempfile -import shutil -import subprocess import logging from typing import List, Tuple @@ -148,51 +145,6 @@ def pdf_to_markdown(content: bytes) -> str: return "\n".join(lines) -# ═══════════════════════════════════════════════════════════════════════════ -# DOC → Markdown (через LibreOffice) -# ═══════════════════════════════════════════════════════════════════════════ - -def doc_to_markdown(content: bytes) -> str: - """Конвертировать бинарный .doc → .docx (LibreOffice) → Markdown. - - Использует soffice --headless --convert-to docx, затем прогоняет - через штатный docx_to_markdown() с полным форматированием и таблицами. - - Args: - content: Бинарное содержимое .doc файла - - Returns: - Строка в формате Markdown (или сообщение об ошибке) - """ - tmpdir = tempfile.mkdtemp() - doc_path = os.path.join(tmpdir, "input.doc") - try: - with open(doc_path, 'wb') as f: - f.write(content) - - result = subprocess.run( - ["soffice", "--headless", "--convert-to", "docx", - "--outdir", tmpdir, doc_path], - timeout=60, capture_output=True - ) - - docx_path = os.path.join(tmpdir, "input.docx") - if os.path.exists(docx_path): - with open(docx_path, 'rb') as f: - return docx_to_markdown(f.read()) - - stderr = result.stderr.decode('utf-8', errors='replace').strip() - log.warning("LibreOffice conversion failed: %s", stderr) - return f"[DOC — LibreOffice conversion failed: {stderr}]" - - except FileNotFoundError: - return "[DOC — LibreOffice not installed. Install: apt install libreoffice-writer]" - except subprocess.TimeoutExpired: - return "[DOC — conversion timed out (>60s)]" - finally: - shutil.rmtree(tmpdir, ignore_errors=True) - - # ═══════════════════════════════════════════════════════════════════════════ # Единая точка входа # ═══════════════════════════════════════════════════════════════════════════ @@ -224,9 +176,9 @@ def extract_text(fname: str, content: bytes, ctype: str = "") -> str: except ImportError: return content.decode('utf-8', errors='replace') - # ── .doc: бинарный → LibreOffice → DOCX → Markdown ── + # ── .doc: бинарный — пока не поддерживается ── elif ext == '.doc': - return doc_to_markdown(content) + return "[DOC binary — not supported. Convert to .docx first.]" # ── .txt и прочие ── else: diff --git a/site/app.py b/site/app.py index 0053bd0..e0f6ec2 100644 --- a/site/app.py +++ b/site/app.py @@ -20,7 +20,7 @@ if _sys_path_root not in sys.path: sys.path.insert(0, _sys_path_root) # Версия приложения (меняется при изменениях) -VERSION = "0.0.17" +VERSION = "0.0.16" def create_app():