diff --git a/backend/open_webui/routers/channels.py b/backend/open_webui/routers/channels.py index 0a500c710..2cc093e36 100644 --- a/backend/open_webui/routers/channels.py +++ b/backend/open_webui/routers/channels.py @@ -103,6 +103,29 @@ async def update_channel_by_id( ) +############################ +# DeleteChannelById +############################ + + +@router.delete("/{id}/delete", response_model=bool) +async def delete_channel_by_id(id: str, user=Depends(get_admin_user)): + channel = Channels.get_channel_by_id(id) + if not channel: + raise HTTPException( + status_code=status.HTTP_404_NOT_FOUND, detail=ERROR_MESSAGES.NOT_FOUND + ) + + try: + Channels.delete_channel_by_id(id) + return True + except Exception as e: + log.exception(e) + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, detail=ERROR_MESSAGES.DEFAULT() + ) + + ############################ # GetChannelMessages ############################ diff --git a/src/lib/apis/channels/index.ts b/src/lib/apis/channels/index.ts index 4b662bb85..5fe3e6452 100644 --- a/src/lib/apis/channels/index.ts +++ b/src/lib/apis/channels/index.ts @@ -134,6 +134,37 @@ export const updateChannelById = async (token: string = '', channel_id: string, return res; } +export const deleteChannelById = async (token: string = '', channel_id: string) => { + let error = null; + + const res = await fetch(`${WEBUI_API_BASE_URL}/channels/${channel_id}/delete`, { + method: 'DELETE', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + authorization: `Bearer ${token}` + } + }) + .then(async (res) => { + if (!res.ok) throw await res.json(); + return res.json(); + }) + .then((json) => { + return json; + }) + .catch((err) => { + error = err.detail; + console.log(err); + return null; + }); + + if (error) { + throw error; + } + + return res; +} + export const getChannelMessages = async (token: string = '', channel_id: string, page: number = 1) => { let error = null; diff --git a/src/lib/components/layout/Sidebar/ChannelItem.svelte b/src/lib/components/layout/Sidebar/ChannelItem.svelte index 6e4e8c62f..b4fff5141 100644 --- a/src/lib/components/layout/Sidebar/ChannelItem.svelte +++ b/src/lib/components/layout/Sidebar/ChannelItem.svelte @@ -24,6 +24,7 @@ bind:show={showEditChannelModal} {channel} edit={true} + {onUpdate} onSubmit={async ({ name, access_control }) => { const res = await updateChannelById(localStorage.token, channel.id, { name, diff --git a/src/lib/components/layout/Sidebar/ChannelModal.svelte b/src/lib/components/layout/Sidebar/ChannelModal.svelte index e0ccc58bb..ec229bc50 100644 --- a/src/lib/components/layout/Sidebar/ChannelModal.svelte +++ b/src/lib/components/layout/Sidebar/ChannelModal.svelte @@ -1,16 +1,19 @@