Bug fix
This commit is contained in:
@@ -239,9 +239,17 @@ print(f\"Indexed {n} document(s).\")"
|
|||||||
if [ -z "$file" ] || [ ! -f "$file" ]; then echo "Usage: owui-upload </abs/path/file>" >&2; exit 1; fi
|
if [ -z "$file" ] || [ ! -f "$file" ]; then echo "Usage: owui-upload </abs/path/file>" >&2; exit 1; fi
|
||||||
_require "OPENWEBUI_URL" "$OPENWEBUI_URL"
|
_require "OPENWEBUI_URL" "$OPENWEBUI_URL"
|
||||||
_require "OPENWEBUI_API_KEY" "$OPENWEBUI_API_KEY"
|
_require "OPENWEBUI_API_KEY" "$OPENWEBUI_API_KEY"
|
||||||
curl -sS -H "Authorization: Bearer $OPENWEBUI_API_KEY" \
|
tmp="$(mktemp)"
|
||||||
|
code="$(curl -sS -H "Authorization: Bearer $OPENWEBUI_API_KEY" \
|
||||||
-F "file=@$file" \
|
-F "file=@$file" \
|
||||||
"$(_owui_url)/api/v1/files/" | ppjson
|
-w "%{http_code}" --output "$tmp" \
|
||||||
|
"$(_owui_url)/api/v1/files/" || true)"
|
||||||
|
cat "$tmp" | ppjson
|
||||||
|
rm -f "$tmp"
|
||||||
|
if [ "$code" != "200" ]; then
|
||||||
|
echo "Upload failed (HTTP $code)" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
owui-attach)
|
owui-attach)
|
||||||
@@ -252,15 +260,34 @@ print(f\"Indexed {n} document(s).\")"
|
|||||||
fi
|
fi
|
||||||
_require "OPENWEBUI_URL" "$OPENWEBUI_URL"
|
_require "OPENWEBUI_URL" "$OPENWEBUI_URL"
|
||||||
_require "OPENWEBUI_API_KEY" "$OPENWEBUI_API_KEY"
|
_require "OPENWEBUI_API_KEY" "$OPENWEBUI_API_KEY"
|
||||||
FILE_JSON="$(curl -sS -H "Authorization: Bearer $OPENWEBUI_API_KEY" -F "file=@$file" "$(_owui_url)/api/v1/files/")"
|
tmp_up="$(mktemp)"
|
||||||
|
code_up="$(curl -sS -H "Authorization: Bearer $OPENWEBUI_API_KEY" \
|
||||||
|
-F "file=@$file" \
|
||||||
|
-w "%{http_code}" --output "$tmp_up" \
|
||||||
|
"$(_owui_url)/api/v1/files/" || true)"
|
||||||
|
FILE_JSON="$(cat "$tmp_up")"
|
||||||
|
rm -f "$tmp_up"
|
||||||
|
if [ "$code_up" != "200" ]; then
|
||||||
|
echo "Upload failed (HTTP $code_up)" >&2
|
||||||
|
echo "$FILE_JSON" | ppjson
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
FILE_ID="$(python3 -c 'import sys,json; d=json.loads(sys.stdin.read()); print(d.get("id") or (d.get("data") or {}).get("id",""))' <<<"$FILE_JSON")"
|
FILE_ID="$(python3 -c 'import sys,json; d=json.loads(sys.stdin.read()); print(d.get("id") or (d.get("data") or {}).get("id",""))' <<<"$FILE_JSON")"
|
||||||
if [ -z "$FILE_ID" ]; then echo "Upload failed (no file id)"; echo "$FILE_JSON" | ppjson; exit 1; fi
|
if [ -z "$FILE_ID" ]; then echo "Upload failed (no file id)"; echo "$FILE_JSON" | ppjson; exit 1; fi
|
||||||
KB_ID="$(_kb_id_by_name "$kb_name")"
|
KB_ID="$(_kb_id_by_name "$kb_name")"
|
||||||
if [ -z "$KB_ID" ]; then echo "KB '$kb_name' not found"; exit 1; fi
|
if [ -z "$KB_ID" ]; then echo "KB '$kb_name' not found"; exit 1; fi
|
||||||
RESP="$(curl -sS -H "Authorization: Bearer $OPENWEBUI_API_KEY" -H "Content-Type: application/json" \
|
tmp_att="$(mktemp)"
|
||||||
|
code_att="$(curl -sS -H "Authorization: Bearer $OPENWEBUI_API_KEY" -H "Content-Type: application/json" \
|
||||||
-d "{\"file_id\":\"$FILE_ID\"}" \
|
-d "{\"file_id\":\"$FILE_ID\"}" \
|
||||||
"$(_owui_url)/api/v1/knowledge/$KB_ID/file/add")"
|
-w "%{http_code}" --output "$tmp_att" \
|
||||||
|
"$(_owui_url)/api/v1/knowledge/$KB_ID/file/add" || true)"
|
||||||
|
RESP="$(cat "$tmp_att")"
|
||||||
|
rm -f "$tmp_att"
|
||||||
echo "$RESP" | ppjson
|
echo "$RESP" | ppjson
|
||||||
|
if [ "$code_att" != "200" ]; then
|
||||||
|
echo "Attach failed (HTTP $code_att)" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
owui-kb-files)
|
owui-kb-files)
|
||||||
@@ -291,13 +318,31 @@ print(f\"Indexed {n} document(s).\")"
|
|||||||
if [ ${#matched[@]} -eq 0 ]; then echo "No files match: $glob_pat"; exit 1; fi
|
if [ ${#matched[@]} -eq 0 ]; then echo "No files match: $glob_pat"; exit 1; fi
|
||||||
for f in "${matched[@]}"; do
|
for f in "${matched[@]}"; do
|
||||||
echo "[owui] uploading: $f"
|
echo "[owui] uploading: $f"
|
||||||
FILE_JSON="$(curl -sS -H "Authorization: Bearer $OPENWEBUI_API_KEY" -F "file=@$f" "$(_owui_url)/api/v1/files/")"
|
tmp_up="$(mktemp)"
|
||||||
|
code_up="$(curl -sS -H "Authorization: Bearer $OPENWEBUI_API_KEY" \
|
||||||
|
-F "file=@$f" \
|
||||||
|
-w "%{http_code}" --output "$tmp_up" \
|
||||||
|
"$(_owui_url)/api/v1/files/" || true)"
|
||||||
|
FILE_JSON="$(cat "$tmp_up")"
|
||||||
|
rm -f "$tmp_up"
|
||||||
|
if [ "$code_up" != "200" ]; then
|
||||||
|
echo " upload failed (HTTP $code_up), skipping"
|
||||||
|
echo "$FILE_JSON" | ppjson
|
||||||
|
continue
|
||||||
|
fi
|
||||||
FILE_ID="$(python3 -c 'import sys,json; d=json.loads(sys.stdin.read()); print(d.get("id") or (d.get("data") or {}).get("id",""))' <<<"$FILE_JSON")"
|
FILE_ID="$(python3 -c 'import sys,json; d=json.loads(sys.stdin.read()); print(d.get("id") or (d.get("data") or {}).get("id",""))' <<<"$FILE_JSON")"
|
||||||
if [ -z "$FILE_ID" ]; then echo " upload failed, skipping"; continue; fi
|
if [ -z "$FILE_ID" ]; then echo " upload failed (no id), skipping"; echo "$FILE_JSON" | ppjson; continue; fi
|
||||||
RESP="$(curl -sS -H "Authorization: Bearer $OPENWEBUI_API_KEY" -H "Content-Type: application/json" \
|
tmp_att="$(mktemp)"
|
||||||
|
code_att="$(curl -sS -H "Authorization: Bearer $OPENWEBUI_API_KEY" -H "Content-Type: application/json" \
|
||||||
-d "{\"file_id\":\"$FILE_ID\"}" \
|
-d "{\"file_id\":\"$FILE_ID\"}" \
|
||||||
"$(_owui_url)/api/v1/knowledge/$KB_ID/file/add")"
|
-w "%{http_code}" --output "$tmp_att" \
|
||||||
|
"$(_owui_url)/api/v1/knowledge/$KB_ID/file/add" || true)"
|
||||||
|
RESP="$(cat "$tmp_att")"
|
||||||
|
rm -f "$tmp_att"
|
||||||
echo "$RESP" | ppjson
|
echo "$RESP" | ppjson
|
||||||
|
if [ "$code_att" != "200" ]; then
|
||||||
|
echo " attach failed (HTTP $code_att)"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user