mirror of
https://github.com/open-webui/open-webui
synced 2024-12-28 06:42:47 +00:00
enh: channel delete
This commit is contained in:
parent
7ad8918cd9
commit
4c756b5501
@ -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
|
# GetChannelMessages
|
||||||
############################
|
############################
|
||||||
|
@ -134,6 +134,37 @@ export const updateChannelById = async (token: string = '', channel_id: string,
|
|||||||
return res;
|
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) => {
|
export const getChannelMessages = async (token: string = '', channel_id: string, page: number = 1) => {
|
||||||
let error = null;
|
let error = null;
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
bind:show={showEditChannelModal}
|
bind:show={showEditChannelModal}
|
||||||
{channel}
|
{channel}
|
||||||
edit={true}
|
edit={true}
|
||||||
|
{onUpdate}
|
||||||
onSubmit={async ({ name, access_control }) => {
|
onSubmit={async ({ name, access_control }) => {
|
||||||
const res = await updateChannelById(localStorage.token, channel.id, {
|
const res = await updateChannelById(localStorage.token, channel.id, {
|
||||||
name,
|
name,
|
||||||
|
@ -1,16 +1,19 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { getContext, createEventDispatcher, onMount } from 'svelte';
|
import { getContext, createEventDispatcher, onMount } from 'svelte';
|
||||||
import { createNewChannel } from '$lib/apis/channels';
|
import { createNewChannel, deleteChannelById } from '$lib/apis/channels';
|
||||||
|
|
||||||
import Modal from '$lib/components/common/Modal.svelte';
|
import Modal from '$lib/components/common/Modal.svelte';
|
||||||
import AccessControl from '$lib/components/workspace/common/AccessControl.svelte';
|
import AccessControl from '$lib/components/workspace/common/AccessControl.svelte';
|
||||||
import DeleteConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
|
import DeleteConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
|
||||||
|
|
||||||
import { toast } from 'svelte-sonner';
|
import { toast } from 'svelte-sonner';
|
||||||
|
import { page } from '$app/stores';
|
||||||
|
import { goto } from '$app/navigation';
|
||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
export let show = false;
|
export let show = false;
|
||||||
export let onSubmit: Function = () => {};
|
export let onSubmit: Function = () => {};
|
||||||
|
export let onUpdate: Function = () => {};
|
||||||
|
|
||||||
export let channel = null;
|
export let channel = null;
|
||||||
export let edit = false;
|
export let edit = false;
|
||||||
@ -47,6 +50,20 @@
|
|||||||
|
|
||||||
const deleteHandler = async () => {
|
const deleteHandler = async () => {
|
||||||
showDeleteConfirmDialog = false;
|
showDeleteConfirmDialog = false;
|
||||||
|
|
||||||
|
const res = await deleteChannelById(localStorage.token, channel.id).catch((error) => {
|
||||||
|
toast.error(error.message);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
toast.success('Channel deleted successfully');
|
||||||
|
onUpdate();
|
||||||
|
|
||||||
|
if ($page.url.pathname === `/channels/${channel.id}`) {
|
||||||
|
goto('/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
show = false;
|
show = false;
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user