From 87a6df45c50f54cd49d82fd681c4a3f94e41938a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?=
Date: Thu, 16 Jul 2026 11:28:16 +0400
Subject: [PATCH] =?UTF-8?q?v0.0.30:=20.doc=20=D0=BF=D0=BE=D0=B4=D0=B4?=
=?UTF-8?q?=D0=B5=D1=80=D0=B6=D0=BA=D0=B0=20=E2=80=94=20accept=20+=20liber?=
=?UTF-8?q?ta=20API=20=D0=B2=D0=BC=D0=B5=D1=81=D1=82=D0=BE=20LibreOffice?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
drhider/extractor.py | 54 +++++++++++++++++----------------------
site/app.py | 2 +-
site/templates/index.html | 2 +-
3 files changed, 26 insertions(+), 32 deletions(-)
diff --git a/drhider/extractor.py b/drhider/extractor.py
index 2c0d159..ed23f9c 100644
--- a/drhider/extractor.py
+++ b/drhider/extractor.py
@@ -149,14 +149,14 @@ def pdf_to_markdown(content: bytes) -> str:
# ═══════════════════════════════════════════════════════════════════════════
-# DOC → Markdown (через LibreOffice)
+# DOC → Markdown (через сервис liberta)
# ═══════════════════════════════════════════════════════════════════════════
def doc_to_markdown(content: bytes) -> str:
- """Конвертировать бинарный .doc → .docx (LibreOffice) → Markdown.
+ """Конвертировать бинарный .doc → .docx (сервис liberta) → Markdown.
- Использует soffice --headless --convert-to docx, затем прогоняет
- через штатный docx_to_markdown() с полным форматированием и таблицами.
+ Отправляет .doc на HTTP-сервис конвертации, получает .docx,
+ затем прогоняет через штатный docx_to_markdown().
Args:
content: Бинарное содержимое .doc файла
@@ -164,33 +164,27 @@ def doc_to_markdown(content: bytes) -> str:
Returns:
Строка в формате Markdown (или сообщение об ошибке)
"""
- tmpdir = tempfile.mkdtemp()
- doc_path = os.path.join(tmpdir, "input.doc")
+ import httpx
+ url = os.environ.get(
+ "CONVERT_SERVICE_URL",
+ "https://liberta.containerk8s.dev.nubes.ru/convert"
+ )
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)
+ with httpx.Client(timeout=120) as client:
+ resp = client.post(
+ url,
+ files={"file": ("input.doc", content, "application/msword")}
+ )
+ if resp.status_code == 200:
+ return docx_to_markdown(resp.content)
+ err = resp.json().get("error", f"HTTP {resp.status_code}")
+ log.warning("liberta conversion failed: %s", err)
+ return f"[DOC — conversion failed: {err}]"
+ except httpx.TimeoutException:
+ return "[DOC — conversion timed out (>120s)]"
+ except Exception as e:
+ log.warning("liberta error: %s", e)
+ return f"[DOC — conversion error: {e}]"
# ═══════════════════════════════════════════════════════════════════════════
diff --git a/site/app.py b/site/app.py
index 07ab789..059d46e 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.29"
+VERSION = "0.0.30"
def create_app():
diff --git a/site/templates/index.html b/site/templates/index.html
index 8240bdb..c5ee1c1 100644
--- a/site/templates/index.html
+++ b/site/templates/index.html
@@ -101,7 +101,7 @@
CSV с таблицей замен скачивается отдельно.
-
+