v1.0.157: VM API /api/supplements + /api/documents — index.cfm no longer calls Lucee api.cfm
This commit is contained in:
@@ -10,6 +10,11 @@ from db import prompts as db_prompts
|
|||||||
from db.connection import DB_CONFIG
|
from db.connection import DB_CONFIG
|
||||||
db_prompts.seed_defaults()
|
db_prompts.seed_defaults()
|
||||||
|
|
||||||
|
# ── DB modules ────────────────────────────────────────────────────────────
|
||||||
|
from db import supplements as db_supplements
|
||||||
|
from db import documents as db_documents
|
||||||
|
from db import spec_current as db_spec_current
|
||||||
|
|
||||||
# ── Services ──────────────────────────────────────────────────────────────
|
# ── Services ──────────────────────────────────────────────────────────────
|
||||||
from services.upload import handle_upload
|
from services.upload import handle_upload
|
||||||
from services.unzip import handle_unzip
|
from services.unzip import handle_unzip
|
||||||
@@ -35,6 +40,10 @@ class Handler(BaseHTTPRequestHandler):
|
|||||||
self._handle_process_v2(parsed)
|
self._handle_process_v2(parsed)
|
||||||
elif parsed.path == "/health":
|
elif parsed.path == "/health":
|
||||||
self._json({"ok": True, "db": DB_CONFIG["dbname"]})
|
self._json({"ok": True, "db": DB_CONFIG["dbname"]})
|
||||||
|
elif parsed.path == "/api/supplements":
|
||||||
|
self._handle_api_supplements(parsed)
|
||||||
|
elif parsed.path.startswith("/api/documents/"):
|
||||||
|
self._handle_api_document(parsed)
|
||||||
else:
|
else:
|
||||||
self.send_error(404)
|
self.send_error(404)
|
||||||
|
|
||||||
@@ -79,6 +88,33 @@ class Handler(BaseHTTPRequestHandler):
|
|||||||
self.wfile.write(f"data: {json.dumps(data, ensure_ascii=False)}\n\n".encode())
|
self.wfile.write(f"data: {json.dumps(data, ensure_ascii=False)}\n\n".encode())
|
||||||
self.wfile.flush()
|
self.wfile.flush()
|
||||||
|
|
||||||
|
# ── /api/supplements ──────────────────────────────────────────────────
|
||||||
|
|
||||||
|
def _handle_api_supplements(self, parsed):
|
||||||
|
params = parse_qs(parsed.query)
|
||||||
|
cid = params.get("contract_id", [None])[0]
|
||||||
|
if not cid:
|
||||||
|
self._json({"ok": False, "error": "contract_id required"}, 400)
|
||||||
|
return
|
||||||
|
rows = db_supplements.list_by_contract(cid)
|
||||||
|
self._json({"ok": True, "supplements": rows})
|
||||||
|
|
||||||
|
# ── /api/documents/<id> ──────────────────────────────────────────────
|
||||||
|
|
||||||
|
def _handle_api_document(self, parsed):
|
||||||
|
doc_id = parsed.path.split("/")[-1]
|
||||||
|
doc = db_documents.get(doc_id)
|
||||||
|
if not doc:
|
||||||
|
self._json({"ok": False, "error": "not found"}, 404)
|
||||||
|
return
|
||||||
|
self._json({
|
||||||
|
"ok": True,
|
||||||
|
"id": doc["id"],
|
||||||
|
"filename": doc["filename"],
|
||||||
|
"status": doc["status"],
|
||||||
|
"elements_json": doc.get("elements_json"),
|
||||||
|
})
|
||||||
|
|
||||||
# ── /upload ───────────────────────────────────────────────────────────
|
# ── /upload ───────────────────────────────────────────────────────────
|
||||||
|
|
||||||
def _handle_upload(self):
|
def _handle_upload(self):
|
||||||
|
|||||||
@@ -75,7 +75,7 @@
|
|||||||
<body>
|
<body>
|
||||||
<div class="topbar">
|
<div class="topbar">
|
||||||
<img src="/nubes-logo.svg" alt="Nubes">
|
<img src="/nubes-logo.svg" alt="Nubes">
|
||||||
<span class="title">Сверка договоров — LLM AI-driven Event Sourcing <span style="font-weight:400;color:var(--muted);font-size:12px;">v1.0.156 — Lucee</span></span>
|
<span class="title">Сверка договоров — LLM AI-driven Event Sourcing <span style="font-weight:400;color:var(--muted);font-size:12px;">v1.0.157 — Lucee</span></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
@@ -572,14 +572,11 @@ document.getElementById('llmBtn').addEventListener('click', function() {
|
|||||||
async function refreshSupps() {
|
async function refreshSupps() {
|
||||||
if (!contractId) { console.log('refreshSupps: no contractId'); return; }
|
if (!contractId) { console.log('refreshSupps: no contractId'); return; }
|
||||||
try {
|
try {
|
||||||
var resp = await fetch('/api.cfm?action=query&sql=' + encodeURIComponent("SELECT s.id, s.type, s.document_id FROM supplements s WHERE s.contract_id='" + contractId + "'"));
|
var resp = await fetch(VM_API + '/api/supplements?contract_id=' + contractId);
|
||||||
var data = await resp.json();
|
var data = await resp.json();
|
||||||
console.log('refreshSupps: data=', data);
|
console.log('refreshSupps: data=', data);
|
||||||
console.log('refreshSupps: fileQueue doc_ids=', fileQueue.map(function(f){return f.doc_id;}));
|
if (data.ok && data.supplements) {
|
||||||
if (data.OK && data.ROWS) {
|
data.supplements.forEach(function(supp) {
|
||||||
data.ROWS.forEach(function(r) {
|
|
||||||
var supp = {};
|
|
||||||
data.COLUMNS.forEach(function(c, ci) { supp[String(c).toLowerCase()] = r[c]; });
|
|
||||||
console.log('refreshSupps: supp=', supp);
|
console.log('refreshSupps: supp=', supp);
|
||||||
for (var i = 0; i < fileQueue.length; i++) {
|
for (var i = 0; i < fileQueue.length; i++) {
|
||||||
if (fileQueue[i].doc_id === supp.document_id) {
|
if (fileQueue[i].doc_id === supp.document_id) {
|
||||||
@@ -646,13 +643,14 @@ async function showText(i) {
|
|||||||
|
|
||||||
if (docId) {
|
if (docId) {
|
||||||
try {
|
try {
|
||||||
var qResp = await fetch('/api.cfm?action=query&sql=SELECT%20elements_json%20FROM%20documents%20WHERE%20id%3D\'' + docId + '\'');
|
var qResp = await fetch(VM_API + '/api/documents/' + docId);
|
||||||
var qData = await qResp.json();
|
var qData = await qResp.json();
|
||||||
var elements = [];
|
var elements = [];
|
||||||
if (qData.OK && qData.ROWS && qData.ROWS.length > 0) {
|
if (qData.ok && qData.elements_json) {
|
||||||
var ej = qData.ROWS[0].ELEMENTS_JSON;
|
var ej = qData.elements_json;
|
||||||
if (typeof ej === 'object' && ej.Value) ej = ej.Value;
|
if (typeof ej === 'object' && ej.Value) ej = ej.Value;
|
||||||
elements = JSON.parse(ej);
|
if (typeof ej === 'string') elements = JSON.parse(ej);
|
||||||
|
else elements = ej;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Общий textify для обеих панелей
|
// Общий textify для обеих панелей
|
||||||
|
|||||||
Reference in New Issue
Block a user