refac
This commit is contained in:
1 parent
caedcbae49
commit
ed4cb358a0
5 files changed
+68
-31
No files matched your search
@@ -35,6 +35,8 @@
|
|||||||
|
|
||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
|
$: canImportChats = $user?.role === 'admin' || ($user?.permissions?.chat?.import ?? true);
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getChatList,
|
getChatList,
|
||||||
getAllTags,
|
getAllTags,
|
||||||
@@ -372,6 +374,11 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const importChatHandler = async (items, pinned = false, folderId = null) => {
|
const importChatHandler = async (items, pinned = false, folderId = null) => {
|
||||||
|
if (!canImportChats) {
|
||||||
|
toast.error($i18n.t('Access prohibited'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
console.log('importChatHandler', items, pinned, folderId);
|
console.log('importChatHandler', items, pinned, folderId);
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
console.log(item);
|
console.log(item);
|
||||||
@@ -1401,6 +1408,11 @@
|
|||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
if (!chat && item) {
|
if (!chat && item) {
|
||||||
|
if (!canImportChats) {
|
||||||
|
toast.error($i18n.t('Access prohibited'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
chat = await importChats(localStorage.token, [
|
chat = await importChats(localStorage.token, [
|
||||||
{
|
{
|
||||||
chat: item.chat,
|
chat: item.chat,
|
||||||
@@ -1409,9 +1421,9 @@
|
|||||||
folder_id: null,
|
folder_id: null,
|
||||||
created_at: item?.created_at ?? null,
|
created_at: item?.created_at ?? null,
|
||||||
updated_at: item?.updated_at ?? null
|
updated_at: item?.updated_at ?? null
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chat) {
|
if (chat) {
|
||||||
console.log(chat);
|
console.log(chat);
|
||||||
@@ -1467,6 +1479,11 @@
|
|||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
if (!chat && item) {
|
if (!chat && item) {
|
||||||
|
if (!canImportChats) {
|
||||||
|
toast.error($i18n.t('Access prohibited'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
chat = await importChats(localStorage.token, [
|
chat = await importChats(localStorage.token, [
|
||||||
{
|
{
|
||||||
chat: item.chat,
|
chat: item.chat,
|
||||||
|
|||||||
@@ -9,10 +9,6 @@
|
|||||||
import { toast } from 'svelte-sonner';
|
import { toast } from 'svelte-sonner';
|
||||||
import { goto, invalidate, invalidateAll } from '$app/navigation';
|
import { goto, invalidate, invalidateAll } from '$app/navigation';
|
||||||
import { onMount, getContext, createEventDispatcher, tick } from 'svelte';
|
import { onMount, getContext, createEventDispatcher, tick } from 'svelte';
|
||||||
const i18n = getContext('i18n');
|
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
archiveChatById,
|
archiveChatById,
|
||||||
cloneChatById,
|
cloneChatById,
|
||||||
@@ -35,7 +31,8 @@
|
|||||||
currentChatPage,
|
currentChatPage,
|
||||||
tags,
|
tags,
|
||||||
selectedFolder,
|
selectedFolder,
|
||||||
activeChatIds
|
activeChatIds,
|
||||||
|
user
|
||||||
} from '$lib/stores';
|
} from '$lib/stores';
|
||||||
|
|
||||||
import ChatMenu from './ChatMenu.svelte';
|
import ChatMenu from './ChatMenu.svelte';
|
||||||
@@ -53,6 +50,10 @@
|
|||||||
import { generateTitle } from '$lib/apis';
|
import { generateTitle } from '$lib/apis';
|
||||||
import { createMessagesList } from '$lib/utils';
|
import { createMessagesList } from '$lib/utils';
|
||||||
|
|
||||||
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
export let className = '';
|
export let className = '';
|
||||||
|
|
||||||
export let id;
|
export let id;
|
||||||
@@ -143,6 +144,11 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const cloneChatHandler = async (id) => {
|
const cloneChatHandler = async (id) => {
|
||||||
|
if (!($user?.role === 'admin' || ($user?.permissions?.chat?.import ?? true))) {
|
||||||
|
toast.error($i18n.t('Access prohibited'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const res = await cloneChatById(
|
const res = await cloneChatById(
|
||||||
localStorage.token,
|
localStorage.token,
|
||||||
id,
|
id,
|
||||||
|
|||||||
@@ -387,17 +387,19 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<button
|
{#if $user?.role === 'admin' || ($user?.permissions?.chat?.import ?? true)}
|
||||||
draggable="false"
|
<button
|
||||||
class="flex gap-2 items-center px-3 py-1.5 text-sm cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-xl w-full"
|
draggable="false"
|
||||||
on:click={() => {
|
class="flex gap-2 items-center px-3 py-1.5 text-sm cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800 rounded-xl w-full"
|
||||||
show = false;
|
on:click={() => {
|
||||||
cloneChatHandler();
|
show = false;
|
||||||
}}
|
cloneChatHandler();
|
||||||
>
|
}}
|
||||||
<DocumentDuplicate strokeWidth="1.5" />
|
>
|
||||||
<div class="flex items-center">{$i18n.t('Clone')}</div>
|
<DocumentDuplicate strokeWidth="1.5" />
|
||||||
</button>
|
<div class="flex items-center">{$i18n.t('Clone')}</div>
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
|
||||||
{#if chatId && $folders.length > 0}
|
{#if chatId && $folders.length > 0}
|
||||||
<DropdownSub
|
<DropdownSub
|
||||||
|
|||||||
@@ -161,6 +161,11 @@
|
|||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
if (!chat && item) {
|
if (!chat && item) {
|
||||||
|
if (!($user?.role === 'admin' || ($user?.permissions?.chat?.import ?? true))) {
|
||||||
|
toast.error($i18n.t('Access prohibited'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
chat = await importChats(localStorage.token, [
|
chat = await importChats(localStorage.token, [
|
||||||
{
|
{
|
||||||
chat: item.chat,
|
chat: item.chat,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
import { settings, chatId, WEBUI_NAME, models, config } from '$lib/stores';
|
import { settings, chatId, WEBUI_NAME, models, config, user as sessionUser } from '$lib/stores';
|
||||||
import { convertMessagesToHistory, createMessagesList } from '$lib/utils';
|
import { convertMessagesToHistory, createMessagesList } from '$lib/utils';
|
||||||
|
|
||||||
import { getChatByShareId, cloneSharedChatById } from '$lib/apis/chats';
|
import { getChatByShareId, cloneSharedChatById } from '$lib/apis/chats';
|
||||||
@@ -128,6 +128,11 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const cloneSharedChat = async () => {
|
const cloneSharedChat = async () => {
|
||||||
|
if (!($sessionUser?.role === 'admin' || ($sessionUser?.permissions?.chat?.import ?? true))) {
|
||||||
|
toast.error($i18n.t('Access prohibited'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!chat) return;
|
if (!chat) return;
|
||||||
|
|
||||||
const res = await cloneSharedChatById(localStorage.token, chat.id).catch((error) => {
|
const res = await cloneSharedChatById(localStorage.token, chat.id).catch((error) => {
|
||||||
@@ -197,18 +202,20 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
{#if $sessionUser?.role === 'admin' || ($sessionUser?.permissions?.chat?.import ?? true)}
|
||||||
class="absolute bottom-0 right-0 left-0 flex justify-center w-full bg-linear-to-b from-transparent to-white dark:to-gray-900"
|
<div
|
||||||
>
|
class="absolute bottom-0 right-0 left-0 flex justify-center w-full bg-linear-to-b from-transparent to-white dark:to-gray-900"
|
||||||
<div class="pb-5">
|
>
|
||||||
<button
|
<div class="pb-5">
|
||||||
class="px-3.5 py-1.5 text-sm font-medium bg-black hover:bg-gray-900 text-white dark:bg-white dark:text-black dark:hover:bg-gray-100 transition rounded-full"
|
<button
|
||||||
on:click={cloneSharedChat}
|
class="px-3.5 py-1.5 text-sm font-medium bg-black hover:bg-gray-900 text-white dark:bg-white dark:text-black dark:hover:bg-gray-100 transition rounded-full"
|
||||||
>
|
on:click={cloneSharedChat}
|
||||||
{$i18n.t('Clone Chat')}
|
>
|
||||||
</button>
|
{$i18n.t('Clone Chat')}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
Reference in new issue
Block a user