diff --git a/backend/open_webui/routers/channels.py b/backend/open_webui/routers/channels.py index df3ccfd51..0a500c710 100644 --- a/backend/open_webui/routers/channels.py +++ b/backend/open_webui/routers/channels.py @@ -78,6 +78,31 @@ async def get_channel_by_id(id: str, user=Depends(get_verified_user)): return ChannelModel(**channel.model_dump()) +############################ +# UpdateChannelById +############################ + + +@router.post("/{id}/update", response_model=Optional[ChannelModel]) +async def update_channel_by_id( + id: str, form_data: ChannelForm, 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: + channel = Channels.update_channel_by_id(id, form_data) + return ChannelModel(**channel.model_dump()) + 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 abc3c2aec..4b662bb85 100644 --- a/src/lib/apis/channels/index.ts +++ b/src/lib/apis/channels/index.ts @@ -102,6 +102,38 @@ export const getChannelById = async (token: string = '', channel_id: string) => return res; } +export const updateChannelById = async (token: string = '', channel_id: string, channel: ChannelForm) => { + let error = null; + + const res = await fetch(`${WEBUI_API_BASE_URL}/channels/${channel_id}/update`, { + method: 'POST', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + authorization: `Bearer ${token}` + }, + body: JSON.stringify({ ...channel }) + }) + .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/channel/Messages.svelte b/src/lib/components/channel/Messages.svelte index a1fde2251..08c975538 100644 --- a/src/lib/components/channel/Messages.svelte +++ b/src/lib/components/channel/Messages.svelte @@ -65,7 +65,7 @@ {($settings?.widescreenMode ?? null) ? 'max-w-full' : 'max-w-5xl'} mx-auto" > {#if channel} -