From 4ce2c060b05bf4dd9c48f8c571d611c9734ebe99 Mon Sep 17 00:00:00 2001 From: anor Date: Wed, 10 Jun 2026 17:13:10 +1000 Subject: [PATCH] =?UTF-8?q?feat(1.4):=20/api/data-version=20=E2=80=94=20?= =?UTF-8?q?=D1=81=D0=B2=D0=B5=D0=B6=D0=B5=D1=81=D1=82=D1=8C=20=D0=BA=D0=BE?= =?UTF-8?q?=D1=80=D0=BF=D1=83=D1=81=D0=BD=D0=BE=D0=B9=20=D0=B1=D0=B0=D0=B7?= =?UTF-8?q?=D1=8B=20=D1=86=D0=B5=D0=BD=20=D0=B8=D0=B7=20=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=BD=D1=8B=D1=85=20+=20=D0=B8=D0=BD=D0=B4=D0=B8=D0=BA=D0=B0?= =?UTF-8?q?=D1=82=D0=BE=D1=80=20=D0=B2=20UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5 --- main.py | 42 ++++++++++++++++++++++++++++++++++++++++++ static/chat.html | 8 +++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index d020f08..bea4ffe 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,9 @@ """smeta-web: AI assistant for estimators — FastAPI + Claude Code or GLM-5.""" +import asyncio import json import os +import re import shutil import time from pathlib import Path @@ -310,6 +312,46 @@ async def version(): return {"version": APP_VERSION} +# Свежесть корпусной базы цен — чтобы сметчик видел, на какой период данные. +# Берём реальный ценовой период ИЗ данных (а не mtime файла: после git clone +# mtime = дата клонирования и врёт). Кэшируем — файлы корпуса по 5–12 МБ. +_DATA_PERIODS_CACHE = None + + +def _compute_data_periods(): + base = Path(__file__).resolve().parent / "data" / "real_corpus" + rx = re.compile(r"(20[12]\d) ?Q([1-4])") # 2010–2029, отсекаем мусор вроде «2052 Q1» + srcs = [ + ("Корпус смет (расценки/цены)", "estimates_index.json"), + ("База материалов (КА)", "ka_index.json"), + ("База работ (ВОР)", "vor_index.json"), + ] + result = [] + for label, fn in srcs: + period = None + try: + txt = (base / fn).read_text(encoding="utf-8") + ms = rx.findall(txt) + if ms: + y, q = max(ms, key=lambda yq: (int(yq[0]), int(yq[1]))) + period = f"{y} Q{q}" + except OSError: + pass + result.append({"label": label, "period": period}) + return result + + +@app.get("/api/data-version") +async def data_version(): + """Public — на какой ценовой период актуальна корпусная база (свежесть данных).""" + global _DATA_PERIODS_CACHE + if _DATA_PERIODS_CACHE is None: + _DATA_PERIODS_CACHE = await asyncio.to_thread(_compute_data_periods) + periods = [s["period"] for s in _DATA_PERIODS_CACHE if s["period"]] + newest = max(periods, key=lambda s: (int(s[:4]), int(s[-1]))) if periods else None + return {"newest_period": newest, "sources": _DATA_PERIODS_CACHE, "app_version": APP_VERSION} + + # Resumable uploads (tus 1.0.0). Same-process, reuses auth + per-user work dir; # the finished file lands in the work dir exactly like legacy /api/upload. TUS_MAX_SIZE = 3 * 1024 * 1024 * 1024 # 3 GB diff --git a/static/chat.html b/static/chat.html index 8c22b58..130bddc 100644 --- a/static/chat.html +++ b/static/chat.html @@ -262,7 +262,7 @@ html { color-scheme: light; } -
О безопасности сервиса
+
О безопасности сервиса
@@ -295,6 +295,12 @@ fetch('/api/version').then(function (r) { return r.json(); }).then(function (d) document.querySelectorAll('.app-version').forEach(function (el) { el.textContent = 'v.' + d.version; }); }).catch(function () {}); +// Индикатор свежести данных: на какой ценовой период актуальна корпусная база. +fetch('/api/data-version').then(function (r) { return r.json(); }).then(function (d) { + if (!d.newest_period) return; + document.querySelectorAll('.data-version').forEach(function (el) { el.textContent = 'цены: ' + d.newest_period; }); +}).catch(function () {}); + function renderMarkdown(text) { // Санитайзим вывод модели перед innerHTML: вырезаем onerror/onclick/javascript: // и прочие XSS-векторы, сохраняя таблицы/ссылки/форматирование. Требуем оба