Zeige die Zusatzfelder in der Trefferliste und erkenne Vorschaubilder am Inhalt statt am Antwort-Header.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2f7de33049
commit
38406d3293
4 files changed
+89
-10
No files matched your search
+40
-4
@@ -437,6 +437,7 @@ def paperless_documents(conn, owner_id: UUID, query: str, connector_id: UUID | N
|
||||
"document_type": _named(doc.get("document_type"), names["document_types"]),
|
||||
"storage_path": _named(doc.get("storage_path"), names["storage_paths"]),
|
||||
"tags": [name for name in (_named(tag, names["tags"]) for tag in doc.get("tags") or []) if name][:12],
|
||||
"custom_fields": _custom_display(doc.get("custom_fields"), names["custom_fields"]),
|
||||
"pages": pages if isinstance(pages, int) and pages > 0 else None,
|
||||
"asn": asn if isinstance(asn, int) else None,
|
||||
"snippet": _snippet(doc, terms),
|
||||
@@ -508,11 +509,19 @@ def paperless_thumbnail(conn, owner_id: UUID, document_id: str, connector_id: UU
|
||||
assert_still_owned(conn, row["id"], owner_id)
|
||||
if fetched is None:
|
||||
raise not_found()
|
||||
data, media, _name = fetched
|
||||
# Raster pictures only. A vector file could carry markup.
|
||||
data, header, _name = fetched
|
||||
return data, _thumbnail_media(data, header)
|
||||
|
||||
|
||||
def _thumbnail_media(data: bytes, header: str) -> str:
|
||||
"""Raster pictures only, told by their bytes. A vector file could carry markup, a header can be wrong."""
|
||||
try:
|
||||
media = sniff(data)
|
||||
except Problem:
|
||||
media = "image/gif" if data[:4] == b"GIF8" else ""
|
||||
if media not in _THUMBNAIL_MEDIA:
|
||||
raise unprocessable("Paperless hat kein Vorschaubild geliefert.")
|
||||
return data, media
|
||||
raise unprocessable(f"Paperless hat kein Vorschaubild geliefert (Antworttyp {header or 'unbekannt'}).")
|
||||
return media
|
||||
|
||||
|
||||
_LOOKUP_TTL = 60.0
|
||||
@@ -576,6 +585,33 @@ def _paperless_names_or_none(base: str, token: str, path: str) -> list[dict]:
|
||||
return []
|
||||
|
||||
|
||||
_CUSTOM_SHOWN = 8
|
||||
|
||||
|
||||
def _custom_display(values, fields: list[dict]) -> list[dict]:
|
||||
"""The custom fields of a hit as name, type and readable value. Empty values and unknown fields are left out."""
|
||||
if not isinstance(values, list):
|
||||
return []
|
||||
known = {field["id"]: field for field in fields}
|
||||
shown = []
|
||||
for entry in values:
|
||||
if not isinstance(entry, dict):
|
||||
continue
|
||||
field = known.get(str(entry.get("field")))
|
||||
value = entry.get("value")
|
||||
if field is None or value is None or value == "" or isinstance(value, list):
|
||||
continue
|
||||
if field["type"] == "boolean":
|
||||
text = "Ja" if value else "Nein"
|
||||
elif field["type"] == "select":
|
||||
text = next((option["name"] for option in field["options"] if option["id"] == str(value)), "")
|
||||
else:
|
||||
text = str(value)
|
||||
if text:
|
||||
shown.append({"name": field["name"], "type": field["type"], "value": text[:200]})
|
||||
return shown[:_CUSTOM_SHOWN]
|
||||
|
||||
|
||||
def _named(value, entries: list[dict]) -> str | None:
|
||||
if value is None or isinstance(value, bool):
|
||||
return None
|
||||
|
||||
Reference in new issue
Block a user