mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 04:15:25 +00:00
enh: add folder modal
This commit is contained in:
parent
a638a187bb
commit
1159f3a781
5 changed files with 35 additions and 16 deletions
|
|
@ -63,7 +63,7 @@ class FolderForm(BaseModel):
|
||||||
|
|
||||||
class FolderTable:
|
class FolderTable:
|
||||||
def insert_new_folder(
|
def insert_new_folder(
|
||||||
self, user_id: str, name: str, parent_id: Optional[str] = None
|
self, user_id: str, form_data: FolderForm, parent_id: Optional[str] = None
|
||||||
) -> Optional[FolderModel]:
|
) -> Optional[FolderModel]:
|
||||||
with get_db() as db:
|
with get_db() as db:
|
||||||
id = str(uuid.uuid4())
|
id = str(uuid.uuid4())
|
||||||
|
|
@ -71,7 +71,7 @@ class FolderTable:
|
||||||
**{
|
**{
|
||||||
"id": id,
|
"id": id,
|
||||||
"user_id": user_id,
|
"user_id": user_id,
|
||||||
"name": name,
|
**(form_data.model_dump(exclude_unset=True) or {}),
|
||||||
"parent_id": parent_id,
|
"parent_id": parent_id,
|
||||||
"created_at": int(time.time()),
|
"created_at": int(time.time()),
|
||||||
"updated_at": int(time.time()),
|
"updated_at": int(time.time()),
|
||||||
|
|
|
||||||
|
|
@ -78,7 +78,7 @@ def create_folder(form_data: FolderForm, user=Depends(get_verified_user)):
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
folder = Folders.insert_new_folder(user.id, form_data.name)
|
folder = Folders.insert_new_folder(user.id, form_data)
|
||||||
return folder
|
return folder
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.exception(e)
|
log.exception(e)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,11 @@
|
||||||
import { WEBUI_API_BASE_URL } from '$lib/constants';
|
import { WEBUI_API_BASE_URL } from '$lib/constants';
|
||||||
|
|
||||||
export const createNewFolder = async (token: string, name: string) => {
|
type FolderForm = {
|
||||||
|
name: string;
|
||||||
|
data?: Record<string, any>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const createNewFolder = async (token: string, folderForm: FolderForm) => {
|
||||||
let error = null;
|
let error = null;
|
||||||
|
|
||||||
const res = await fetch(`${WEBUI_API_BASE_URL}/folders/`, {
|
const res = await fetch(`${WEBUI_API_BASE_URL}/folders/`, {
|
||||||
|
|
@ -10,9 +15,7 @@ export const createNewFolder = async (token: string, name: string) => {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
authorization: `Bearer ${token}`
|
authorization: `Bearer ${token}`
|
||||||
},
|
},
|
||||||
body: JSON.stringify({
|
body: JSON.stringify(folderForm)
|
||||||
name: name
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
.then(async (res) => {
|
.then(async (res) => {
|
||||||
if (!res.ok) throw await res.json();
|
if (!res.ok) throw await res.json();
|
||||||
|
|
@ -92,11 +95,6 @@ export const getFolderById = async (token: string, id: string) => {
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
type FolderForm = {
|
|
||||||
name: string;
|
|
||||||
data?: Record<string, any>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const updateFolderById = async (token: string, id: string, folderForm: FolderForm) => {
|
export const updateFolderById = async (token: string, id: string, folderForm: FolderForm) => {
|
||||||
let error = null;
|
let error = null;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@
|
||||||
import Home from '../icons/Home.svelte';
|
import Home from '../icons/Home.svelte';
|
||||||
import Search from '../icons/Search.svelte';
|
import Search from '../icons/Search.svelte';
|
||||||
import SearchModal from './SearchModal.svelte';
|
import SearchModal from './SearchModal.svelte';
|
||||||
|
import FolderModal from './Sidebar/Folders/FolderModal.svelte';
|
||||||
|
|
||||||
const BREAKPOINT = 768;
|
const BREAKPOINT = 768;
|
||||||
|
|
||||||
|
|
@ -74,6 +75,7 @@
|
||||||
let chatListLoading = false;
|
let chatListLoading = false;
|
||||||
let allChatsLoaded = false;
|
let allChatsLoaded = false;
|
||||||
|
|
||||||
|
let showCreateFolderModal = false;
|
||||||
let folders = {};
|
let folders = {};
|
||||||
let newFolderId = null;
|
let newFolderId = null;
|
||||||
|
|
||||||
|
|
@ -117,7 +119,7 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const createFolder = async (name = 'Untitled') => {
|
const createFolder = async ({ name, data }) => {
|
||||||
if (name === '') {
|
if (name === '') {
|
||||||
toast.error($i18n.t('Folder name cannot be empty.'));
|
toast.error($i18n.t('Folder name cannot be empty.'));
|
||||||
return;
|
return;
|
||||||
|
|
@ -148,13 +150,16 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const res = await createNewFolder(localStorage.token, name).catch((error) => {
|
const res = await createNewFolder(localStorage.token, {
|
||||||
|
name,
|
||||||
|
data
|
||||||
|
}).catch((error) => {
|
||||||
toast.error(`${error}`);
|
toast.error(`${error}`);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
newFolderId = res.id;
|
// newFolderId = res.id;
|
||||||
await initFolders();
|
await initFolders();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -429,6 +434,14 @@
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<FolderModal
|
||||||
|
bind:show={showCreateFolderModal}
|
||||||
|
onSubmit={async (folder) => {
|
||||||
|
await createFolder(folder);
|
||||||
|
showCreateFolderModal = false;
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
||||||
|
|
||||||
{#if $showSidebar}
|
{#if $showSidebar}
|
||||||
|
|
@ -732,7 +745,7 @@
|
||||||
className="px-2 mt-0.5"
|
className="px-2 mt-0.5"
|
||||||
name={$i18n.t('Chats')}
|
name={$i18n.t('Chats')}
|
||||||
onAdd={() => {
|
onAdd={() => {
|
||||||
createFolder();
|
showCreateFolderModal = true;
|
||||||
}}
|
}}
|
||||||
onAddLabel={$i18n.t('New Folder')}
|
onAddLabel={$i18n.t('New Folder')}
|
||||||
on:change={async (e) => {
|
on:change={async (e) => {
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,14 @@
|
||||||
$: if (folder) {
|
$: if (folder) {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$: if (!show && !edit) {
|
||||||
|
name = '';
|
||||||
|
data = {
|
||||||
|
system_prompt: '',
|
||||||
|
files: []
|
||||||
|
};
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Modal size="md" bind:show>
|
<Modal size="md" bind:show>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue