Fixing the owui-kb-files
This commit is contained in:
@@ -547,8 +547,53 @@ PY
|
||||
_require "OPENWEBUI_API_KEY" "$OPENWEBUI_API_KEY"
|
||||
KB_ID="$(_kb_id_by_name "$kb_name")"
|
||||
if [ -z "$KB_ID" ]; then echo "KB '$kb_name' not found"; exit 1; fi
|
||||
curl -sS -H "Authorization: Bearer $OPENWEBUI_API_KEY" \
|
||||
"$(_owui_url)/api/v1/knowledge/$KB_ID/files" | ppjson
|
||||
|
||||
# First, fetch the KB object (includes files array in many OWUI versions)
|
||||
tmp_body="$(_mktemp)"; tmp_code="$(_mktemp)"
|
||||
curl -sS $CURL_TMO -H "Authorization: Bearer $OPENWEBUI_API_KEY" \
|
||||
-w "%{http_code}" --output "$tmp_body" \
|
||||
"$(_owui_url)/api/v1/knowledge/$KB_ID" >"$tmp_code" || true
|
||||
http_code="$(cat "$tmp_code" 2>/dev/null || echo 0)"
|
||||
body="$(cat "$tmp_body" 2>/dev/null || echo '')"
|
||||
rm -f "$tmp_code"
|
||||
|
||||
if [ "$http_code" = "200" ] && [ -n "$body" ]; then
|
||||
# Try to extract and pretty-print just the files array if present
|
||||
if command -v python3 >/dev/null 2>&1; then
|
||||
python3 - <<'PY' 2>/dev/null || echo "$body" | ppjson
|
||||
import sys, json
|
||||
d = json.loads(sys.stdin.read())
|
||||
files = d.get("files")
|
||||
if files is None and isinstance(d.get("data"), dict):
|
||||
# some versions pack file_ids under data.file_ids (UUIDs only)
|
||||
fids = d["data"].get("file_ids") or []
|
||||
files = [{"id": fid} for fid in fids]
|
||||
if files is None:
|
||||
raise SystemExit(1)
|
||||
print(json.dumps(files, indent=2))
|
||||
PY
|
||||
else
|
||||
echo "$body" | ppjson
|
||||
fi
|
||||
rm -f "$tmp_body"
|
||||
;;
|
||||
fi
|
||||
|
||||
# Fallback to /files endpoint if the KB object route didn't yield JSON files
|
||||
tmp_code2="$(_mktemp)"
|
||||
curl -sS $CURL_TMO -H "Authorization: Bearer $OPENWEBUI_API_KEY" \
|
||||
-w "%{http_code}" --output "$tmp_body" \
|
||||
"$(_owui_url)/api/v1/knowledge/$KB_ID/files" >"$tmp_code2" || true
|
||||
http_code2="$(cat "$tmp_code2" 2>/dev/null || echo 0)"
|
||||
body2="$(cat "$tmp_body" 2>/dev/null || echo '')"
|
||||
rm -f "$tmp_body" "$tmp_code2"
|
||||
|
||||
if [ "$http_code2" = "200" ] && [ -n "$body2" ]; then
|
||||
echo "$body2" | ppjson
|
||||
else
|
||||
echo "Failed to fetch KB files (HTTP $http_code / $http_code2)" >&2
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
|
||||
owui-kb-debug)
|
||||
|
Reference in New Issue
Block a user