lambda-erp 1.4.26__tar.gz → 1.4.27__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/PKG-INFO +1 -1
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/attachments.py +41 -36
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/chat.py +3 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/database.py +6 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/pyproject.toml +1 -1
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/.gitignore +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/LICENSE +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/README.md +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/__init__.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/auth.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/bootstrap.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/chat_links.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/demo_limits.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/deps.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/erp_context.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/errors.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/list_values.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/llm_provider.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/main.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/mcp_oauth.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/mentions.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/menu_layout.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/oauth.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/pdf.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/pdf_contract.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/pdf_exports.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/pdf_fonts.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/pdf_pages.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/pdf_profiles.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/pdf_templates.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/pricing_actions.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/providers.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/record_attachments.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/record_notes.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/remarks_md.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/routers/__init__.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/routers/accounting.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/routers/actions.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/routers/admin.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/routers/analytics.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/routers/availability.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/routers/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/routers/bank_statements.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/routers/chat_api.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/routers/documents.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/routers/masters.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/routers/mcp.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/routers/pdf_templates.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/routers/proposals.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/routers/reports.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/routers/setup.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/services.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/stock_actions.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/templates/_proposal_totals.html +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/templates/_record_base.html +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/templates/delivery_note.html +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/templates/document.html +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/templates/proposal.html +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/templates/record.html +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/templates/reservation.html +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/time_filters.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/tool_permissions.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/tool_results.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/api/write_context.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/docs/agents/README.md +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/frontend/LICENSE +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/frontend/README.md +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/frontend/src/api/client.ts +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/__init__.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/__init__.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/bank_account.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/bank_reconciliation.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/bank_statement_import.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/bank_transaction.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/budget.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/camt.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/chart_of_accounts.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/general_ledger.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/journal_entry.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/payment_entry.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/pos_invoice.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/purchase_invoice.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/revaluation.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/sales_invoice.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/settlement.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/setup/__init__.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/setup/engine.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/setup/pack.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/setup/packs/__init__.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/setup/packs/ch.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/setup/packs/de_common.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/setup/packs/de_skr03.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/setup/packs/de_skr04.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/setup/packs/generic.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/setup/profiles.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/setup/spine.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/accounting/subscription.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/addresses.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/assets/__init__.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/assets/asset.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/assets/lifecycle.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/assets/reservation.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/backlog.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/bundles.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/buying/__init__.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/buying/purchase_order.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/controllers/__init__.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/controllers/currency.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/controllers/defaults.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/controllers/item_price.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/controllers/item_prices.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/controllers/price_resolution.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/controllers/pricing_rule.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/controllers/tax_defaults.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/controllers/taxes_and_totals.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/exceptions.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/hooks.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/master_integrity.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/model.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/permissions.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/selling/__init__.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/selling/proposal.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/selling/quotation.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/selling/sales_order.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/simulation.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/stock/__init__.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/stock/consignment.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/stock/delivery_note.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/stock/purchase_receipt.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/stock/reservation.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/stock/serial.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/stock/stock_count.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/stock/stock_entry.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/stock/stock_ledger.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/timestamps.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/units.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/utils.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/validation.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/lambda_erp/workflow.py +0 -0
- {lambda_erp-1.4.26 → lambda_erp-1.4.27}/terraform/README.md +0 -0
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
"""Chat attachment upload/download. Files
|
|
1
|
+
"""Chat attachment upload/download. Files follow the chat database unless a deployment configures upload storage."""
|
|
2
2
|
|
|
3
3
|
import base64
|
|
4
4
|
import io
|
|
5
5
|
import logging
|
|
6
6
|
import os
|
|
7
|
-
import tempfile
|
|
8
7
|
import time
|
|
9
8
|
import uuid
|
|
10
9
|
from typing import Optional
|
|
@@ -196,17 +195,9 @@ def spreadsheet_row_warning(data: bytes, mime: str, filename: str) -> Optional[s
|
|
|
196
195
|
"Split the file or ask about a specific range.")
|
|
197
196
|
return None
|
|
198
197
|
|
|
199
|
-
#
|
|
200
|
-
#
|
|
201
|
-
|
|
202
|
-
# app user, so every upload 500s with "[Errno 13] Permission denied". Default to
|
|
203
|
-
# the OS temp dir (always writable; chat attachments are session-scoped and
|
|
204
|
-
# get_attachments_by_ids tolerates a missing file). Deployments that need the
|
|
205
|
-
# files to survive a restart set LAMBDA_ERP_UPLOAD_DIR to a mounted volume.
|
|
206
|
-
UPLOAD_ROOT = (
|
|
207
|
-
os.environ.get("LAMBDA_ERP_UPLOAD_DIR")
|
|
208
|
-
or os.path.join(tempfile.gettempdir(), "lambda-erp-uploads")
|
|
209
|
-
)
|
|
198
|
+
# Explicitly configured volumes retain their existing filesystem storage mode.
|
|
199
|
+
# Otherwise keep the bytes in the same database transaction as their metadata.
|
|
200
|
+
UPLOAD_ROOT = os.environ.get("LAMBDA_ERP_UPLOAD_DIR")
|
|
210
201
|
|
|
211
202
|
|
|
212
203
|
def _ensure_upload_dir(user_id: str) -> str:
|
|
@@ -297,18 +288,27 @@ async def upload_attachment(
|
|
|
297
288
|
att_id = uuid.uuid4().hex
|
|
298
289
|
ext = _safe_ext(file.filename or "", mime)
|
|
299
290
|
user_id = user["name"]
|
|
300
|
-
|
|
301
|
-
|
|
291
|
+
file_path = ""
|
|
292
|
+
if UPLOAD_ROOT:
|
|
293
|
+
upload_dir = _ensure_upload_dir(user_id)
|
|
294
|
+
file_path = os.path.join(upload_dir, f"{att_id}.{ext}")
|
|
302
295
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
296
|
+
try:
|
|
297
|
+
if file_path:
|
|
298
|
+
with open(file_path, "wb") as f:
|
|
299
|
+
f.write(data)
|
|
300
|
+
db.sql(
|
|
301
|
+
'INSERT INTO "Chat Attachment" (id, session_id, user_id, filename, mime_type, size_bytes, file_path, data, created_at) '
|
|
302
|
+
'VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
|
303
|
+
[att_id, session_id, user_id, file.filename or f"file.{ext}", mime, len(data), file_path,
|
|
304
|
+
None if file_path else data, now()],
|
|
305
|
+
)
|
|
306
|
+
db.conn.commit()
|
|
307
|
+
except Exception:
|
|
308
|
+
db.conn.rollback()
|
|
309
|
+
if file_path and os.path.isfile(file_path):
|
|
310
|
+
os.remove(file_path)
|
|
311
|
+
raise
|
|
312
312
|
|
|
313
313
|
resp = {
|
|
314
314
|
"id": att_id,
|
|
@@ -325,6 +325,16 @@ async def upload_attachment(
|
|
|
325
325
|
return resp
|
|
326
326
|
|
|
327
327
|
|
|
328
|
+
def _attachment_bytes(row: dict) -> bytes | None:
|
|
329
|
+
if row["data"] is not None:
|
|
330
|
+
return bytes(row["data"])
|
|
331
|
+
try:
|
|
332
|
+
with open(row["file_path"], "rb") as f:
|
|
333
|
+
return f.read()
|
|
334
|
+
except FileNotFoundError:
|
|
335
|
+
return None
|
|
336
|
+
|
|
337
|
+
|
|
328
338
|
@router.get("/attachments/{attachment_id}")
|
|
329
339
|
def download_attachment(
|
|
330
340
|
attachment_id: str,
|
|
@@ -333,7 +343,7 @@ def download_attachment(
|
|
|
333
343
|
"""Download a chat attachment. Scoped to the owning user."""
|
|
334
344
|
db = get_db()
|
|
335
345
|
rows = db.sql(
|
|
336
|
-
'SELECT filename, mime_type, file_path, user_id FROM "Chat Attachment" WHERE id = ?',
|
|
346
|
+
'SELECT filename, mime_type, file_path, data, user_id FROM "Chat Attachment" WHERE id = ?',
|
|
337
347
|
[attachment_id],
|
|
338
348
|
)
|
|
339
349
|
if not rows:
|
|
@@ -344,12 +354,10 @@ def download_attachment(
|
|
|
344
354
|
if row["user_id"] != user["name"] and user.get("role") != "admin":
|
|
345
355
|
raise HTTPException(status_code=403, detail="Not authorized")
|
|
346
356
|
|
|
347
|
-
|
|
357
|
+
data = _attachment_bytes(row)
|
|
358
|
+
if data is None:
|
|
348
359
|
raise HTTPException(status_code=404, detail="File missing on disk")
|
|
349
360
|
|
|
350
|
-
with open(row["file_path"], "rb") as f:
|
|
351
|
-
data = f.read()
|
|
352
|
-
|
|
353
361
|
return Response(
|
|
354
362
|
content=data,
|
|
355
363
|
media_type=row["mime_type"],
|
|
@@ -369,16 +377,15 @@ def get_attachments_by_ids(attachment_ids: list[str], user_id: str) -> list[dict
|
|
|
369
377
|
db = get_db()
|
|
370
378
|
placeholders = ",".join(["?"] * len(attachment_ids))
|
|
371
379
|
rows = db.sql(
|
|
372
|
-
f'SELECT id, filename, mime_type, file_path, size_bytes, '
|
|
380
|
+
f'SELECT id, filename, mime_type, file_path, data, size_bytes, '
|
|
373
381
|
f'openai_file_id, openai_file_expires_at FROM "Chat Attachment" '
|
|
374
382
|
f'WHERE id IN ({placeholders}) AND user_id = ?',
|
|
375
383
|
list(attachment_ids) + [user_id],
|
|
376
384
|
)
|
|
377
385
|
result = []
|
|
378
386
|
for row in rows:
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
data = f.read()
|
|
387
|
+
data = _attachment_bytes(row)
|
|
388
|
+
if data is not None:
|
|
382
389
|
result.append({
|
|
383
390
|
"id": row["id"],
|
|
384
391
|
"filename": row["filename"],
|
|
@@ -388,8 +395,6 @@ def get_attachments_by_ids(attachment_ids: list[str], user_id: str) -> list[dict
|
|
|
388
395
|
"openai_file_expires_at": row.get("openai_file_expires_at"),
|
|
389
396
|
"data": data,
|
|
390
397
|
})
|
|
391
|
-
except FileNotFoundError:
|
|
392
|
-
continue
|
|
393
398
|
return result
|
|
394
399
|
|
|
395
400
|
|
|
@@ -474,7 +479,7 @@ def list_session_attachments(session_id: str, user_id: str) -> list[dict]:
|
|
|
474
479
|
def delete_session_attachments(session_id: str) -> None:
|
|
475
480
|
"""Delete all attachments (DB + files) for a session. Used on chat clear/delete."""
|
|
476
481
|
db = get_db()
|
|
477
|
-
rows = db.sql('SELECT file_path FROM "Chat Attachment" WHERE session_id = ?', [session_id])
|
|
482
|
+
rows = db.sql('SELECT file_path FROM "Chat Attachment" WHERE session_id = ? AND length(file_path) > 0', [session_id])
|
|
478
483
|
for r in rows:
|
|
479
484
|
try:
|
|
480
485
|
os.remove(r["file_path"])
|
|
@@ -2247,6 +2247,9 @@ def _handle_retrieve_chat_attachment(args, session_id: str | None = None, user_i
|
|
|
2247
2247
|
from api.attachments import get_attachments_by_ids, build_multimodal_content
|
|
2248
2248
|
atts = get_attachments_by_ids([attachment_id], user_id)
|
|
2249
2249
|
if not atts:
|
|
2250
|
+
if get_db().sql('SELECT id FROM "Chat Attachment" WHERE id = ? AND session_id = ? AND user_id = ?',
|
|
2251
|
+
[attachment_id, session_id, user_id]):
|
|
2252
|
+
return {"error": "The attachment is listed in this chat, but its stored file is missing."}
|
|
2250
2253
|
return {"error": "Attachment not found or access denied."}
|
|
2251
2254
|
att = atts[0]
|
|
2252
2255
|
return {
|
|
@@ -1624,6 +1624,7 @@ class Database:
|
|
|
1624
1624
|
mime_type TEXT NOT NULL,
|
|
1625
1625
|
size_bytes INTEGER NOT NULL,
|
|
1626
1626
|
file_path TEXT NOT NULL,
|
|
1627
|
+
data BLOB,
|
|
1627
1628
|
openai_file_id TEXT,
|
|
1628
1629
|
openai_file_expires_at INTEGER,
|
|
1629
1630
|
created_at TEXT DEFAULT CURRENT_TIMESTAMP,
|
|
@@ -3779,6 +3780,10 @@ def _m042_record_notes(db: "Database") -> None:
|
|
|
3779
3780
|
db.conn.commit()
|
|
3780
3781
|
|
|
3781
3782
|
|
|
3783
|
+
def _m069_chat_attachment_data(db: "Database") -> None:
|
|
3784
|
+
db._add_column_if_missing("Chat Attachment", "data", "BLOB")
|
|
3785
|
+
|
|
3786
|
+
|
|
3782
3787
|
Database.MIGRATIONS = [
|
|
3783
3788
|
(1, "chat_message_session_id", _m001_chat_message_session_id),
|
|
3784
3789
|
(2, "chat_session_user_id", _m002_chat_session_user_id),
|
|
@@ -3848,6 +3853,7 @@ Database.MIGRATIONS = [
|
|
|
3848
3853
|
(66, "attachment_sensitivity", _m066_attachment_sensitivity),
|
|
3849
3854
|
(67, "item_units", _m067_item_units),
|
|
3850
3855
|
(68, "units_completed", _m068_units_completed),
|
|
3856
|
+
(69, "chat_attachment_data", _m069_chat_attachment_data),
|
|
3851
3857
|
]
|
|
3852
3858
|
|
|
3853
3859
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|