From b85c6ef667ff06be1dfc4f110224250f992c2c7d Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Fri, 1 Mar 2024 23:32:06 -0800 Subject: [PATCH 01/22] fix: ol display issue #963 --- src/app.css | 15 +++++++++++++++ .../chat/Messages/ResponseMessage.svelte | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/app.css b/src/app.css index 091db396..95605a09 100644 --- a/src/app.css +++ b/src/app.css @@ -28,6 +28,21 @@ math { @apply rounded-lg; } +ol > li { + counter-increment: list-number; + display: block; + margin-bottom: 0; + margin-top: 0; + min-height: 28px; +} + +ol > li::before { + content: counters(list-number, '.') '.'; + padding-right: 0.5rem; + color: var(--tw-prose-counters); + font-weight: 400; +} + ::-webkit-scrollbar-thumb { --tw-border-opacity: 1; background-color: rgba(217, 217, 227, 0.8); diff --git a/src/lib/components/chat/Messages/ResponseMessage.svelte b/src/lib/components/chat/Messages/ResponseMessage.svelte index 69b301e3..25426965 100644 --- a/src/lib/components/chat/Messages/ResponseMessage.svelte +++ b/src/lib/components/chat/Messages/ResponseMessage.svelte @@ -334,7 +334,7 @@ {/if}
{#if edit === true} From a12b5ffab3d4f0aaa058723bd5e84943c9ff5a79 Mon Sep 17 00:00:00 2001 From: Han Cen Date: Sat, 2 Mar 2024 15:38:14 +0800 Subject: [PATCH 02/22] Fix enable signup env --- backend/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/config.py b/backend/config.py index effcd246..df24b97e 100644 --- a/backend/config.py +++ b/backend/config.py @@ -226,7 +226,7 @@ if OPENAI_API_BASE_URL == "": # WEBUI #################################### -ENABLE_SIGNUP = os.environ.get("ENABLE_SIGNUP", True) +ENABLE_SIGNUP = os.environ.get("ENABLE_SIGNUP", "True").lower() == "true" DEFAULT_MODELS = os.environ.get("DEFAULT_MODELS", None) From a4c6a8d5a4697e5ee5fbab2d407f5e9f3584f6a5 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 2 Mar 2024 00:05:25 -0800 Subject: [PATCH 03/22] fix: sonner toast styling issue --- src/app.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app.css b/src/app.css index 95605a09..63b34465 100644 --- a/src/app.css +++ b/src/app.css @@ -36,7 +36,7 @@ ol > li { min-height: 28px; } -ol > li::before { +.prose ol > li::before { content: counters(list-number, '.') '.'; padding-right: 0.5rem; color: var(--tw-prose-counters); From 74809e733037412081de691b4b4f7f7b4576bb0f Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 2 Mar 2024 00:07:50 -0800 Subject: [PATCH 04/22] fix: user chat delete loophole --- backend/apps/web/routers/chats.py | 12 +++++++++++- src/lib/apis/chats/index.ts | 2 +- src/lib/components/chat/Settings/Chats.svelte | 4 +++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/backend/apps/web/routers/chats.py b/backend/apps/web/routers/chats.py index 1ce537ec..0c0ac1ce 100644 --- a/backend/apps/web/routers/chats.py +++ b/backend/apps/web/routers/chats.py @@ -271,6 +271,16 @@ async def delete_all_chat_tags_by_id(id: str, user=Depends(get_current_user)): @router.delete("/", response_model=bool) -async def delete_all_user_chats(user=Depends(get_current_user)): +async def delete_all_user_chats(request: Request, user=Depends(get_current_user)): + + if ( + user.role == "user" + and not request.app.state.USER_PERMISSIONS["chat"]["deletion"] + ): + raise HTTPException( + status_code=status.HTTP_401_UNAUTHORIZED, + detail=ERROR_MESSAGES.ACCESS_PROHIBITED, + ) + result = Chats.delete_chats_by_user_id(user.id) return result diff --git a/src/lib/apis/chats/index.ts b/src/lib/apis/chats/index.ts index aadf3769..35b259d5 100644 --- a/src/lib/apis/chats/index.ts +++ b/src/lib/apis/chats/index.ts @@ -439,7 +439,7 @@ export const deleteAllChats = async (token: string) => { return json; }) .catch((err) => { - error = err; + error = err.detail; console.log(err); return null; diff --git a/src/lib/components/chat/Settings/Chats.svelte b/src/lib/components/chat/Settings/Chats.svelte index bab3acc7..e13689f5 100644 --- a/src/lib/components/chat/Settings/Chats.svelte +++ b/src/lib/components/chat/Settings/Chats.svelte @@ -75,7 +75,9 @@ const deleteChats = async () => { await goto('/'); - await deleteAllChats(localStorage.token); + await deleteAllChats(localStorage.token).catch((error) => { + toast.error(error); + }); await chats.set(await getChatList(localStorage.token)); }; From 6d854125cc923a6e348520921f695c5c1131c1e3 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 2 Mar 2024 00:19:24 -0800 Subject: [PATCH 05/22] refac: ollama.db renamed to webui.db --- backend/apps/web/internal/db.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/backend/apps/web/internal/db.py b/backend/apps/web/internal/db.py index 1f8c3bf7..d0aa9969 100644 --- a/backend/apps/web/internal/db.py +++ b/backend/apps/web/internal/db.py @@ -1,6 +1,16 @@ from peewee import * from config import DATA_DIR +import os -DB = SqliteDatabase(f"{DATA_DIR}/ollama.db") +# Check if the file exists +if os.path.exists(f"{DATA_DIR}/ollama.db"): + # Rename the file + os.rename(f"{DATA_DIR}/ollama.db", f"{DATA_DIR}/webui.db") + print("File renamed successfully.") +else: + pass + + +DB = SqliteDatabase(f"{DATA_DIR}/webui.db") DB.connect() From edb63c22808f5d1ccf511380cae8eabe5f8e5f9b Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 2 Mar 2024 00:33:20 -0800 Subject: [PATCH 06/22] feat: download db from admin settings --- backend/apps/web/routers/utils.py | 15 ++++- src/lib/apis/utils/index.ts | 32 ++++++++++ .../components/admin/Settings/Database.svelte | 63 +++++++++++++++++++ src/lib/components/admin/SettingsModal.svelte | 35 +++++++++++ 4 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 src/lib/components/admin/Settings/Database.svelte diff --git a/backend/apps/web/routers/utils.py b/backend/apps/web/routers/utils.py index 86e1a9e5..6356bf45 100644 --- a/backend/apps/web/routers/utils.py +++ b/backend/apps/web/routers/utils.py @@ -1,6 +1,7 @@ from fastapi import APIRouter, UploadFile, File, BackgroundTasks from fastapi import Depends, HTTPException, status -from starlette.responses import StreamingResponse +from starlette.responses import StreamingResponse, FileResponse + from pydantic import BaseModel @@ -9,6 +10,8 @@ import os import aiohttp import json + +from utils.utils import get_admin_user from utils.misc import calculate_sha256, get_gravatar_url from config import OLLAMA_API_BASE_URL, DATA_DIR, UPLOAD_DIR @@ -172,3 +175,13 @@ async def get_gravatar( email: str, ): return get_gravatar_url(email) + + +@router.get("/db/download") +async def download_db(user=Depends(get_admin_user)): + + return FileResponse( + f"{DATA_DIR}/webui.db", + media_type="application/octet-stream", + filename="webui.db", + ) diff --git a/src/lib/apis/utils/index.ts b/src/lib/apis/utils/index.ts index ed4d4e02..bcb55407 100644 --- a/src/lib/apis/utils/index.ts +++ b/src/lib/apis/utils/index.ts @@ -21,3 +21,35 @@ export const getGravatarUrl = async (email: string) => { return res; }; + +export const downloadDatabase = async (token: string) => { + let error = null; + + const res = await fetch(`${WEBUI_API_BASE_URL}/utils/db/download`, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + Authorization: `Bearer ${token}` + } + }) + .then((response) => { + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return response.blob(); + }) + .then((blob) => { + const url = window.URL.createObjectURL(blob); + const a = document.createElement('a'); + a.href = url; + a.download = 'webui.db'; + document.body.appendChild(a); + a.click(); + window.URL.revokeObjectURL(url); + }) + .catch((err) => { + console.log(err); + error = err; + return null; + }); +}; diff --git a/src/lib/components/admin/Settings/Database.svelte b/src/lib/components/admin/Settings/Database.svelte new file mode 100644 index 00000000..1b725c4a --- /dev/null +++ b/src/lib/components/admin/Settings/Database.svelte @@ -0,0 +1,63 @@ + + +
{ + saveHandler(); + }} +> +
+
+
Database
+ +
+ + + +
+
+
+ + +
diff --git a/src/lib/components/admin/SettingsModal.svelte b/src/lib/components/admin/SettingsModal.svelte index 67f6be88..0a3878e0 100644 --- a/src/lib/components/admin/SettingsModal.svelte +++ b/src/lib/components/admin/SettingsModal.svelte @@ -1,5 +1,6 @@ + +
+ +
From f9482275f25490a74978920813d16ad7aeee97d8 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 2 Mar 2024 01:20:50 -0800 Subject: [PATCH 08/22] fix: tooltip --- src/lib/components/common/Tooltip.svelte | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/lib/components/common/Tooltip.svelte b/src/lib/components/common/Tooltip.svelte index fca2b0e8..62ca4eb8 100644 --- a/src/lib/components/common/Tooltip.svelte +++ b/src/lib/components/common/Tooltip.svelte @@ -10,18 +10,19 @@ $: if (tooltipElement && content) { if (tooltipInstance) { - tooltipInstance[0]?.destroy(); + tooltipInstance.setContent(content); + } else { + tooltipInstance = tippy(tooltipElement, { + content: content, + placement: placement, + allowHTML: true + }); } - tooltipInstance = tippy(tooltipElement, { - content: content, - placement: placement, - allowHTML: true - }); } onDestroy(() => { if (tooltipInstance) { - tooltipInstance[0]?.destroy(); + tooltipInstance.destroy(); } }); From 0bc3e0a302409865904a5516fae57a79e076e2ed Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 2 Mar 2024 01:21:00 -0800 Subject: [PATCH 09/22] feat: tooltip added to sidebar --- src/lib/components/layout/Sidebar.svelte | 51 +++++++++++++----------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index 711e4fd6..2f74128b 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -19,6 +19,7 @@ import { toast } from 'svelte-sonner'; import { slide } from 'svelte/transition'; import { WEBUI_BASE_URL } from '$lib/constants'; + import Tooltip from '../common/Tooltip.svelte'; let show = false; let navElement; @@ -670,30 +671,32 @@
- + + +
From b9444d00b37219a82d55069a200c8b54690a4889 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 2 Mar 2024 01:27:01 -0800 Subject: [PATCH 10/22] Update Tooltip.svelte --- src/lib/components/common/Tooltip.svelte | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/components/common/Tooltip.svelte b/src/lib/components/common/Tooltip.svelte index 62ca4eb8..0eabdb6e 100644 --- a/src/lib/components/common/Tooltip.svelte +++ b/src/lib/components/common/Tooltip.svelte @@ -4,6 +4,7 @@ export let placement = 'top'; export let content = `I'm a tooltip!`; + export let touch = true; let tooltipElement; let tooltipInstance; @@ -15,7 +16,8 @@ tooltipInstance = tippy(tooltipElement, { content: content, placement: placement, - allowHTML: true + allowHTML: true, + touch: touch }); } } From 9b86e0bb41ec1a469c7543c52cfd6764dbe03693 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 2 Mar 2024 01:27:34 -0800 Subject: [PATCH 11/22] Update Sidebar.svelte --- src/lib/components/layout/Sidebar.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/components/layout/Sidebar.svelte b/src/lib/components/layout/Sidebar.svelte index 2f74128b..6201e077 100644 --- a/src/lib/components/layout/Sidebar.svelte +++ b/src/lib/components/layout/Sidebar.svelte @@ -671,7 +671,7 @@
- +
Admin Panel
+ + {/if} +
+ + +
+ + + +
+ + +
+
+